From: Martin Storsjö Date: Mon, 23 Nov 2009 22:55:12 +0000 (+0200) Subject: Refactor winsock initialization into a separate function X-Git-Tag: v1.6.6-rc1~34 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b7cc9f82594a2d5fe12867c515d86d91ecedad8f;p=git.git Refactor winsock initialization into a separate function The winsock library must be initialized. Since gethostbyname() is the first function that calls into winsock, it was overridden to do the initialization. This refactoring helps the next patch, where other functions can be called earlier. Signed-off-by: Martin Storsjo Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- diff --git a/compat/mingw.c b/compat/mingw.c index 15fe33eaa..f9d82ff10 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -903,16 +903,25 @@ char **make_augmented_environ(const char *const *vars) 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); }