summaryrefslogtreecommitdiff
path: root/src/node_os.cc
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2018-12-18 13:48:47 -0500
committercjihrig <cjihrig@gmail.com>2018-12-20 13:44:28 -0500
commit3438f4b2cab572b4e21ed68013f2b25adf911e8b (patch)
treea4d3f553a68e79154ca734e0c5fa61ab7bc91f81 /src/node_os.cc
parent9ac108d834539122625c85bb0a88f51a62b22d36 (diff)
downloadandroid-node-v8-3438f4b2cab572b4e21ed68013f2b25adf911e8b.tar.gz
android-node-v8-3438f4b2cab572b4e21ed68013f2b25adf911e8b.tar.bz2
android-node-v8-3438f4b2cab572b4e21ed68013f2b25adf911e8b.zip
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>
Diffstat (limited to 'src/node_os.cc')
-rw-r--r--src/node_os.cc13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/node_os.cc b/src/node_os.cc
index 5a40e171ed..6ecfb7fe9f 100644
--- a/src/node_os.cc
+++ b/src/node_os.cc
@@ -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));
}