From 7336516a6f2ac781b4a78a73f99e41e9e8b66e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 17 Jun 2009 22:37:31 +0300 Subject: [PATCH] Refactor winsock initialization into a separate function Signed-off-by: Martin Storsjo --- compat/mingw.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index bed417875e..f570d115c9 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -886,16 +886,25 @@ char **env_setenv(char **env, const char *name) return env; } -/* this is the first function to call into WS_32; initialize it */ -#undef gethostbyname -struct hostent *mingw_gethostbyname(const char *host) +static void ensure_socket_initialization(void) { WSADATA wsa; + static int initialized = 0; + + if (initialized) + return; if (WSAStartup(MAKEWORD(2,2), &wsa)) die("unable to initialize winsock subsystem, error %d", WSAGetLastError()); atexit((void(*)(void)) WSACleanup); + initialized = 1; +} + +#undef gethostbyname +struct hostent *mingw_gethostbyname(const char *host) +{ + ensure_socket_initialization(); return gethostbyname(host); }