diff options
author | Martin Willi <martin@revosec.ch> | 2013-10-25 16:03:07 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-06-04 15:53:02 +0200 |
commit | 110e42361e38bd7b6ee85c84d809afc72dce6bf1 (patch) | |
tree | 449faae8343e811325135386810d2c0e0072cb39 /src/libstrongswan/utils/windows.h | |
parent | 204098a7520205b4534044b3840f68cb1a6e20ae (diff) | |
download | strongswan-110e42361e38bd7b6ee85c84d809afc72dce6bf1.tar.bz2 strongswan-110e42361e38bd7b6ee85c84d809afc72dce6bf1.tar.xz |
unit-tests: Uninline dlopen() and friends, make more dynamic, fix dlerror()
As the error string contains a newline, we have to remove that before
returning the string.
Diffstat (limited to 'src/libstrongswan/utils/windows.h')
-rw-r--r-- | src/libstrongswan/utils/windows.h | 70 |
1 files changed, 12 insertions, 58 deletions
diff --git a/src/libstrongswan/utils/windows.h b/src/libstrongswan/utils/windows.h index 8e6fd80b1..e070a79a2 100644 --- a/src/libstrongswan/utils/windows.h +++ b/src/libstrongswan/utils/windows.h @@ -204,39 +204,11 @@ static inline int setenv(const char *name, const char *value, int overwrite) } /** - * dlerror(3) from <dlfcn.h>, printing error to an alloca() buffer - */ -#define dlerror() \ -({ \ - char buf[128], *out;\ - ssize_t len; \ - DWORD err; \ - err = GetLastError(); \ - len = FormatMessage(0, NULL, err, 0, buf, sizeof(buf), NULL); \ - if (len <= 0) \ - { \ - len = snprintf(buf, sizeof(buf), "(%u)", err); \ - } \ - len++; \ - out = alloca(len); \ - memcpy(out, buf, len); \ - out; \ -}) - -/** * Lazy binding, ignored on Windows */ #define RTLD_LAZY 1 /** - * dlopen(3) from <dlfcn.h> - */ -static inline void *dlopen(const char *filename, int flag) -{ - return LoadLibrary(filename); -} - -/** * Default handle targeting .exe */ #define RTLD_DEFAULT (NULL) @@ -247,42 +219,24 @@ static inline void *dlopen(const char *filename, int flag) #define RTLD_NEXT ((void*)~(uintptr_t)0) /** + * dlopen(3) from <dlfcn.h> + */ +void* dlopen(const char *filename, int flag); + +/** * dlsym() from <dlfcn.h> */ -static inline void *dlsym(void *handle, const char *symbol) -{ - if (handle == RTLD_DEFAULT) - { - handle = GetModuleHandle(NULL); - } - else if (handle == RTLD_NEXT) - { - if (strcmp(symbol, "malloc") == 0 || - strcmp(symbol, "realloc") == 0 || - strcmp(symbol, "free") == 0) - { - /* for leak-detective */ - handle = GetModuleHandle("msvcrt"); - } - else - { - return NULL; - } - } - if (handle) - { - return GetProcAddress((HMODULE)handle, symbol); - } - return NULL; -} +void* dlsym(void *handle, const char *symbol); + +/** + * dlerror(3) from <dlfcn.h>, currently not thread save + */ +char* dlerror(void); /** * dlclose() from <dlfcn.h> */ -static inline int dlclose(void *handle) -{ - return FreeLibrary((HMODULE)handle); -} +int dlclose(void *handle); /** * socketpair(2) for SOCK_STREAM, uses TCP on loopback |