Improve configuration for dlopen and add suitable test
This commit is contained in:
parent
8509159d1a
commit
400c6c8e76
|
@ -74,6 +74,10 @@
|
|||
<not-bool/>
|
||||
</arg>
|
||||
</function>
|
||||
<resource>
|
||||
<alloc>dlopen</alloc>
|
||||
<dealloc>dlclose</dealloc>
|
||||
</resource>
|
||||
<!-- see http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlopen.html -->
|
||||
<function name="dlopen">
|
||||
<noreturn>false</noreturn>
|
||||
|
@ -4107,4 +4111,8 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
|
|||
<podtype name="glob_t"/>
|
||||
<podtype name="locale_t"/>
|
||||
<define name="MAP_FAILED" value="-1"/>
|
||||
<define name="RTLD_LAZY" value="0x01"/>
|
||||
<define name="RTLD_NOW" value="0x02"/>
|
||||
<define name="RTLD_GLOBAL" value="0x04"/>
|
||||
<define name="RTLD_LOCAL" value="0x08"/>
|
||||
</def>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <dirent.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
// unavailable on some linux systems #include <ndbm.h>
|
||||
#include <netdb.h>
|
||||
|
@ -331,3 +332,19 @@ void timet_h(struct timespec* ptp1)
|
|||
// cppcheck-suppress ctime_rCalled
|
||||
ctime_r(&clock, buf);
|
||||
}
|
||||
|
||||
void dl(const char* libname, const char* func)
|
||||
{
|
||||
void* lib = dlopen(libname, RTLD_NOW);
|
||||
// cppcheck-suppress resourceLeak
|
||||
// cppcheck-suppress redundantAssignment
|
||||
lib = dlopen(libname, RTLD_LAZY);
|
||||
const char* funcname;
|
||||
// cppcheck-suppress uninitvar
|
||||
// cppcheck-suppress unreadVariable
|
||||
void* sym = dlsym(lib, funcname);
|
||||
void* uninit;
|
||||
// cppcheck-suppress uninitvar
|
||||
dlclose(uninit);
|
||||
// cppcheck-suppress resourceLeak
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue