Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: the dl functions don't set errno
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Dec 18, 2011
1 parent d808cf9 commit e9235a3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/unix/dl.c
Expand Up @@ -25,11 +25,17 @@
#include <dlfcn.h>
#include <errno.h>

/* The dl family of functions don't set errno. We need a good way to communicate
* errors to the caller but there is only dlerror() and that returns a string -
* a string that may or may not be safe to keep a reference to...
*/
static const uv_err_t uv_inval_ = { UV_EINVAL, EINVAL };


uv_err_t uv_dlopen(const char* filename, uv_lib_t* library) {
void* handle = dlopen(filename, RTLD_LAZY);
if (handle == NULL) {
return uv__new_sys_error(errno);
return uv_inval_;
}

*library = handle;
Expand All @@ -39,7 +45,7 @@ uv_err_t uv_dlopen(const char* filename, uv_lib_t* library) {

uv_err_t uv_dlclose(uv_lib_t library) {
if (dlclose(library) != 0) {
return uv__new_sys_error(errno);
return uv_inval_;
}

return uv_ok_;
Expand All @@ -49,7 +55,7 @@ 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) {
return uv__new_sys_error(errno);
return uv_inval_;
}

*ptr = (void*) address;
Expand Down

0 comments on commit e9235a3

Please sign in to comment.