Skip to content

Commit 16e4cd1

Browse files
committed
os: implement os.type() using uv_os_uname()
The happy path behavior should be identical on all platforms except MinGW, which now identifies MinGW separately from Windows. PR-URL: #25659 Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 80441c8 commit 16e4cd1

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

‎src/node_os.cc‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
# include<netdb.h>// MAXHOSTNAMELEN on Solaris.
3737
# include<unistd.h>// gethostname, sysconf
3838
# include<sys/param.h>// MAXHOSTNAMELEN on Linux and the BSDs.
39-
# include<sys/utsname.h>
4039
#endif// __POSIX__
4140

4241
// Add Windows fallback.
@@ -84,21 +83,16 @@ static void GetHostname(const FunctionCallbackInfo<Value>& args){
8483

8584
staticvoidGetOSType(const FunctionCallbackInfo<Value>& args){
8685
Environment* env = Environment::GetCurrent(args);
87-
constchar* rval;
86+
uv_utsname_t info;
87+
int err = uv_os_uname(&info);
8888

89-
#ifdef __POSIX__
90-
structutsname info;
91-
if (uname(&info) < 0){
89+
if (err != 0){
9290
CHECK_GE(args.Length(), 1);
93-
env->CollectExceptionInfo(args[args.Length() - 1], errno, "uname");
91+
env->CollectUVExceptionInfo(args[args.Length() - 1], err, "uv_os_uname");
9492
return args.GetReturnValue().SetUndefined();
9593
}
96-
rval = info.sysname;
97-
#else// __MINGW32__
98-
rval = "Windows_NT";
99-
#endif// __POSIX__
10094

101-
args.GetReturnValue().Set(OneByteString(env->isolate(), rval));
95+
args.GetReturnValue().Set(OneByteString(env->isolate(), info.sysname));
10296
}
10397

10498

0 commit comments

Comments
(0)