[Mono-osx] OSX vs Linux

Gavin Landon Gavin.Landon at ignitetech.com
Mon Dec 17 19:31:23 EST 2007


I'm receiving an error for uname on the code line:  
static extern int uname (IntPtr buf);

Error: 
A namespace can only contain types and namespace declarations (CS0116)

Thanks for your time,
Gavin

-----Original Message-----
From: Miguel de Icaza [mailto:miguel at novell.com] 
Sent: Monday, December 17, 2007 6:04 PM
To: Gavin Landon
Cc: mono-osx at lists.ximian.com
Subject: Re: [Mono-osx] OSX vs Linux

Hello,

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

Oh.

>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";
                        return;
                }

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

                UnixMarshal.FreeHeap(buf);
        }

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20071217/b0234483/attachment-0001.html 


More information about the Mono-osx mailing list