summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1fdffa6)
raw | patch | inline | side by side (parent: 1fdffa6)
author | Martin Storsjö <martin@martin.st> | |
Mon, 23 Nov 2009 22:55:12 +0000 (00:55 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 24 Nov 2009 08:57:39 +0000 (00:57 -0800) |
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>
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>
compat/mingw.c | patch | blob | history |
diff --git a/compat/mingw.c b/compat/mingw.c
index 15fe33eaa0f220e94131006bca89effd14d6d058..f9d82ff103cd096ac328d221c8b1b5e7a4e7d330 100644 (file)
--- a/compat/mingw.c
+++ b/compat/mingw.c
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);
}