diff options
Diffstat (limited to 'lib/src/util')
-rw-r--r-- | lib/src/util/ip_address.c | 5 | ||||
-rw-r--r-- | lib/src/util/windows/dlfcn.c | 65 |
2 files changed, 69 insertions, 1 deletions
diff --git a/lib/src/util/ip_address.c b/lib/src/util/ip_address.c index d4b34dc0b..1d123d8cd 100644 --- a/lib/src/util/ip_address.c +++ b/lib/src/util/ip_address.c @@ -302,7 +302,10 @@ ip_prefix_ntop(const ip_prefix_t * ip_prefix, char *dst, size_t size) } if (!s) return -1; - return snprintf(dst, size, "%s/%d", ip_s, ip_prefix->len); + int rc = snprintf(dst, size, "%s/%d", ip_s, ip_prefix->len); + if (rc >= size) + return (int)size; + return rc; } int 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 |