[Mono-osx] OSX vs Linux

Miguel de Icaza miguel at novell.com
Mon Dec 17 19:03:46 EST 2007


> I'm having some trouble distinguishing the difference between Linux and
> OSX.  


>From the subject line I felt a new flame war was brewing.

The uname approach works, the following is a piece of uname that uses
P/Invoke instead of depending on uname, its part of mkbundle.cs:

using System.Runtime.InteropServices;

        [DllImport ("libc")]
        static extern int uname (IntPtr buf);

        static void DetectOS ()
                if (!IsUnix) {
                        Console.WriteLine ("OS is: Windows");
                        style = "windows";

                IntPtr buf = UnixMarshal.AllocHeap(8192);
                if (uname (buf) != 0){
                        Console.WriteLine ("Warning: Unable to detect OS");
                string os = Marshal.PtrToStringAnsi (buf);
                Console.WriteLine ("OS is: " + os);
                if (os == "Darwin")
                        style = "osx";


        static bool IsUnix {
                get {
                        int p = (int) Environment.OSVersion.Platform;
                        return ((p == 4) || (p == 128));

More information about the Mono-osx mailing list