Skip to content

Commit 13d24b0

Browse files
patthoytsgitster
authored andcommitted
mingw: ensure sockets are initialized before calling gethostname
If the Windows sockets subsystem has not been initialized yet then an attempt to get the hostname returns an error and prints a warning to the console. This solves this issue for msysGit as seen with 'git fetch'. Signed-off-by: Pat Thoyts <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8850c3d commit 13d24b0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

compat/mingw.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,13 @@ static void ensure_socket_initialization(void)
13211321
initialized = 1;
13221322
}
13231323

1324+
#undef gethostname
1325+
int mingw_gethostname(char *name, int namelen)
1326+
{
1327+
ensure_socket_initialization();
1328+
return gethostname(name, namelen);
1329+
}
1330+
13241331
#undef gethostbyname
13251332
struct hostent *mingw_gethostbyname(const char *host)
13261333
{

compat/mingw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ char *mingw_getcwd(char *pointer, int len);
190190
char *mingw_getenv(const char *name);
191191
#define getenv mingw_getenv
192192

193+
int mingw_gethostname(char *host, int namelen);
194+
#define gethostname mingw_gethostname
195+
193196
struct hostent *mingw_gethostbyname(const char *host);
194197
#define gethostbyname mingw_gethostbyname
195198

0 commit comments

Comments
 (0)