From ba519913f92c6691ad079295c52505fcd16fd1e4 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 18 Dec 2018 13:48:47 -0500 Subject: [PATCH] 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 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- src/node_os.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/node_os.cc b/src/node_os.cc index 3ab190b6a2f93b..1050125dea4e4c 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -67,18 +67,15 @@ using v8::Value; static void GetHostname(const FunctionCallbackInfo& 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)); }