diff options
author | cjihrig <cjihrig@gmail.com> | 2019-01-21 04:18:31 +0300 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-05-16 21:57:13 +0300 |
commit | eef2debcc78818b3f909af6b0cb9456a455ec174 (patch) | |
tree | 5a1d1924cdb865b941ef1df81fa66f390cde7152 /src | |
parent | 7e5ef4a0e14b045fac16b1bea8aa202773e35ee0 (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.
Backport-PR-URL: https://github.com/nodejs/node/pull/27728
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')
-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 1050125dea4..2cdc4ea8d05 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -103,44 +103,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)); } |