[Mono-osx] OSX vs Linux

Geoff Norton gnorton at novell.com
Mon Dec 17 19:35:37 EST 2007


You need to put the dllimport in a class.

-g

On 17-Dec-07, at 7:31 PM, Gavin Landon wrote:

> 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));
>                 }
>         }
>
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx

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


More information about the Mono-osx mailing list