diff options
-rw-r--r-- | ConfigureChecks.cmake | 4 | ||||
-rw-r--r-- | cmake/Modules/DefinePlatformDefaults.cmake | 4 | ||||
-rw-r--r-- | config.h.cmake | 2 | ||||
-rw-r--r-- | src/socket_wrapper.c | 21 |
4 files changed, 24 insertions, 7 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index ec72b4e..0d906c5 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -163,6 +163,10 @@ if (HAVE_LIBDL) set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${DLFCN_LIBRARY}) endif (HAVE_LIBDL) +if (OSX) + set(HAVE_APPLE 1) +endif (OSX) + # ENDIAN if (NOT WIN32) test_big_endian(WORDS_BIGENDIAN) diff --git a/cmake/Modules/DefinePlatformDefaults.cmake b/cmake/Modules/DefinePlatformDefaults.cmake index 502d936..f36d9e6 100644 --- a/cmake/Modules/DefinePlatformDefaults.cmake +++ b/cmake/Modules/DefinePlatformDefaults.cmake @@ -26,3 +26,7 @@ endif (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") if (CMAKE_SYSTEM_NAME MATCHES "OS2") set(OS2 TRUE) endif (CMAKE_SYSTEM_NAME MATCHES "OS2") + +if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(OSX TRUE) +endif (CMAKE_SYSTEM_NAME MATCHES "Darwin") diff --git a/config.h.cmake b/config.h.cmake index 03bd301..f48a32f 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -34,6 +34,8 @@ #cmakedefine HAVE_SOCKADDR_STORAGE 1 #cmakedefine HAVE_IPV6 1 +#cmakedefine HAVE_APPLE 1 + /*************************** ENDIAN *****************************/ /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index dbf20ac..2412c66 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -282,18 +282,18 @@ static int libc_dlopen(void) return 0; } - +#ifdef HAVE_APPLE + if (libc_hnd == NULL) { + libc_hnd = dlopen("libc.dylib", flags); + } +#else for (libc_hnd = NULL, i = 10; libc_hnd == NULL; i--) { char soname[256] = {0}; snprintf(soname, sizeof(soname), "%s.%u", LIBC_NAME, i); libc_hnd = dlopen(soname, flags); } - - /* Maybe we're on MacOSX */ - if (libc_hnd == NULL) { - libc_hnd = dlopen("libc.dylib", flags); - } +#endif if (libc_hnd == NULL) { SWRAP_LOG(SWRAP_LOG_ERROR, @@ -308,10 +308,17 @@ static int libc_dlopen(void) static void *libc_dlsym(const char *name) { void *func; + char sym_name[256]; libc_dlopen(); - func = dlsym(libc_hnd, name); +#ifdef HAVE_APPLE + snprintf(sym_name, sizeof(sym_name), "_%s", name); +#else + snprintf(sym_name, sizeof(sym_name), "%s", name); +#endif + + func = dlsym(libc_hnd, sym_name); if (func == NULL) { SWRAP_LOG(SWRAP_LOG_ERROR, |