diff options
author | cjihrig <cjihrig@gmail.com> | 2019-01-21 18:45:50 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-01-25 08:54:55 -0500 |
commit | 16e4cd19f29287677500583918449b87e29fa29a (patch) | |
tree | fa5a286ccad2f58136430d95d2f8fcc8e092c156 /src | |
parent | 80441c8086aa5d5d74d93b5c6b779eab734149d4 (diff) | |
download | node-new-16e4cd19f29287677500583918449b87e29fa29a.tar.gz |
os: implement os.type() using uv_os_uname()
The happy path behavior should be identical on all
platforms except MinGW, which now identifies MinGW
separately from Windows.
PR-URL: https://github.com/nodejs/node/pull/25659
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_os.cc | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index a5ae53ba75..5639453d2c 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -36,7 +36,6 @@ # include <netdb.h> // MAXHOSTNAMELEN on Solaris. # include <unistd.h> // gethostname, sysconf # include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs. -# include <sys/utsname.h> #endif // __POSIX__ // Add Windows fallback. @@ -84,21 +83,16 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args) { static void GetOSType(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); - const char* rval; + uv_utsname_t info; + int err = uv_os_uname(&info); -#ifdef __POSIX__ - struct utsname info; - if (uname(&info) < 0) { + if (err != 0) { CHECK_GE(args.Length(), 1); - env->CollectExceptionInfo(args[args.Length() - 1], errno, "uname"); + env->CollectUVExceptionInfo(args[args.Length() - 1], err, "uv_os_uname"); return args.GetReturnValue().SetUndefined(); } - rval = info.sysname; -#else // __MINGW32__ - rval = "Windows_NT"; -#endif // __POSIX__ - args.GetReturnValue().Set(OneByteString(env->isolate(), rval)); + args.GetReturnValue().Set(OneByteString(env->isolate(), info.sysname)); } |