From 06bac23cf8abc7b11e11aff1dc7f26b5355b0224 Mon Sep 17 00:00:00 2001 From: kanato Date: Thu, 1 Jan 2009 00:11:06 +0000 Subject: [PATCH] Introduced new platform detection code to p/invoke to uname rather than running it as a process. --- Source/OpenTK/Configuration.cs | 49 +++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/Configuration.cs b/Source/OpenTK/Configuration.cs index 34d09950..605f957d 100644 --- a/Source/OpenTK/Configuration.cs +++ b/Source/OpenTK/Configuration.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices; [assembly: CLSCompliant(true)] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenTK.Utilities")] @@ -92,13 +93,59 @@ namespace OpenTK #region private static string DetectUnixKernel() + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + struct utsname + { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string sysname; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string nodename; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string release; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string version; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string machine; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] + public string extraJustInCase; + + } + + private static string DetectUnixKernel() + { + Debug.Print("Size: {0}", Marshal.SizeOf(typeof(utsname)).ToString()); + Debug.Flush(); + utsname uts = new utsname(); + uname(out uts); + + Debug.WriteLine("System:"); + Debug.Indent(); + Debug.WriteLine(uts.sysname); + Debug.WriteLine(uts.nodename); + Debug.WriteLine(uts.release); + Debug.WriteLine(uts.version); + Debug.WriteLine(uts.machine); + Debug.Unindent(); + + return uts.sysname.ToString(); + } + + [DllImport("libc")] + private static extern void uname(out utsname uname_struct); + + /// /// Executes "uname" which returns a string representing the name of the /// underlying Unix kernel. /// /// "Unix", "Linux", "Darwin" or null. /// Source code from "Mono: A Developer's Notebook" - private static string DetectUnixKernel() + private static string oldDetectUnixKernel() { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.Arguments = "-s";