diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2013-12-05 11:58:21 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2013-12-05 13:43:44 +0100 |
commit | 0e3ebfe55b7afd62c232f360cf930bdf41cea785 (patch) | |
tree | 9f9dfff691ab8f1987a96570abedb80a3908d127 | |
parent | 2ca8c448104fa30cb9c102332a2e6a37596b858d (diff) | |
download | socket_wrapper-0e3ebfe55b7afd62c232f360cf930bdf41cea785.tar.gz socket_wrapper-0e3ebfe55b7afd62c232f360cf930bdf41cea785.tar.xz socket_wrapper-0e3ebfe55b7afd62c232f360cf930bdf41cea785.zip |
swrap: Add swrap_init() and swrap_enabled().
-rw-r--r-- | src/socket_wrapper.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index ab520b1..56d7bac 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -62,6 +62,7 @@ #include <stdio.h> #include <stdint.h> #include <stdarg.h> +#include <stdbool.h> #include <unistd.h> enum swrap_dbglvl_e { @@ -325,11 +326,19 @@ struct swrap { void *libc_handle; void *libsocket_handle; + bool initialised; + bool enabled; + + char *socket_dir; + struct swrap_libc_fns fns; }; static struct swrap swrap; +/* prototypes */ +static const char *socket_wrapper_dir(void); + #define LIBC_NAME "libc.so" static void *swrap_libc_fn(void *handle, const char *fn_name) @@ -453,6 +462,29 @@ static void swrap_libc_init(void) swrap_libc_fn(handle, "socket"); } +static void swrap_init(void) +{ + if (swrap.initialised) { + return; + } + + swrap.socket_dir = strdup(socket_wrapper_dir()); + if (swrap.socket_dir != NULL) { + swrap.enabled = true; + } + + swrap_libc_init(); + + swrap.initialised = true; +} + +static int swrap_enabled(void) +{ + swrap_init(); + + return swrap.enabled ? 1 : 0; +} + #ifndef HAVE_APPLE static void *libc_hnd; |