[Mono-list] Detect OS using mono framework

Jonathan Pryor jonpryor at vt.edu
Thu Mar 27 22:40:34 EDT 2008


On Thu, 2008-03-27 at 22:23 -0400, Chris Howie wrote:
> On Thu, Mar 27, 2008 at 1:29 PM, Jonathan Pryor <jonpryor at vt.edu> wrote:
> > Your OSDetection.IsOSX code can be simplified greatly by using
> > Mono.Posix.dll in Mono 1.9:
> >
> >        static bool IsOSX {
> >                get {
> >                        if (IsWindows)
> >                                return false;
> >                        Mono.Unix.Native.Utsname buf;
> >                        if (Mono.Unix.Native.Syscall.uname (out buf) ==
> >                        0) {
> >                                return string.Compare(buf.sysname, "darwin", true) == 0
> >                        }
> >                        return false;
> >                }
> >        }
> >
>
> Won't the JIT explode if this is called on MS.NET?

Only if you don't include Mono.Posix.dll with your app. :-)

If you don't want it to blow up, it should work to move the Ustname and
uname use into a different method (called by the IsOSX property), as
that method will never be jitted on Windows.

 - Jon




More information about the Mono-list mailing list