mirror of
https://github.com/git/git.git
synced 2026-04-02 13:00:08 +02:00
Refactor winsock initialization into a separate function
Signed-off-by: Martin Storsjo <martin@martin.st>
This commit is contained in:
committed by
Johannes Schindelin
parent
65deb66a2d
commit
7336516a6f
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user