mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
os: use uv_os_gethostname() in hostname()
This commit changes the C++ implementation of os.hostname() to use uv_os_gethostname(). PR-URL: https://github.com/nodejs/node/pull/25111 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
ae50f480d2
commit
add566eee5
1 file changed
+5
-8
+5
-8
@@ -68,18 +68,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));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user