Skip to content

Commit d468848

Browse files
cjihrigMylesBorins
authored andcommitted
os: use uv_os_gethostname() in hostname()
This commit changes the C++ implementation of os.hostname() to use uv_os_gethostname(). PR-URL: #25111 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 870549b commit d468848

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/node_os.cc

+5-8
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,15 @@ using v8::Value;
6767
static void GetHostname(const FunctionCallbackInfo<Value>& args) {
6868
Environment* env = Environment::GetCurrent(args);
6969
char buf[MAXHOSTNAMELEN + 1];
70+
size_t size = sizeof(buf);
71+
int r = uv_os_gethostname(buf, &size);
7072

71-
if (gethostname(buf, sizeof(buf))) {
72-
#ifdef __POSIX__
73-
int errorno = errno;
74-
#else // __MINGW32__
75-
int errorno = WSAGetLastError();
76-
#endif // __POSIX__
73+
if (r != 0) {
7774
CHECK_GE(args.Length(), 1);
78-
env->CollectExceptionInfo(args[args.Length() - 1], errorno, "gethostname");
75+
env->CollectUVExceptionInfo(args[args.Length() - 1], r,
76+
"uv_os_gethostname");
7977
return args.GetReturnValue().SetUndefined();
8078
}
81-
buf[sizeof(buf) - 1] = '\0';
8279

8380
args.GetReturnValue().Set(OneByteString(env->isolate(), buf));
8481
}

0 commit comments

Comments
 (0)