unix: it's legal for dlsym() to return NULL

A symbol name can map to NULL. Check dlerror() to see if a real error happened.
This commit is contained in:
Ben Noordhuis 2011-12-18 16:49:37 +01:00
parent e9235a39f8
commit feb267e611
2 changed files with 10 additions and 3 deletions

View File

@ -1250,7 +1250,8 @@ UV_EXTERN uv_err_t uv_dlopen(const char* filename, uv_lib_t* library);
UV_EXTERN uv_err_t uv_dlclose(uv_lib_t library);
/*
* Retrieves a data pointer from a dynamic library.
* Retrieves a data pointer from a dynamic library. It is legal for a symbol to
* map to NULL.
*/
UV_EXTERN uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr);

View File

@ -53,8 +53,14 @@ uv_err_t uv_dlclose(uv_lib_t library) {
uv_err_t uv_dlsym(uv_lib_t library, const char* name, void** ptr) {
void* address = dlsym(library, name);
if (address == NULL) {
void* address;
/* Reset error status. */
dlerror();
address = dlsym(library, name);
if (dlerror()) {
return uv_inval_;
}