Skip to content

Commit 0ebe6eb

Browse files
cjihrigtargos
authored andcommittedJan 24, 2019
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: #25600 Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent f688e73 commit 0ebe6eb

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed
 

‎src/node_os.cc

+5-33
Original file line numberDiff line numberDiff line change
@@ -105,44 +105,16 @@ static void GetOSType(const FunctionCallbackInfo<Value>& args) {
105105

106106
static void GetOSRelease(const FunctionCallbackInfo<Value>& args) {
107107
Environment* env = Environment::GetCurrent(args);
108-
const char* rval;
108+
uv_utsname_t info;
109+
int err = uv_os_uname(&info);
109110

110-
#ifdef __POSIX__
111-
struct utsname info;
112-
if (uname(&info) < 0) {
111+
if (err != 0) {
113112
CHECK_GE(args.Length(), 1);
114-
env->CollectExceptionInfo(args[args.Length() - 1], errno, "uname");
113+
env->CollectUVExceptionInfo(args[args.Length() - 1], err, "uv_os_uname");
115114
return args.GetReturnValue().SetUndefined();
116115
}
117-
# ifdef _AIX
118-
char release[256];
119-
snprintf(release, sizeof(release),
120-
"%s.%s", info.version, info.release);
121-
rval = release;
122-
# else
123-
rval = info.release;
124-
# endif
125-
#else // Windows
126-
char release[256];
127-
OSVERSIONINFOW info;
128-
129-
info.dwOSVersionInfoSize = sizeof(info);
130-
131-
// Don't complain that GetVersionEx is deprecated; there is no alternative.
132-
#pragma warning(suppress : 4996)
133-
if (GetVersionExW(&info) == 0)
134-
return;
135-
136-
snprintf(release,
137-
sizeof(release),
138-
"%d.%d.%d",
139-
static_cast<int>(info.dwMajorVersion),
140-
static_cast<int>(info.dwMinorVersion),
141-
static_cast<int>(info.dwBuildNumber));
142-
rval = release;
143-
#endif // __POSIX__
144116

145-
args.GetReturnValue().Set(OneByteString(env->isolate(), rval));
117+
args.GetReturnValue().Set(OneByteString(env->isolate(), info.release));
146118
}
147119

148120

0 commit comments

Comments
 (0)