diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/cutils.c | 23 | ||||
-rw-r--r-- | util/osdep.c | 23 | ||||
-rw-r--r-- | util/qemu-sockets.c | 24 |
3 files changed, 46 insertions, 24 deletions
diff --git a/util/cutils.c b/util/cutils.c index 5024253405..a1658197cf 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -482,3 +482,26 @@ int uleb128_decode_small(const uint8_t *in, uint32_t *n) return 2; } } + +/* + * helper to parse debug environment variables + */ +int parse_debug_env(const char *name, int max, int initial) +{ + char *debug_env = getenv(name); + char *inv = NULL; + int debug; + + if (!debug_env) { + return initial; + } + debug = strtol(debug_env, &inv, 10); + if (inv == debug_env) { + return initial; + } + if (debug < 0 || debug > max) { + fprintf(stderr, "warning: %s not in [0, %d]", name, max); + return initial; + } + return debug; +} diff --git a/util/osdep.c b/util/osdep.c index bd59ac90c1..6ae5aaf781 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -406,3 +406,26 @@ bool fips_get_state(void) return fips_enabled; } +#ifdef _WIN32 +static void socket_cleanup(void) +{ + WSACleanup(); +} +#endif + +int socket_init(void) +{ +#ifdef _WIN32 + WSADATA Data; + int ret, err; + + ret = WSAStartup(MAKEWORD(2, 2), &Data); + if (ret != 0) { + err = WSAGetLastError(); + fprintf(stderr, "WSAStartup: %d\n", err); + return -1; + } + atexit(socket_cleanup); +#endif + return 0; +} diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 94581aa236..fdd8dc460b 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -974,27 +974,3 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) qemu_opts_del(opts); return fd; } - -#ifdef _WIN32 -static void socket_cleanup(void) -{ - WSACleanup(); -} -#endif - -int socket_init(void) -{ -#ifdef _WIN32 - WSADATA Data; - int ret, err; - - ret = WSAStartup(MAKEWORD(2,2), &Data); - if (ret != 0) { - err = WSAGetLastError(); - fprintf(stderr, "WSAStartup: %d\n", err); - return -1; - } - atexit(socket_cleanup); -#endif - return 0; -} |