Skip to content

Commit

Permalink
Refactor winsock initialization into a separate function
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Martin Storsjö authored and Junio C Hamano committed Nov 24, 2009
1 parent 1fdffa6 commit b7cc9f8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit b7cc9f8

Please sign in to comment.