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 <martin@martin.st> Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin Storsjö committed
Nov 24, 2009 at 00:55 UTC
b7cc9f82594a2d5fe12867c515d86d91ecedad8f
1 file changed
+12
-3
compat/mingw.c
+12
-3
@@ -903,16 +903,25 @@ char **make_augmented_environ(const char *const *vars)
903
return env;
904
}
905
906
-/* this is the first function to call into WS_32; initialize it */
907
-#undef gethostbyname
908
-struct hostent *mingw_gethostbyname(const char *host)
906
+static void ensure_socket_initialization(void)
907
{
908
WSADATA wsa;
909
+ static int initialized = 0;
910
+
911
+ if (initialized)
912
+ return;
913
914
if (WSAStartup(MAKEWORD(2,2), &wsa))
915
die("unable to initialize winsock subsystem, error %d",
916
WSAGetLastError());
917
atexit((void(*)(void)) WSACleanup);
918
+ initialized = 1;
919
+}
920
+
921
+#undef gethostbyname
922
+struct hostent *mingw_gethostbyname(const char *host)
923
+{
924
+ ensure_socket_initialization();
925
return gethostbyname(host);
926
}
927