Skip to content

Commit add566e

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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ae50f48 commit add566e

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
@@ -68,18 +68,15 @@ using v8::Value;
6868
static void GetHostname(const FunctionCallbackInfo<Value>& args) {
6969
Environment* env = Environment::GetCurrent(args);
7070
char buf[MAXHOSTNAMELEN + 1];
71+
size_t size = sizeof(buf);
72+
int r = uv_os_gethostname(buf, &size);
7173

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

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

0 commit comments

Comments
 (0)