Browse Source

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>
maint
Martin Storsjö 15 years ago committed by Junio C Hamano
parent
commit
b7cc9f8259
  1. 15
      compat/mingw.c

15
compat/mingw.c

@ -903,16 +903,25 @@ char **make_augmented_environ(const char *const *vars)
return env; return env;
} }


/* this is the first function to call into WS_32; initialize it */ static void ensure_socket_initialization(void)
#undef gethostbyname
struct hostent *mingw_gethostbyname(const char *host)
{ {
WSADATA wsa; WSADATA wsa;
static int initialized = 0;

if (initialized)
return;


if (WSAStartup(MAKEWORD(2,2), &wsa)) if (WSAStartup(MAKEWORD(2,2), &wsa))
die("unable to initialize winsock subsystem, error %d", die("unable to initialize winsock subsystem, error %d",
WSAGetLastError()); WSAGetLastError());
atexit((void(*)(void)) WSACleanup); atexit((void(*)(void)) WSACleanup);
initialized = 1;
}

#undef gethostbyname
struct hostent *mingw_gethostbyname(const char *host)
{
ensure_socket_initialization();
return gethostbyname(host); return gethostbyname(host);
} }



Loading…
Cancel
Save