瀏覽代碼

cmLib.c : Attempts to load non-library files now fail silently.

master
kpl_harpo 10 年之前
父節點
當前提交
4712a0ccb2
共有 1 個檔案被更改,包括 14 行新增1 行删除
  1. 14
    1
      cmLib.c

+ 14
- 1
cmLib.c 查看文件

@@ -160,7 +160,20 @@ unsigned  cmLibOpen(  cmLibH_t h, const cmChar_t* libFn )
160 160
 
161 161
   if( _cmLibIsNull(lH) )
162 162
   {
163
-    cmErrMsg(&p->err,kOpenFailLibRC,"Library load failed. System Message: %s", _cmLibSysError() );
163
+    // There is apparently no way to get an error code which indicates that the
164
+    // file load attempt failed because the file was not a shared library - 
165
+    // which should not generate an error message - therefore
166
+    // we must match the end of the the error string returned by dlerror() with 
167
+    // 'invalid ELF header'.
168
+    const char* errMsg = _cmLibSysError();
169
+    const char* s      = "invalid ELF header";
170
+    unsigned    sn      = strlen(s);
171
+    unsigned    mn       = strlen(errMsg);
172
+    if( errMsg!=NULL && mn>sn && strcmp(errMsg+mn-sn,s)==0 )
173
+      cmErrSetRC(&p->err,kOpenFailLibRC ); // signal error but no error message
174
+    else
175
+      cmErrMsg(&p->err,kOpenFailLibRC,"Library load failed. System Message: %s", errMsg );
176
+
164 177
     return cmInvalidId;
165 178
   }
166 179
   

Loading…
取消
儲存