Introduced new platform detection code to p/invoke to uname rather than running it as a process.

This commit is contained in:
kanato 2009-01-01 00:11:06 +00:00
parent 23f4858e2c
commit 06bac23cf8

View file

@ -11,6 +11,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenTK.Utilities")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenTK.Utilities")]
@ -92,13 +93,59 @@ namespace OpenTK
#region private static string DetectUnixKernel() #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);
/// <summary> /// <summary>
/// Executes "uname" which returns a string representing the name of the /// Executes "uname" which returns a string representing the name of the
/// underlying Unix kernel. /// underlying Unix kernel.
/// </summary> /// </summary>
/// <returns>"Unix", "Linux", "Darwin" or null.</returns> /// <returns>"Unix", "Linux", "Darwin" or null.</returns>
/// <remarks>Source code from "Mono: A Developer's Notebook"</remarks> /// <remarks>Source code from "Mono: A Developer's Notebook"</remarks>
private static string DetectUnixKernel() private static string oldDetectUnixKernel()
{ {
ProcessStartInfo startInfo = new ProcessStartInfo(); ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = "-s"; startInfo.Arguments = "-s";