Skip to content

Commit eef2deb

Browse files
cjihrigMylesBorins
authored andcommitted
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: #27728 PR-URL: #25600 Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 7e5ef4a commit eef2deb

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
@@ -103,44 +103,16 @@ static void GetOSType(const FunctionCallbackInfo<Value>& args) {
103103

104104
static void GetOSRelease(const FunctionCallbackInfo<Value>& args) {
105105
Environment* env = Environment::GetCurrent(args);
106-
const char* rval;
106+
uv_utsname_t info;
107+
int err = uv_os_uname(&info);
107108

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

143-
args.GetReturnValue().Set(OneByteString(env->isolate(), rval));
115+
args.GetReturnValue().Set(OneByteString(env->isolate(), info.release));
144116
}
145117

146118

0 commit comments

Comments
 (0)