[System] Warnings cleanup
[mono.git] / mcs / class / System / System / Platform.cs
index 8f6f496e906e8fd8cc9dcbbf549e1aebd3065e23..8afd40370cd599aeae22ae1b8ad0b908f5fdc81f 100644 (file)
@@ -28,36 +28,59 @@ using System.Runtime.InteropServices;
 
 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;
+                       }
+               }
        }
 }