From 914af23b3d13c7e5f9439621db80a595ad9a0fb8 Mon Sep 17 00:00:00 2001
From: cjihrig <cjihrig@gmail.com>
Date: Sun, 20 Jan 2019 20:18:31 -0500
Subject: [PATCH] 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>
---
 src/node_os.cc | 38 +++++---------------------------------
 1 file changed, 5 insertions(+), 33 deletions(-)

diff --git a/src/node_os.cc b/src/node_os.cc
index 4a372f4e428491..541c2dc1e9d6c1 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));
 }