From 4712a0ccb265579a022a1921743cd9645fff708b Mon Sep 17 00:00:00 2001 From: kpl_harpo Date: Tue, 8 Apr 2014 09:07:46 -0400 Subject: [PATCH] cmLib.c : Attempts to load non-library files now fail silently. --- cmLib.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmLib.c b/cmLib.c index 443b586..278191f 100644 --- a/cmLib.c +++ b/cmLib.c @@ -160,7 +160,20 @@ unsigned cmLibOpen( cmLibH_t h, const cmChar_t* libFn ) if( _cmLibIsNull(lH) ) { - cmErrMsg(&p->err,kOpenFailLibRC,"Library load failed. System Message: %s", _cmLibSysError() ); + // There is apparently no way to get an error code which indicates that the + // file load attempt failed because the file was not a shared library - + // which should not generate an error message - therefore + // we must match the end of the the error string returned by dlerror() with + // 'invalid ELF header'. + const char* errMsg = _cmLibSysError(); + const char* s = "invalid ELF header"; + unsigned sn = strlen(s); + unsigned mn = strlen(errMsg); + if( errMsg!=NULL && mn>sn && strcmp(errMsg+mn-sn,s)==0 ) + cmErrSetRC(&p->err,kOpenFailLibRC ); // signal error but no error message + else + cmErrMsg(&p->err,kOpenFailLibRC,"Library load failed. System Message: %s", errMsg ); + return cmInvalidId; }