diff options
author | Angelo Mantellini <manangel@cisco.com> | 2021-04-30 12:26:57 +0200 |
---|---|---|
committer | Angelo Mantellini <angelo.mantellini@cisco.com> | 2021-04-30 14:54:00 +0200 |
commit | 07133ac060c2af721941f7b47c52c075df3168ba (patch) | |
tree | a3a618442fc9f1adb5f1cf2e3d442c70fd787d2b /lib/src | |
parent | 39e15ebb3805efb6c71a1dd16f18061cd86487cf (diff) |
[HICN-703] Update windows-sdk and hicn code
Signed-off-by: Angelo Mantellini <@ngelo.mantellini@cisco.com>
Change-Id: I05e4c92ce7de3640f0272afae127e1377862bd3e
Signed-off-by: Angelo Mantellini <angelo.mantellini@cisco.com>
Diffstat (limited to 'lib/src')
-rw-r--r-- | lib/src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | lib/src/util/windows/dlfcn.c | 65 |
2 files changed, 70 insertions, 0 deletions
diff --git a/lib/src/CMakeLists.txt b/lib/src/CMakeLists.txt index 49b735f51..f410e3d83 100644 --- a/lib/src/CMakeLists.txt +++ b/lib/src/CMakeLists.txt @@ -30,6 +30,11 @@ list(APPEND LIBHICN_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/util/log.c ) +if (WIN32) + list(APPEND LIBHICN_SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/util/windows/dlfcn.c + ) +endif () set (COMPILER_DEFINITIONS "-DWITH_MAPME") include(BuildMacros) diff --git a/lib/src/util/windows/dlfcn.c b/lib/src/util/windows/dlfcn.c new file mode 100644 index 000000000..c8173cdb0 --- /dev/null +++ b/lib/src/util/windows/dlfcn.c @@ -0,0 +1,65 @@ +/* dlfcn.c */ + +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <windows.h> + +static struct { + long lasterror; + const char *err_rutin; +} var = { + 0, + NULL +}; + +void *dlopen (const char *filename, int flags) +{ + HINSTANCE hInst; + + hInst= LoadLibrary (filename); + if (hInst==NULL) { + var.lasterror = GetLastError (); + var.err_rutin = "dlopen"; + } + return hInst; +} + +int dlclose (void *handle) +{ + BOOL ok; + int rc= 0; + + ok= FreeLibrary ((HINSTANCE)handle); + if (! ok) { + var.lasterror = GetLastError (); + var.err_rutin = "dlclose"; + rc= -1; + } + return rc; +} + +void *dlsym (void *handle, const char *name) +{ + FARPROC fp; + + fp= GetProcAddress ((HINSTANCE)handle, name); + if (!fp) { + var.lasterror = GetLastError (); + var.err_rutin = "dlsym"; + } + return (void *)(intptr_t)fp; +} + +const char *dlerror (void) +{ +static char errstr [88]; + + if (var.lasterror) { + sprintf (errstr, "%s error #%ld", var.err_rutin, var.lasterror); + return errstr; + } else { + return NULL; + } +}
\ No newline at end of file |