Skip to content

Commit 268fd52

Browse files
authored
Merge pull request #980 from Unity-Technologies/platform-no-libc
Assume not having libc means this is not macOS
2 parents d130c38 + 4bd6b75 commit 268fd52

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

mcs/class/System/System/Platform.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,40 @@ private static void CheckOS() {
5959
}
6060

6161
IntPtr buf = Marshal.AllocHGlobal (8192);
62-
if (uname (buf) == 0) {
63-
string os = Marshal.PtrToStringAnsi (buf);
64-
switch (os) {
65-
case "Darwin":
66-
isMacOS = true;
67-
break;
68-
case "FreeBSD":
69-
isFreeBSD = true;
70-
break;
62+
try {
63+
if (uname (buf) == 0) {
64+
string os = Marshal.PtrToStringAnsi (buf);
65+
switch (os) {
66+
case "Darwin":
67+
isMacOS = true;
68+
break;
69+
case "FreeBSD":
70+
isFreeBSD = true;
71+
break;
72+
}
7173
}
7274
}
73-
Marshal.FreeHGlobal (buf);
74-
checkedOS = true;
75+
finally {
76+
Marshal.FreeHGlobal (buf);
77+
checkedOS = true;
78+
}
7579
}
7680
#endif
7781

7882
public static bool IsMacOS {
7983
get {
8084
if (!checkedOS)
85+
#if UNITY
86+
try {
87+
CheckOS();
88+
}
89+
catch (DllNotFoundException e) {
90+
// libc does not exist, so this is not MacOS
91+
isMacOS = false;
92+
}
93+
#else
8194
CheckOS();
95+
#endif
8296
return isMacOS;
8397
}
8498
}

0 commit comments

Comments
 (0)