Skip to content

Commit

Permalink
os: use uv_os_gethostname() in hostname()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and MylesBorins committed May 16, 2019
1 parent 870549b commit d468848
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,15 @@ using v8::Value;
static void GetHostname(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
char buf[MAXHOSTNAMELEN + 1];
size_t size = sizeof(buf);
int r = uv_os_gethostname(buf, &size);

if (gethostname(buf, sizeof(buf))) {
#ifdef __POSIX__
int errorno = errno;
#else // __MINGW32__
int errorno = WSAGetLastError();
#endif // __POSIX__
if (r != 0) {
CHECK_GE(args.Length(), 1);
env->CollectExceptionInfo(args[args.Length() - 1], errorno, "gethostname");
env->CollectUVExceptionInfo(args[args.Length() - 1], r,
"uv_os_gethostname");
return args.GetReturnValue().SetUndefined();
}
buf[sizeof(buf) - 1] = '\0';

args.GetReturnValue().Set(OneByteString(env->isolate(), buf));
}
Expand Down

0 comments on commit d468848

Please sign in to comment.