Skip to content

Commit e59f161

Browse files
committed
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]>
1 parent 7e4bf67 commit e59f161

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
@@ -1391,6 +1391,13 @@ static void ensure_socket_initialization(void)
13911391
initialized = 1;
13921392
}
13931393

1394+
#undef gethostname
1395+
int mingw_gethostname(char *name, int namelen)
1396+
{
1397+
ensure_socket_initialization();
1398+
return gethostname(name, namelen);
1399+
}
1400+
13941401
#undef gethostbyname
13951402
struct hostent *mingw_gethostbyname(const char *host)
13961403
{

compat/mingw.h

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

190+
int mingw_gethostname(char *host, int namelen);
191+
#define gethostname mingw_gethostname
192+
190193
struct hostent *mingw_gethostbyname(const char *host);
191194
#define gethostbyname mingw_gethostbyname
192195

0 commit comments

Comments
 (0)