Skip to content

Commit

Permalink
os: implement os.release() using uv_os_uname()
Browse files Browse the repository at this point in the history
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: #25600
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
cjihrig authored and targos committed Jan 24, 2019
1 parent f688e73 commit 0ebe6eb
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down

0 comments on commit 0ebe6eb

Please sign in to comment.