summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-07-05 11:29:22 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-07-05 11:29:22 +0200
commit1421501bca3d407b9e5e8680b44014fd73034054 (patch)
treeb6e8340ec0e3a4a5efa9110767628ab5ef0924b1
parent471fd3d71d17210ca0dc583272f757e48bdb9cef (diff)
downloadsocket_wrapper-1421501bca3d407b9e5e8680b44014fd73034054.tar.gz
socket_wrapper-1421501bca3d407b9e5e8680b44014fd73034054.tar.xz
socket_wrapper-1421501bca3d407b9e5e8680b44014fd73034054.zip
src: Correctly load symbols on APPLE.
-rw-r--r--ConfigureChecks.cmake4
-rw-r--r--cmake/Modules/DefinePlatformDefaults.cmake4
-rw-r--r--config.h.cmake2
-rw-r--r--src/socket_wrapper.c21
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,