Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <errno.h>
#ifdef _WIN32
#include <direct.h> // for _mkdir
#define WIN32_LEAN_AND_MEAN
#include <windows.h> // for GetComputerNameA
#endif

// Tracking child processes needs SIGCHLD and waitpid, which native Windows
Expand Down Expand Up @@ -1968,6 +1970,17 @@ static Obj FuncIO_gethostname(Obj self)
}
return MakeString(name);
}
#elif defined(_WIN32)
// gethostname is part of Winsock; the computer name needs no network setup
static Obj FuncIO_gethostname(Obj self)
{
char name[MAX_COMPUTERNAME_LENGTH + 1];
DWORD len = sizeof(name);
if (!GetComputerNameA(name, &len)) {
return Fail;
}
return MakeString(name);
}
#endif

static Obj FuncIO_getenv(Obj self, Obj name)
Expand Down Expand Up @@ -2265,7 +2278,7 @@ static StructGVarFunc GVarFuncs[] = {
GVAR_FUNC(IO_getsockname, 1, "fd"),
#endif

#ifdef HAVE_GETHOSTNAME
#if defined(HAVE_GETHOSTNAME) || defined(_WIN32)
GVAR_FUNC(IO_gethostname, 0, ""),
#endif

Expand Down