Lines 28-63
Link Here
|
28 |
|
28 |
|
29 |
namespace System { |
29 |
namespace System { |
30 |
internal static class Platform { |
30 |
internal static class Platform { |
|
|
31 |
static bool checkedOS; |
32 |
static bool isMacOS; |
33 |
static bool isFreeBSD; |
34 |
|
31 |
#if MONOTOUCH || XAMMAC |
35 |
#if MONOTOUCH || XAMMAC |
32 |
public static bool IsMacOS { |
36 |
private static void CheckOS() { |
33 |
get { return true; } |
37 |
isMacOS = true; |
34 |
} |
38 |
checkedOS = true; |
|
|
39 |
} |
35 |
#else |
40 |
#else |
36 |
[DllImport ("libc")] |
41 |
[DllImport ("libc")] |
37 |
static extern int uname (IntPtr buf); |
42 |
static extern int uname (IntPtr buf); |
38 |
|
43 |
|
39 |
static bool checkedIsMacOS; |
44 |
private static void CheckOS() { |
40 |
static bool isMacOS; |
45 |
if (Environment.OSVersion.Platform != PlatformID.Unix) { |
41 |
|
46 |
checkedOS = true; |
42 |
public static bool IsMacOS { |
47 |
return; |
43 |
get { |
48 |
} |
44 |
if (Environment.OSVersion.Platform != PlatformID.Unix) |
49 |
|
45 |
return false; |
50 |
IntPtr buf = Marshal.AllocHGlobal (8192); |
46 |
|
51 |
if (uname (buf) == 0) { |
47 |
if (!checkedIsMacOS) { |
52 |
string os = Marshal.PtrToStringAnsi (buf); |
48 |
IntPtr buf = Marshal.AllocHGlobal (8192); |
53 |
switch (os) { |
49 |
if (uname (buf) == 0) { |
54 |
case "Darwin": |
50 |
string os = Marshal.PtrToStringAnsi (buf); |
55 |
isMacOS = true; |
51 |
if (os == "Darwin") |
56 |
break; |
52 |
isMacOS = true; |
57 |
case "FreeBSD": |
53 |
} |
58 |
isFreeBSD = true; |
54 |
Marshal.FreeHGlobal (buf); |
59 |
break; |
55 |
checkedIsMacOS = true; |
60 |
} |
56 |
} |
61 |
} |
57 |
|
62 |
Marshal.FreeHGlobal (buf); |
58 |
return isMacOS; |
63 |
checkedOS = true; |
59 |
} |
64 |
} |
60 |
} |
|
|
61 |
#endif |
65 |
#endif |
|
|
66 |
|
67 |
public static bool IsMacOS { |
68 |
get { |
69 |
if (!checkedOS) |
70 |
CheckOS(); |
71 |
return isMacOS; |
72 |
} |
73 |
} |
74 |
|
75 |
public static bool IsFreeBSD { |
76 |
get { |
77 |
if (!checkedOS) |
78 |
CheckOS(); |
79 |
return isFreeBSD; |
80 |
} |
81 |
} |
62 |
} |
82 |
} |
63 |
} |
83 |
} |