diff options
author | cjihrig <cjihrig@gmail.com> | 2019-01-21 04:18:31 +0300 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-01-23 08:15:10 +0300 |
commit | 914af23b3d13c7e5f9439621db80a595ad9a0fb8 (patch) | |
tree | 4c30c35fd2515988d9162c51d38492ba7b7d4539 /src/node_os.cc | |
parent | 907ff0a47d4e0fec66f85d204a93cd29d40103e5 (diff) |
os: implement os.release() using uv_os_uname()
For non-Windows platforms, the happy path behavior should be
identical. On Windows, uv_os_uname() attempts to use
RtlGetVersion() before falling back to the deprecated
GetVersionExW() that Node was previously using.
PR-URL: https://github.com/nodejs/node/pull/25600
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/node_os.cc')
-rw-r--r-- | src/node_os.cc | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/src/node_os.cc b/src/node_os.cc index 4a372f4e428..541c2dc1e9d 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -105,44 +105,16 @@ static void GetOSType(const FunctionCallbackInfo<Value>& args) { static void GetOSRelease(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(); } -# ifdef _AIX - char release[256]; - snprintf(release, sizeof(release), - "%s.%s", info.version, info.release); - rval = release; -# else - rval = info.release; -# endif -#else // Windows - char release[256]; - OSVERSIONINFOW info; - - info.dwOSVersionInfoSize = sizeof(info); - - // Don't complain that GetVersionEx is deprecated; there is no alternative. - #pragma warning(suppress : 4996) - if (GetVersionExW(&info) == 0) - return; - - snprintf(release, - sizeof(release), - "%d.%d.%d", - static_cast<int>(info.dwMajorVersion), - static_cast<int>(info.dwMinorVersion), - static_cast<int>(info.dwBuildNumber)); - rval = release; -#endif // __POSIX__ - args.GetReturnValue().Set(OneByteString(env->isolate(), rval)); + args.GetReturnValue().Set(OneByteString(env->isolate(), info.release)); } |