namespace System {
internal static class Platform {
-#if MONOTOUCH
- public static bool IsMacOS {
- get { return true; }
+ static bool checkedOS;
+ static bool isMacOS;
+
+#if MONOTOUCH || XAMMAC
+ const bool isFreeBSD = false;
+
+ private static void CheckOS() {
+ isMacOS = true;
+ checkedOS = true;
}
#else
+ static bool isFreeBSD;
+
[DllImport ("libc")]
static extern int uname (IntPtr buf);
-
- static bool checkedIsMacOS;
- static bool isMacOS;
-
+
+ private static void CheckOS() {
+ if (Environment.OSVersion.Platform != PlatformID.Unix) {
+ checkedOS = true;
+ return;
+ }
+
+ IntPtr buf = Marshal.AllocHGlobal (8192);
+ if (uname (buf) == 0) {
+ string os = Marshal.PtrToStringAnsi (buf);
+ switch (os) {
+ case "Darwin":
+ isMacOS = true;
+ break;
+ case "FreeBSD":
+ isFreeBSD = true;
+ break;
+ }
+ }
+ Marshal.FreeHGlobal (buf);
+ checkedOS = true;
+ }
+#endif
+
public static bool IsMacOS {
get {
- if (Environment.OSVersion.Platform != PlatformID.Unix)
- return false;
-
- if (!checkedIsMacOS) {
- IntPtr buf = Marshal.AllocHGlobal (8192);
- if (uname (buf) == 0) {
- string os = Marshal.PtrToStringAnsi (buf);
- if (os == "Darwin")
- isMacOS = true;
- }
- Marshal.FreeHGlobal (buf);
- checkedIsMacOS = true;
- }
-
+ if (!checkedOS)
+ CheckOS();
return isMacOS;
}
}
-#endif
+
+ public static bool IsFreeBSD {
+ get {
+ if (!checkedOS)
+ CheckOS();
+ return isFreeBSD;
+ }
+ }
}
}