include ../../build/rules.make
LIBRARY = Mono.Posix.dll
---LIB_MCS_FLAGS = /unsafe /r:$(corlib) /r:System.dll
+++# Don't warn about [Obsolete] members, as there are now *lots* of [Obsolete]
+++# members, generating volumes of output.
+++LIB_MCS_FLAGS = /unsafe /r:$(corlib) /r:System.dll /nowarn:0618
TEST_MCS_FLAGS = /r:Mono.Posix.dll /r:System.dll /nowarn:0219,0618
include ../../build/library.make
---EXTRA_DISTFILES = Mono.Unix/make-map.cs
+++EXTRA_DISTFILES = Mono.Unix.Native/make-map.cs
---all-local: Mono.Unix/make-map.exe
+++all-local: Mono.Unix.Native/make-map.exe
---Mono.Unix/make-map.exe: Mono.Unix/make-map.cs $(the_lib)
--- cp $(the_lib) Mono.Unix/
+++Mono.Unix.Native/make-map.exe: Mono.Unix.Native/make-map.cs $(the_lib)
+++ cp $(the_lib) Mono.Unix.Native/
ifneq ($(PLATFORM),win32)
--- $(CSCOMPILE) -out:Mono.Unix/make-map.exe -r:Mono.Posix.dll Mono.Unix/make-map.cs
+++ $(CSCOMPILE) -debug+ -out:Mono.Unix.Native/make-map.exe -r:Mono.Posix.dll Mono.Unix.Native/make-map.cs
else
--- $(CSCOMPILE) -out:Mono.Unix/make-map.exe -r:Mono.Posix.dll Mono.Unix\\make-map.cs
+++ $(CSCOMPILE) -debug+ -out:Mono.Unix.Native/make-map.exe -r:Mono.Posix.dll Mono.Unix.Native\\make-map.cs
endif
---CLEAN_FILES = Mono.Unix/make-map.exe Mono.Unix/Mono.Posix.dll
+++CLEAN_FILES = Mono.Unix.Native/make-map.exe Mono.Unix.Native/Mono.Posix.dll
./Mono.Unix/UnixSymbolicLinkInfo.cs
./Mono.Unix/UnixUser.cs
./Mono.Unix/UnixUserInfo.cs
+++./Mono.Unix.Native/CdeclFunction.cs
+++./Mono.Unix.Native/HeaderAttribute.cs
+++./Mono.Unix.Native/NativeConvert.cs
+++./Mono.Unix.Native/NativeConvert.generated.cs
+++./Mono.Unix.Native/Stdlib.cs
+++./Mono.Unix.Native/Syscall.cs
./Mono.Posix/Catalog.cs
./Mono.Posix/PeerCred.cs
./Mono.Posix/Syscall.cs
--- /dev/null
--- /dev/null
--- /dev/null
+++//
+++// Mono.Unix/CdeclFunction.cs
+++//
+++// Authors:
+++// Jonathan Pryor (jonpryor@vt.edu)
+++//
+++// (C) 2004 Jonathan Pryor
+++//
+++// Permission is hereby granted, free of charge, to any person obtaining
+++// a copy of this software and associated documentation files (the
+++// "Software"), to deal in the Software without restriction, including
+++// without limitation the rights to use, copy, modify, merge, publish,
+++// distribute, sublicense, and/or sell copies of the Software, and to
+++// permit persons to whom the Software is furnished to do so, subject to
+++// the following conditions:
+++//
+++// The above copyright notice and this permission notice shall be
+++// included in all copies or substantial portions of the Software.
+++//
+++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+++//
+++
+++using System;
+++using System.Collections;
+++using System.Reflection;
+++using System.Reflection.Emit;
+++using System.Runtime.InteropServices;
+++using System.Text;
+++
+++namespace Mono.Unix.Native {
+++
+++ // This class represents a single unmanaged function with "cdecl" calling
+++ // convention -- that is, it can accept a variable number of arguments which
+++ // are passed on the runtime stack.
+++ //
+++ // To use, create an instance:
+++ //
+++ // CdeclFunction printf = new CdeclFunction ("the library",
+++ // "the function name", /* optional */ typeof (ReturnType));
+++ //
+++ // Then call the Invoke method with the appropriate number of arguments:
+++ //
+++ // printf.Invoke (new object[]{"hello, %s\n", "world!"});
+++ //
+++ // In the background a P/Invoke definition for the method with the
+++ // requested argument types will be generated and invoked, invoking the
+++ // unmanaged function. The generated methods are cached, so that subsequent
+++ // calls with the same argument list do not generate new code, speeding up
+++ // the call sequence.
+++ //
+++ // Invoking Cdecl functions is not guaranteed to be portable across all
+++ // platforms. For example, AMD64 requires that the caller set EAX to the
+++ // number of floating point arguments passed in the SSE registers. This
+++ // is only required for variable argument/cdecl functions; consequently,
+++ // the overload technique used by this class wouldn't normally work.
+++ // Mono's AMD64 JIT works around this by always setting EAX on P/Invoke
+++ // invocations, allowing CdeclFunction to work properly, but it will not
+++ // necessarily always work. See also:
+++ //
+++ // http://lwn.net/Articles/5201/?format=printable
+++ //
+++ // Due to potential portability issues, cdecl functions should be avoided
+++ // on most platforms.
+++ //
+++ // This class is intended to be thread-safe.
+++ public sealed class CdeclFunction
+++ {
+++ // The readonly fields (1) shouldn't be modified, and (2) should only be
+++ // used when `overloads' is locked.
+++ private readonly string library;
+++ private readonly string method;
+++ private readonly Type returnType;
+++ private readonly AssemblyName assemblyName;
+++ private readonly AssemblyBuilder assemblyBuilder;
+++ private readonly ModuleBuilder moduleBuilder;
+++
+++ private Hashtable overloads;
+++
+++ public CdeclFunction (string library, string method)
+++ : this (library, method, typeof(void))
+++ {
+++ }
+++
+++ public CdeclFunction (string library, string method, Type returnType)
+++ {
+++ this.library = library;
+++ this.method = method;
+++ this.returnType = returnType;
+++ this.overloads = new Hashtable ();
+++ this.assemblyName = new AssemblyName ();
+++ this.assemblyName.Name = "Mono.Posix.Imports." + library;
+++ this.assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly (
+++ assemblyName, AssemblyBuilderAccess.Run);
+++ this.moduleBuilder = assemblyBuilder.DefineDynamicModule (assemblyName.Name);
+++ }
+++
+++ public object Invoke (object[] parameters)
+++ {
+++ Type[] parameterTypes = GetParameterTypes (parameters);
+++ MethodInfo m = CreateMethod (parameterTypes);
+++ return m.Invoke (null, parameters);
+++ }
+++
+++ private MethodInfo CreateMethod (Type[] parameterTypes)
+++ {
+++ string typeName = GetTypeName (parameterTypes);
+++
+++ lock (overloads) {
+++ MethodInfo mi = (MethodInfo) overloads [typeName];
+++
+++ if (mi != null) {
+++ return mi;
+++ }
+++
+++ TypeBuilder tb = CreateType (typeName);
+++ /* MethodBuilder mb = */ tb.DefinePInvokeMethod (
+++ method,
+++ library,
+++ MethodAttributes.PinvokeImpl | MethodAttributes.Static | MethodAttributes.Public,
+++ CallingConventions.Standard,
+++ returnType,
+++ parameterTypes,
+++ CallingConvention.Cdecl,
+++ CharSet.Ansi);
+++ mi = tb.CreateType ().GetMethod (method);
+++ overloads.Add (typeName, mi);
+++ return mi;
+++ }
+++ }
+++
+++ private TypeBuilder CreateType (string typeName)
+++ {
+++ return moduleBuilder.DefineType (typeName, TypeAttributes.Public);
+++ }
+++
+++ private static Type GetMarshalType (Type t)
+++ {
+++ switch (Type.GetTypeCode (t)) {
+++ // types < sizeof(int) are marshaled as ints
+++ case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte:
+++ case TypeCode.Int16: case TypeCode.Int32:
+++ return typeof(int);
+++ case TypeCode.Byte: case TypeCode.UInt16: case TypeCode.UInt32:
+++ return typeof(uint);
+++ case TypeCode.Int64:
+++ return typeof(long);
+++ case TypeCode.UInt64:
+++ return typeof(ulong);
+++ case TypeCode.Single: case TypeCode.Double:
+++ return typeof(double);
+++ default:
+++ return t;
+++ }
+++ }
+++
+++ private string GetTypeName (Type[] parameterTypes)
+++ {
+++ StringBuilder sb = new StringBuilder ();
+++
+++ sb.Append ("[").Append (library).Append ("] ").Append (method);
+++ sb.Append ("(");
+++
+++ if (parameterTypes.Length > 0)
+++ sb.Append (parameterTypes [0]);
+++ for (int i = 1; i < parameterTypes.Length; ++i)
+++ sb.Append (",").Append (parameterTypes [i]);
+++
+++ sb.Append (") : ").Append (returnType.FullName);
+++
+++ return sb.ToString ();
+++ }
+++
+++ private static Type[] GetParameterTypes (object[] parameters)
+++ {
+++ Type[] parameterTypes = new Type [parameters.Length];
+++ for (int i = 0; i < parameters.Length; ++i)
+++ parameterTypes [i] = GetMarshalType (parameters [i].GetType ());
+++ return parameterTypes;
+++ }
+++ }
+++}
+++
--- /dev/null
--- /dev/null
--- /dev/null
+++2005-09-20 Jonathan Pryor <jonpryor@vt.edu>
+++
+++ * ChangeLog: Started.
+++ * CdeclFunction.cs: Copied from ../Mono.Unix; change namespace.
+++ * HeaderAttribute.cs: Added
+++ * make-map.cs: Copied from ../Mono.Unix; sort type and member names in
+++ output (makes for a more stable svn history, as types/members won't change
+++ position anymore within generated code); look for HeaderAttribute not
+++ IncludeAttribute for getting headers & #defines; generate NativeConvert
+++ partial class.
+++ * NativeConvert.cs: Copied from ../Mono.Unix; change namespace; turn into a
+++ partial class; Remove generated code (generated code is in
+++ NativeConvert.generated.cs).
+++ * NativeConvert.generated.cs: Added
+++ * Stdlib.cs: Copied from ../Mono.Unix; change namespace; rename Error to
+++ Errno (as Error is a "reserved word" in FxCop); [CLSCompliant(false)]
+++ support.
+++ * Syscall.cs: Use HeaderAttribute, not IncludeAttribute, for CLS compliance;
+++ add [CLSCompliant(false)] as needed; use NativeConvert, not UnixConvert.
+++
--- /dev/null
--- /dev/null
--- /dev/null
+++//
+++// IncludeAttribute.cs
+++//
+++// Author:
+++// Jonathan Pryor (jonpryor@vt.edu)
+++//
+++// (C) Novell, Inc.
+++//
+++
+++//
+++// Permission is hereby granted, free of charge, to any person obtaining
+++// a copy of this software and associated documentation files (the
+++// "Software"), to deal in the Software without restriction, including
+++// without limitation the rights to use, copy, modify, merge, publish,
+++// distribute, sublicense, and/or sell copies of the Software, and to
+++// permit persons to whom the Software is furnished to do so, subject to
+++// the following conditions:
+++//
+++// The above copyright notice and this permission notice shall be
+++// included in all copies or substantial portions of the Software.
+++//
+++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+++//
+++using System;
+++
+++namespace Mono.Unix.Native {
+++
+++ [AttributeUsage (AttributeTargets.Assembly)]
+++ internal class HeaderAttribute : Attribute {
+++ string includes = "";
+++ string defines = "";
+++
+++ public string Includes {
+++ get {return includes;}
+++ set {includes = value;}
+++ }
+++
+++ public string Defines {
+++ get {return defines;}
+++ set {defines = value;}
+++ }
+++ }
+++}
+++
--- /dev/null
--- /dev/null
--- /dev/null
+++/*
+++ * This file was automatically generated by make-map from Mono.Posix.dll.
+++ *
+++ * DO NOT MODIFY.
+++ */
+++
+++using System;
+++using System.IO;
+++using System.Runtime.InteropServices;
+++using Mono.Unix.Native;
+++
+++namespace Mono.Unix.Native {
+++
+++ [CLSCompliant (false)]
+++ public sealed /* static */ partial class NativeConvert
+++ {
+++ //
+++ // Non-generated exports
+++ //
+++
+++ // convert from octal representation.
+++ public static FilePermissions FromOctalPermissionString (string value)
+++ {
+++ uint n = Convert.ToUInt32 (value, 8);
+++ return ToFilePermissions (n);
+++ }
+++
+++ public static string ToOctalPermissionString (FilePermissions value)
+++ {
+++ string s = Convert.ToString ((int) (value & ~FilePermissions.S_IFMT), 8);
+++ return new string ('0', 4-s.Length) + s;
+++ }
+++
+++ public static FilePermissions FromUnixPermissionString (string value)
+++ {
+++ if (value == null)
+++ throw new ArgumentNullException ("value");
+++ if (value.Length != 9 && value.Length != 10)
+++ throw new ArgumentException ("value", "must contain 9 or 10 characters");
+++
+++ int i = 0;
+++ FilePermissions perms = new FilePermissions ();
+++
+++ if (value.Length == 10) {
+++ perms |= GetUnixPermissionDevice (value [i]);
+++ ++i;
+++ }
+++
+++ perms |= GetUnixPermissionGroup (
+++ value [i++], FilePermissions.S_IRUSR,
+++ value [i++], FilePermissions.S_IWUSR,
+++ value [i++], FilePermissions.S_IXUSR,
+++ 's', 'S', FilePermissions.S_ISUID);
+++
+++ perms |= GetUnixPermissionGroup (
+++ value [i++], FilePermissions.S_IRGRP,
+++ value [i++], FilePermissions.S_IWGRP,
+++ value [i++], FilePermissions.S_IXGRP,
+++ 's', 'S', FilePermissions.S_ISGID);
+++
+++ perms |= GetUnixPermissionGroup (
+++ value [i++], FilePermissions.S_IROTH,
+++ value [i++], FilePermissions.S_IWOTH,
+++ value [i++], FilePermissions.S_IXOTH,
+++ 't', 'T', FilePermissions.S_ISVTX);
+++
+++ return perms;
+++ }
+++
+++ private static FilePermissions GetUnixPermissionDevice (char value)
+++ {
+++ switch (value) {
+++ case 'd': return FilePermissions.S_IFDIR;
+++ case 'c': return FilePermissions.S_IFCHR;
+++ case 'b': return FilePermissions.S_IFBLK;
+++ case '-': return FilePermissions.S_IFREG;
+++ case 'p': return FilePermissions.S_IFIFO;
+++ case 'l': return FilePermissions.S_IFLNK;
+++ case 's': return FilePermissions.S_IFSOCK;
+++ }
+++ throw new ArgumentException ("value", "invalid device specification: " +
+++ value);
+++ }
+++
+++ private static FilePermissions GetUnixPermissionGroup (
+++ char read, FilePermissions readb,
+++ char write, FilePermissions writeb,
+++ char exec, FilePermissions execb,
+++ char xboth, char xbitonly, FilePermissions xbit)
+++ {
+++ FilePermissions perms = new FilePermissions ();
+++ if (read == 'r')
+++ perms |= readb;
+++ if (write == 'w')
+++ perms |= writeb;
+++ if (exec == 'x')
+++ perms |= execb;
+++ else if (exec == xbitonly)
+++ perms |= xbit;
+++ else if (exec == xboth)
+++ perms |= (execb | xbit);
+++ return perms;
+++ }
+++
+++ // Create ls(1) drwxrwxrwx permissions display
+++ public static string ToUnixPermissionString (FilePermissions value)
+++ {
+++ char [] access = new char[] {
+++ '-', // device
+++ '-', '-', '-', // owner
+++ '-', '-', '-', // group
+++ '-', '-', '-', // other
+++ };
+++ bool have_device = true;
+++ switch (value & FilePermissions.S_IFMT) {
+++ case FilePermissions.S_IFDIR: access [0] = 'd'; break;
+++ case FilePermissions.S_IFCHR: access [0] = 'c'; break;
+++ case FilePermissions.S_IFBLK: access [0] = 'b'; break;
+++ case FilePermissions.S_IFREG: access [0] = '-'; break;
+++ case FilePermissions.S_IFIFO: access [0] = 'p'; break;
+++ case FilePermissions.S_IFLNK: access [0] = 'l'; break;
+++ case FilePermissions.S_IFSOCK: access [0] = 's'; break;
+++ default: have_device = false; break;
+++ }
+++ SetUnixPermissionGroup (value, access, 1,
+++ FilePermissions.S_IRUSR, FilePermissions.S_IWUSR, FilePermissions.S_IXUSR,
+++ 's', 'S', FilePermissions.S_ISUID);
+++ SetUnixPermissionGroup (value, access, 4,
+++ FilePermissions.S_IRGRP, FilePermissions.S_IWGRP, FilePermissions.S_IXGRP,
+++ 's', 'S', FilePermissions.S_ISGID);
+++ SetUnixPermissionGroup (value, access, 7,
+++ FilePermissions.S_IROTH, FilePermissions.S_IWOTH, FilePermissions.S_IXOTH,
+++ 't', 'T', FilePermissions.S_ISVTX);
+++ return have_device
+++ ? new string (access)
+++ : new string (access, 1, 9);
+++ }
+++
+++ private static void SetUnixPermissionGroup (FilePermissions value,
+++ char[] access, int index,
+++ FilePermissions read, FilePermissions write, FilePermissions exec,
+++ char both, char setonly, FilePermissions setxbit)
+++ {
+++ if (UnixFileSystemInfo.IsType (value, read))
+++ access [index] = 'r';
+++ if (UnixFileSystemInfo.IsType (value, write))
+++ access [index+1] = 'w';
+++ access [index+2] = GetSymbolicMode (value, exec, both, setonly, setxbit);
+++ }
+++
+++ // Implement the GNU ls(1) permissions spec; see `info coreutils ls`,
+++ // section 10.1.2, the `-l' argument information.
+++ private static char GetSymbolicMode (FilePermissions value,
+++ FilePermissions xbit, char both, char setonly, FilePermissions setxbit)
+++ {
+++ bool is_x = UnixFileSystemInfo.IsType (value, xbit);
+++ bool is_sx = UnixFileSystemInfo.IsType (value, setxbit);
+++
+++ if (is_x && is_sx)
+++ return both;
+++ if (is_sx)
+++ return setonly;
+++ if (is_x)
+++ return 'x';
+++ return '-';
+++ }
+++
+++ public static readonly DateTime LocalUnixEpoch =
+++ new DateTime (1970, 1, 1).ToLocalTime();
+++
+++ public static DateTime ToDateTime (long time)
+++ {
+++ return FromTimeT (time);
+++ }
+++
+++ public static long FromDateTime (DateTime time)
+++ {
+++ return ToTimeT (time);
+++ }
+++
+++ public static DateTime FromTimeT (long time)
+++ {
+++ DateTime r = LocalUnixEpoch.AddSeconds (time);
+++ return r;
+++ }
+++
+++ public static long ToTimeT (DateTime time)
+++ {
+++ return (long) time.Subtract (LocalUnixEpoch).TotalSeconds;
+++ }
+++
+++ public static OpenFlags ToOpenFlags (FileMode mode, FileAccess access)
+++ {
+++ OpenFlags flags = 0;
+++ switch (mode) {
+++ case FileMode.CreateNew:
+++ flags = OpenFlags.O_CREAT | OpenFlags.O_EXCL;
+++ break;
+++ case FileMode.Create:
+++ flags = OpenFlags.O_CREAT | OpenFlags.O_TRUNC;
+++ break;
+++ case FileMode.Open:
+++ // do nothing
+++ break;
+++ case FileMode.OpenOrCreate:
+++ flags = OpenFlags.O_CREAT;
+++ break;
+++ case FileMode.Truncate:
+++ flags = OpenFlags.O_TRUNC;
+++ break;
+++ case FileMode.Append:
+++ flags = OpenFlags.O_APPEND;
+++ break;
+++ default:
+++ throw new ArgumentException (Locale.GetText ("Unsupported mode value"), "mode");
+++ }
+++
+++ // Is O_LARGEFILE supported?
+++ int _v;
+++ if (TryFromOpenFlags (OpenFlags.O_LARGEFILE, out _v))
+++ flags |= OpenFlags.O_LARGEFILE;
+++
+++ switch (access) {
+++ case FileAccess.Read:
+++ flags |= OpenFlags.O_RDONLY;
+++ break;
+++ case FileAccess.Write:
+++ flags |= OpenFlags.O_WRONLY;
+++ break;
+++ case FileAccess.ReadWrite:
+++ flags |= OpenFlags.O_RDWR;
+++ break;
+++ default:
+++ throw new ArgumentOutOfRangeException (Locale.GetText ("Unsupported access value"), "access");
+++ }
+++
+++ return flags;
+++ }
+++
+++ public static string ToFopenMode (FileAccess access)
+++ {
+++ switch (access) {
+++ case FileAccess.Read: return "rb";
+++ case FileAccess.Write: return "wb";
+++ case FileAccess.ReadWrite: return "r+b";
+++ default: throw new ArgumentOutOfRangeException ("access");
+++ }
+++ }
+++
+++ public static string ToFopenMode (FileMode mode)
+++ {
+++ switch (mode) {
+++ case FileMode.CreateNew: case FileMode.Create: return "w+b";
+++ case FileMode.Open: case FileMode.OpenOrCreate: return "r+b";
+++ case FileMode.Truncate: return "w+b";
+++ case FileMode.Append: return "a+b";
+++ default: throw new ArgumentOutOfRangeException ("mode");
+++ }
+++ }
+++
+++ private static readonly string[][] fopen_modes = new string[][]{
+++ // Read Write ReadWrite
+++ /* FileMode.CreateNew: */ new string[]{"Can't Read+Create", "wb", "w+b"},
+++ /* FileMode.Create: */ new string[]{"Can't Read+Create", "wb", "w+b"},
+++ /* FileMode.Open: */ new string[]{"rb", "wb", "r+b"},
+++ /* FileMode.OpenOrCreate: */ new string[]{"rb", "wb", "r+b"},
+++ /* FileMode.Truncate: */ new string[]{"Cannot Truncate and Read","wb", "w+b"},
+++ /* FileMode.Append: */ new string[]{"Cannot Append and Read", "ab", "a+b"},
+++ };
+++
+++ public static string ToFopenMode (FileMode mode, FileAccess access)
+++ {
+++ int fm = -1, fa = -1;
+++ switch (mode) {
+++ case FileMode.CreateNew: fm = 0; break;
+++ case FileMode.Create: fm = 1; break;
+++ case FileMode.Open: fm = 2; break;
+++ case FileMode.OpenOrCreate: fm = 3; break;
+++ case FileMode.Truncate: fm = 4; break;
+++ case FileMode.Append: fm = 5; break;
+++ }
+++ switch (access) {
+++ case FileAccess.Read: fa = 0; break;
+++ case FileAccess.Write: fa = 1; break;
+++ case FileAccess.ReadWrite: fa = 2; break;
+++ }
+++
+++ if (fm == -1)
+++ throw new ArgumentOutOfRangeException ("mode");
+++ if (fa == -1)
+++ throw new ArgumentOutOfRangeException ("access");
+++
+++ string fopen_mode = fopen_modes [fm][fa];
+++ if (fopen_mode [0] != 'r' && fopen_mode [0] != 'w' && fopen_mode [0] != 'a')
+++ throw new ArgumentException (fopen_mode);
+++ return fopen_mode;
+++ }
+++ }
+++}
+++
+++// vim: noexpandtab
--- /dev/null
--- /dev/null
--- /dev/null
+++/*
+++ * This file was automatically generated by make-map from Mono.Posix.dll.
+++ *
+++ * DO NOT MODIFY.
+++ */
+++
+++using System;
+++using System.Runtime.InteropServices;
+++using Mono.Unix.Native;
+++
+++namespace Mono.Unix.Native {
+++
+++ [CLSCompliant (false)]
+++ public sealed /* static */ partial class NativeConvert
+++ {
+++ private NativeConvert () {}
+++
+++ private const string LIB = "MonoPosixHelper";
+++
+++ private static void ThrowArgumentException (object value)
+++ {
+++ throw new ArgumentOutOfRangeException ("value", value,
+++ Locale.GetText ("Current platform doesn't support this value."));
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromError")]
+++ private static extern int FromError (Error value, out Int32 rval);
+++
+++ [Obsolete ("Use Mono.Unix.Native.Errno")]
+++ public static bool TryFromError (Error value, out Int32 rval)
+++ {
+++ return FromError (value, out rval) == 0;
+++ }
+++
+++ [Obsolete ("Use Mono.Unix.Native.Errno")]
+++ public static Int32 FromError (Error value)
+++ {
+++ Int32 rval;
+++ if (FromError (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToError")]
+++ private static extern int ToError (Int32 value, out Error rval);
+++
+++ [Obsolete ("Use Mono.Unix.Native.Errno")]
+++ public static bool TryToError (Int32 value, out Error rval)
+++ {
+++ return ToError (value, out rval) == 0;
+++ }
+++
+++ [Obsolete ("Use Mono.Unix.Native.Errno")]
+++ public static Error ToError (Int32 value)
+++ {
+++ Error rval;
+++ if (ToError (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromAccessModes")]
+++ private static extern int FromAccessModes (AccessModes value, out Int32 rval);
+++
+++ public static bool TryFromAccessModes (AccessModes value, out Int32 rval)
+++ {
+++ return FromAccessModes (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromAccessModes (AccessModes value)
+++ {
+++ Int32 rval;
+++ if (FromAccessModes (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToAccessModes")]
+++ private static extern int ToAccessModes (Int32 value, out AccessModes rval);
+++
+++ public static bool TryToAccessModes (Int32 value, out AccessModes rval)
+++ {
+++ return ToAccessModes (value, out rval) == 0;
+++ }
+++
+++ public static AccessModes ToAccessModes (Int32 value)
+++ {
+++ AccessModes rval;
+++ if (ToAccessModes (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromConfStr")]
+++ private static extern int FromConfStr (ConfStr value, out Int32 rval);
+++
+++ public static bool TryFromConfStr (ConfStr value, out Int32 rval)
+++ {
+++ return FromConfStr (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromConfStr (ConfStr value)
+++ {
+++ Int32 rval;
+++ if (FromConfStr (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToConfStr")]
+++ private static extern int ToConfStr (Int32 value, out ConfStr rval);
+++
+++ public static bool TryToConfStr (Int32 value, out ConfStr rval)
+++ {
+++ return ToConfStr (value, out rval) == 0;
+++ }
+++
+++ public static ConfStr ToConfStr (Int32 value)
+++ {
+++ ConfStr rval;
+++ if (ToConfStr (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromDirectoryNotifyFlags")]
+++ private static extern int FromDirectoryNotifyFlags (DirectoryNotifyFlags value, out Int32 rval);
+++
+++ public static bool TryFromDirectoryNotifyFlags (DirectoryNotifyFlags value, out Int32 rval)
+++ {
+++ return FromDirectoryNotifyFlags (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromDirectoryNotifyFlags (DirectoryNotifyFlags value)
+++ {
+++ Int32 rval;
+++ if (FromDirectoryNotifyFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToDirectoryNotifyFlags")]
+++ private static extern int ToDirectoryNotifyFlags (Int32 value, out DirectoryNotifyFlags rval);
+++
+++ public static bool TryToDirectoryNotifyFlags (Int32 value, out DirectoryNotifyFlags rval)
+++ {
+++ return ToDirectoryNotifyFlags (value, out rval) == 0;
+++ }
+++
+++ public static DirectoryNotifyFlags ToDirectoryNotifyFlags (Int32 value)
+++ {
+++ DirectoryNotifyFlags rval;
+++ if (ToDirectoryNotifyFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromErrno")]
+++ private static extern int FromErrno (Errno value, out Int32 rval);
+++
+++ public static bool TryFromErrno (Errno value, out Int32 rval)
+++ {
+++ return FromErrno (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromErrno (Errno value)
+++ {
+++ Int32 rval;
+++ if (FromErrno (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToErrno")]
+++ private static extern int ToErrno (Int32 value, out Errno rval);
+++
+++ public static bool TryToErrno (Int32 value, out Errno rval)
+++ {
+++ return ToErrno (value, out rval) == 0;
+++ }
+++
+++ public static Errno ToErrno (Int32 value)
+++ {
+++ Errno rval;
+++ if (ToErrno (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromFcntlCommand")]
+++ private static extern int FromFcntlCommand (FcntlCommand value, out Int32 rval);
+++
+++ public static bool TryFromFcntlCommand (FcntlCommand value, out Int32 rval)
+++ {
+++ return FromFcntlCommand (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromFcntlCommand (FcntlCommand value)
+++ {
+++ Int32 rval;
+++ if (FromFcntlCommand (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToFcntlCommand")]
+++ private static extern int ToFcntlCommand (Int32 value, out FcntlCommand rval);
+++
+++ public static bool TryToFcntlCommand (Int32 value, out FcntlCommand rval)
+++ {
+++ return ToFcntlCommand (value, out rval) == 0;
+++ }
+++
+++ public static FcntlCommand ToFcntlCommand (Int32 value)
+++ {
+++ FcntlCommand rval;
+++ if (ToFcntlCommand (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromFilePermissions")]
+++ private static extern int FromFilePermissions (FilePermissions value, out UInt32 rval);
+++
+++ public static bool TryFromFilePermissions (FilePermissions value, out UInt32 rval)
+++ {
+++ return FromFilePermissions (value, out rval) == 0;
+++ }
+++
+++ public static UInt32 FromFilePermissions (FilePermissions value)
+++ {
+++ UInt32 rval;
+++ if (FromFilePermissions (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToFilePermissions")]
+++ private static extern int ToFilePermissions (UInt32 value, out FilePermissions rval);
+++
+++ public static bool TryToFilePermissions (UInt32 value, out FilePermissions rval)
+++ {
+++ return ToFilePermissions (value, out rval) == 0;
+++ }
+++
+++ public static FilePermissions ToFilePermissions (UInt32 value)
+++ {
+++ FilePermissions rval;
+++ if (ToFilePermissions (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromLockType")]
+++ private static extern int FromLockType (LockType value, out Int16 rval);
+++
+++ public static bool TryFromLockType (LockType value, out Int16 rval)
+++ {
+++ return FromLockType (value, out rval) == 0;
+++ }
+++
+++ public static Int16 FromLockType (LockType value)
+++ {
+++ Int16 rval;
+++ if (FromLockType (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToLockType")]
+++ private static extern int ToLockType (Int16 value, out LockType rval);
+++
+++ public static bool TryToLockType (Int16 value, out LockType rval)
+++ {
+++ return ToLockType (value, out rval) == 0;
+++ }
+++
+++ public static LockType ToLockType (Int16 value)
+++ {
+++ LockType rval;
+++ if (ToLockType (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromLockfCommand")]
+++ private static extern int FromLockfCommand (LockfCommand value, out Int32 rval);
+++
+++ public static bool TryFromLockfCommand (LockfCommand value, out Int32 rval)
+++ {
+++ return FromLockfCommand (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromLockfCommand (LockfCommand value)
+++ {
+++ Int32 rval;
+++ if (FromLockfCommand (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToLockfCommand")]
+++ private static extern int ToLockfCommand (Int32 value, out LockfCommand rval);
+++
+++ public static bool TryToLockfCommand (Int32 value, out LockfCommand rval)
+++ {
+++ return ToLockfCommand (value, out rval) == 0;
+++ }
+++
+++ public static LockfCommand ToLockfCommand (Int32 value)
+++ {
+++ LockfCommand rval;
+++ if (ToLockfCommand (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromMlockallFlags")]
+++ private static extern int FromMlockallFlags (MlockallFlags value, out Int32 rval);
+++
+++ public static bool TryFromMlockallFlags (MlockallFlags value, out Int32 rval)
+++ {
+++ return FromMlockallFlags (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromMlockallFlags (MlockallFlags value)
+++ {
+++ Int32 rval;
+++ if (FromMlockallFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToMlockallFlags")]
+++ private static extern int ToMlockallFlags (Int32 value, out MlockallFlags rval);
+++
+++ public static bool TryToMlockallFlags (Int32 value, out MlockallFlags rval)
+++ {
+++ return ToMlockallFlags (value, out rval) == 0;
+++ }
+++
+++ public static MlockallFlags ToMlockallFlags (Int32 value)
+++ {
+++ MlockallFlags rval;
+++ if (ToMlockallFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromMmapFlags")]
+++ private static extern int FromMmapFlags (MmapFlags value, out Int32 rval);
+++
+++ public static bool TryFromMmapFlags (MmapFlags value, out Int32 rval)
+++ {
+++ return FromMmapFlags (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromMmapFlags (MmapFlags value)
+++ {
+++ Int32 rval;
+++ if (FromMmapFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToMmapFlags")]
+++ private static extern int ToMmapFlags (Int32 value, out MmapFlags rval);
+++
+++ public static bool TryToMmapFlags (Int32 value, out MmapFlags rval)
+++ {
+++ return ToMmapFlags (value, out rval) == 0;
+++ }
+++
+++ public static MmapFlags ToMmapFlags (Int32 value)
+++ {
+++ MmapFlags rval;
+++ if (ToMmapFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromMmapProts")]
+++ private static extern int FromMmapProts (MmapProts value, out Int32 rval);
+++
+++ public static bool TryFromMmapProts (MmapProts value, out Int32 rval)
+++ {
+++ return FromMmapProts (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromMmapProts (MmapProts value)
+++ {
+++ Int32 rval;
+++ if (FromMmapProts (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToMmapProts")]
+++ private static extern int ToMmapProts (Int32 value, out MmapProts rval);
+++
+++ public static bool TryToMmapProts (Int32 value, out MmapProts rval)
+++ {
+++ return ToMmapProts (value, out rval) == 0;
+++ }
+++
+++ public static MmapProts ToMmapProts (Int32 value)
+++ {
+++ MmapProts rval;
+++ if (ToMmapProts (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromMountFlags")]
+++ private static extern int FromMountFlags (MountFlags value, out UInt64 rval);
+++
+++ public static bool TryFromMountFlags (MountFlags value, out UInt64 rval)
+++ {
+++ return FromMountFlags (value, out rval) == 0;
+++ }
+++
+++ public static UInt64 FromMountFlags (MountFlags value)
+++ {
+++ UInt64 rval;
+++ if (FromMountFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToMountFlags")]
+++ private static extern int ToMountFlags (UInt64 value, out MountFlags rval);
+++
+++ public static bool TryToMountFlags (UInt64 value, out MountFlags rval)
+++ {
+++ return ToMountFlags (value, out rval) == 0;
+++ }
+++
+++ public static MountFlags ToMountFlags (UInt64 value)
+++ {
+++ MountFlags rval;
+++ if (ToMountFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromMremapFlags")]
+++ private static extern int FromMremapFlags (MremapFlags value, out UInt64 rval);
+++
+++ public static bool TryFromMremapFlags (MremapFlags value, out UInt64 rval)
+++ {
+++ return FromMremapFlags (value, out rval) == 0;
+++ }
+++
+++ public static UInt64 FromMremapFlags (MremapFlags value)
+++ {
+++ UInt64 rval;
+++ if (FromMremapFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToMremapFlags")]
+++ private static extern int ToMremapFlags (UInt64 value, out MremapFlags rval);
+++
+++ public static bool TryToMremapFlags (UInt64 value, out MremapFlags rval)
+++ {
+++ return ToMremapFlags (value, out rval) == 0;
+++ }
+++
+++ public static MremapFlags ToMremapFlags (UInt64 value)
+++ {
+++ MremapFlags rval;
+++ if (ToMremapFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromMsyncFlags")]
+++ private static extern int FromMsyncFlags (MsyncFlags value, out Int32 rval);
+++
+++ public static bool TryFromMsyncFlags (MsyncFlags value, out Int32 rval)
+++ {
+++ return FromMsyncFlags (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromMsyncFlags (MsyncFlags value)
+++ {
+++ Int32 rval;
+++ if (FromMsyncFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToMsyncFlags")]
+++ private static extern int ToMsyncFlags (Int32 value, out MsyncFlags rval);
+++
+++ public static bool TryToMsyncFlags (Int32 value, out MsyncFlags rval)
+++ {
+++ return ToMsyncFlags (value, out rval) == 0;
+++ }
+++
+++ public static MsyncFlags ToMsyncFlags (Int32 value)
+++ {
+++ MsyncFlags rval;
+++ if (ToMsyncFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromOpenFlags")]
+++ private static extern int FromOpenFlags (OpenFlags value, out Int32 rval);
+++
+++ public static bool TryFromOpenFlags (OpenFlags value, out Int32 rval)
+++ {
+++ return FromOpenFlags (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromOpenFlags (OpenFlags value)
+++ {
+++ Int32 rval;
+++ if (FromOpenFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToOpenFlags")]
+++ private static extern int ToOpenFlags (Int32 value, out OpenFlags rval);
+++
+++ public static bool TryToOpenFlags (Int32 value, out OpenFlags rval)
+++ {
+++ return ToOpenFlags (value, out rval) == 0;
+++ }
+++
+++ public static OpenFlags ToOpenFlags (Int32 value)
+++ {
+++ OpenFlags rval;
+++ if (ToOpenFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromPathConf")]
+++ private static extern int FromPathConf (PathConf value, out Int32 rval);
+++
+++ public static bool TryFromPathConf (PathConf value, out Int32 rval)
+++ {
+++ return FromPathConf (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromPathConf (PathConf value)
+++ {
+++ Int32 rval;
+++ if (FromPathConf (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToPathConf")]
+++ private static extern int ToPathConf (Int32 value, out PathConf rval);
+++
+++ public static bool TryToPathConf (Int32 value, out PathConf rval)
+++ {
+++ return ToPathConf (value, out rval) == 0;
+++ }
+++
+++ public static PathConf ToPathConf (Int32 value)
+++ {
+++ PathConf rval;
+++ if (ToPathConf (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromPollEvents")]
+++ private static extern int FromPollEvents (PollEvents value, out Int16 rval);
+++
+++ public static bool TryFromPollEvents (PollEvents value, out Int16 rval)
+++ {
+++ return FromPollEvents (value, out rval) == 0;
+++ }
+++
+++ public static Int16 FromPollEvents (PollEvents value)
+++ {
+++ Int16 rval;
+++ if (FromPollEvents (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToPollEvents")]
+++ private static extern int ToPollEvents (Int16 value, out PollEvents rval);
+++
+++ public static bool TryToPollEvents (Int16 value, out PollEvents rval)
+++ {
+++ return ToPollEvents (value, out rval) == 0;
+++ }
+++
+++ public static PollEvents ToPollEvents (Int16 value)
+++ {
+++ PollEvents rval;
+++ if (ToPollEvents (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromPosixFadviseAdvice")]
+++ private static extern int FromPosixFadviseAdvice (PosixFadviseAdvice value, out Int32 rval);
+++
+++ public static bool TryFromPosixFadviseAdvice (PosixFadviseAdvice value, out Int32 rval)
+++ {
+++ return FromPosixFadviseAdvice (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromPosixFadviseAdvice (PosixFadviseAdvice value)
+++ {
+++ Int32 rval;
+++ if (FromPosixFadviseAdvice (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToPosixFadviseAdvice")]
+++ private static extern int ToPosixFadviseAdvice (Int32 value, out PosixFadviseAdvice rval);
+++
+++ public static bool TryToPosixFadviseAdvice (Int32 value, out PosixFadviseAdvice rval)
+++ {
+++ return ToPosixFadviseAdvice (value, out rval) == 0;
+++ }
+++
+++ public static PosixFadviseAdvice ToPosixFadviseAdvice (Int32 value)
+++ {
+++ PosixFadviseAdvice rval;
+++ if (ToPosixFadviseAdvice (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromPosixMadviseAdvice")]
+++ private static extern int FromPosixMadviseAdvice (PosixMadviseAdvice value, out Int32 rval);
+++
+++ public static bool TryFromPosixMadviseAdvice (PosixMadviseAdvice value, out Int32 rval)
+++ {
+++ return FromPosixMadviseAdvice (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromPosixMadviseAdvice (PosixMadviseAdvice value)
+++ {
+++ Int32 rval;
+++ if (FromPosixMadviseAdvice (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToPosixMadviseAdvice")]
+++ private static extern int ToPosixMadviseAdvice (Int32 value, out PosixMadviseAdvice rval);
+++
+++ public static bool TryToPosixMadviseAdvice (Int32 value, out PosixMadviseAdvice rval)
+++ {
+++ return ToPosixMadviseAdvice (value, out rval) == 0;
+++ }
+++
+++ public static PosixMadviseAdvice ToPosixMadviseAdvice (Int32 value)
+++ {
+++ PosixMadviseAdvice rval;
+++ if (ToPosixMadviseAdvice (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromSeekFlags")]
+++ private static extern int FromSeekFlags (SeekFlags value, out Int16 rval);
+++
+++ public static bool TryFromSeekFlags (SeekFlags value, out Int16 rval)
+++ {
+++ return FromSeekFlags (value, out rval) == 0;
+++ }
+++
+++ public static Int16 FromSeekFlags (SeekFlags value)
+++ {
+++ Int16 rval;
+++ if (FromSeekFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToSeekFlags")]
+++ private static extern int ToSeekFlags (Int16 value, out SeekFlags rval);
+++
+++ public static bool TryToSeekFlags (Int16 value, out SeekFlags rval)
+++ {
+++ return ToSeekFlags (value, out rval) == 0;
+++ }
+++
+++ public static SeekFlags ToSeekFlags (Int16 value)
+++ {
+++ SeekFlags rval;
+++ if (ToSeekFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromSignum")]
+++ private static extern int FromSignum (Signum value, out Int32 rval);
+++
+++ public static bool TryFromSignum (Signum value, out Int32 rval)
+++ {
+++ return FromSignum (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromSignum (Signum value)
+++ {
+++ Int32 rval;
+++ if (FromSignum (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToSignum")]
+++ private static extern int ToSignum (Int32 value, out Signum rval);
+++
+++ public static bool TryToSignum (Int32 value, out Signum rval)
+++ {
+++ return ToSignum (value, out rval) == 0;
+++ }
+++
+++ public static Signum ToSignum (Int32 value)
+++ {
+++ Signum rval;
+++ if (ToSignum (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromSysConf")]
+++ private static extern int FromSysConf (SysConf value, out Int32 rval);
+++
+++ public static bool TryFromSysConf (SysConf value, out Int32 rval)
+++ {
+++ return FromSysConf (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromSysConf (SysConf value)
+++ {
+++ Int32 rval;
+++ if (FromSysConf (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToSysConf")]
+++ private static extern int ToSysConf (Int32 value, out SysConf rval);
+++
+++ public static bool TryToSysConf (Int32 value, out SysConf rval)
+++ {
+++ return ToSysConf (value, out rval) == 0;
+++ }
+++
+++ public static SysConf ToSysConf (Int32 value)
+++ {
+++ SysConf rval;
+++ if (ToSysConf (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromSyslogFacility")]
+++ private static extern int FromSyslogFacility (SyslogFacility value, out Int32 rval);
+++
+++ public static bool TryFromSyslogFacility (SyslogFacility value, out Int32 rval)
+++ {
+++ return FromSyslogFacility (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromSyslogFacility (SyslogFacility value)
+++ {
+++ Int32 rval;
+++ if (FromSyslogFacility (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToSyslogFacility")]
+++ private static extern int ToSyslogFacility (Int32 value, out SyslogFacility rval);
+++
+++ public static bool TryToSyslogFacility (Int32 value, out SyslogFacility rval)
+++ {
+++ return ToSyslogFacility (value, out rval) == 0;
+++ }
+++
+++ public static SyslogFacility ToSyslogFacility (Int32 value)
+++ {
+++ SyslogFacility rval;
+++ if (ToSyslogFacility (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromSyslogLevel")]
+++ private static extern int FromSyslogLevel (SyslogLevel value, out Int32 rval);
+++
+++ public static bool TryFromSyslogLevel (SyslogLevel value, out Int32 rval)
+++ {
+++ return FromSyslogLevel (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromSyslogLevel (SyslogLevel value)
+++ {
+++ Int32 rval;
+++ if (FromSyslogLevel (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToSyslogLevel")]
+++ private static extern int ToSyslogLevel (Int32 value, out SyslogLevel rval);
+++
+++ public static bool TryToSyslogLevel (Int32 value, out SyslogLevel rval)
+++ {
+++ return ToSyslogLevel (value, out rval) == 0;
+++ }
+++
+++ public static SyslogLevel ToSyslogLevel (Int32 value)
+++ {
+++ SyslogLevel rval;
+++ if (ToSyslogLevel (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromSyslogOptions")]
+++ private static extern int FromSyslogOptions (SyslogOptions value, out Int32 rval);
+++
+++ public static bool TryFromSyslogOptions (SyslogOptions value, out Int32 rval)
+++ {
+++ return FromSyslogOptions (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromSyslogOptions (SyslogOptions value)
+++ {
+++ Int32 rval;
+++ if (FromSyslogOptions (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToSyslogOptions")]
+++ private static extern int ToSyslogOptions (Int32 value, out SyslogOptions rval);
+++
+++ public static bool TryToSyslogOptions (Int32 value, out SyslogOptions rval)
+++ {
+++ return ToSyslogOptions (value, out rval) == 0;
+++ }
+++
+++ public static SyslogOptions ToSyslogOptions (Int32 value)
+++ {
+++ SyslogOptions rval;
+++ if (ToSyslogOptions (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromWaitOptions")]
+++ private static extern int FromWaitOptions (WaitOptions value, out Int32 rval);
+++
+++ public static bool TryFromWaitOptions (WaitOptions value, out Int32 rval)
+++ {
+++ return FromWaitOptions (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromWaitOptions (WaitOptions value)
+++ {
+++ Int32 rval;
+++ if (FromWaitOptions (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToWaitOptions")]
+++ private static extern int ToWaitOptions (Int32 value, out WaitOptions rval);
+++
+++ public static bool TryToWaitOptions (Int32 value, out WaitOptions rval)
+++ {
+++ return ToWaitOptions (value, out rval) == 0;
+++ }
+++
+++ public static WaitOptions ToWaitOptions (Int32 value)
+++ {
+++ WaitOptions rval;
+++ if (ToWaitOptions (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_FromXattrFlags")]
+++ private static extern int FromXattrFlags (XattrFlags value, out Int32 rval);
+++
+++ public static bool TryFromXattrFlags (XattrFlags value, out Int32 rval)
+++ {
+++ return FromXattrFlags (value, out rval) == 0;
+++ }
+++
+++ public static Int32 FromXattrFlags (XattrFlags value)
+++ {
+++ Int32 rval;
+++ if (FromXattrFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ [DllImport (LIB, EntryPoint="Mono_Posix_ToXattrFlags")]
+++ private static extern int ToXattrFlags (Int32 value, out XattrFlags rval);
+++
+++ public static bool TryToXattrFlags (Int32 value, out XattrFlags rval)
+++ {
+++ return ToXattrFlags (value, out rval) == 0;
+++ }
+++
+++ public static XattrFlags ToXattrFlags (Int32 value)
+++ {
+++ XattrFlags rval;
+++ if (ToXattrFlags (value, out rval) == -1)
+++ ThrowArgumentException (value);
+++ return rval;
+++ }
+++
+++ }
+++}
+++
--- /dev/null
--- /dev/null
--- /dev/null
+++//
+++// Mono.Unix/Stdlib.cs
+++//
+++// Authors:
+++// Jonathan Pryor (jonpryor@vt.edu)
+++//
+++// (C) 2004-2005 Jonathan Pryor
+++//
+++// Permission is hereby granted, free of charge, to any person obtaining
+++// a copy of this software and associated documentation files (the
+++// "Software"), to deal in the Software without restriction, including
+++// without limitation the rights to use, copy, modify, merge, publish,
+++// distribute, sublicense, and/or sell copies of the Software, and to
+++// permit persons to whom the Software is furnished to do so, subject to
+++// the following conditions:
+++//
+++// The above copyright notice and this permission notice shall be
+++// included in all copies or substantial portions of the Software.
+++//
+++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+++//
+++
+++using System;
+++using System.Collections;
+++using System.IO;
+++using System.Runtime.InteropServices;
+++using System.Text;
+++using Mono.Unix.Native;
+++
+++namespace Mono.Unix.Native {
+++
+++ #region Enumerations
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum Errno : int {
+++ // errors & their values liberally copied from
+++ // FC2 /usr/include/asm/errno.h
+++
+++ EPERM = 1, // Operation not permitted
+++ ENOENT = 2, // No such file or directory
+++ ESRCH = 3, // No such process
+++ EINTR = 4, // Interrupted system call
+++ EIO = 5, // I/O error
+++ ENXIO = 6, // No such device or address
+++ E2BIG = 7, // Arg list too long
+++ ENOEXEC = 8, // Exec format error
+++ EBADF = 9, // Bad file number
+++ ECHILD = 10, // No child processes
+++ EAGAIN = 11, // Try again
+++ ENOMEM = 12, // Out of memory
+++ EACCES = 13, // Permission denied
+++ EFAULT = 14, // Bad address
+++ ENOTBLK = 15, // Block device required
+++ EBUSY = 16, // Device or resource busy
+++ EEXIST = 17, // File exists
+++ EXDEV = 18, // Cross-device link
+++ ENODEV = 19, // No such device
+++ ENOTDIR = 20, // Not a directory
+++ EISDIR = 21, // Is a directory
+++ EINVAL = 22, // Invalid argument
+++ ENFILE = 23, // File table overflow
+++ EMFILE = 24, // Too many open files
+++ ENOTTY = 25, // Not a typewriter
+++ ETXTBSY = 26, // Text file busy
+++ EFBIG = 27, // File too large
+++ ENOSPC = 28, // No space left on device
+++ ESPIPE = 29, // Illegal seek
+++ EROFS = 30, // Read-only file system
+++ EMLINK = 31, // Too many links
+++ EPIPE = 32, // Broken pipe
+++ EDOM = 33, // Math argument out of domain of func
+++ ERANGE = 34, // Math result not representable
+++ EDEADLK = 35, // Resource deadlock would occur
+++ ENAMETOOLONG = 36, // File name too long
+++ ENOLCK = 37, // No record locks available
+++ ENOSYS = 38, // Function not implemented
+++ ENOTEMPTY = 39, // Directory not empty
+++ ELOOP = 40, // Too many symbolic links encountered
+++ EWOULDBLOCK = EAGAIN, // Operation would block
+++ ENOMSG = 42, // No message of desired type
+++ EIDRM = 43, // Identifier removed
+++ ECHRNG = 44, // Channel number out of range
+++ EL2NSYNC = 45, // Level 2 not synchronized
+++ EL3HLT = 46, // Level 3 halted
+++ EL3RST = 47, // Level 3 reset
+++ ELNRNG = 48, // Link number out of range
+++ EUNATCH = 49, // Protocol driver not attached
+++ ENOCSI = 50, // No CSI structure available
+++ EL2HLT = 51, // Level 2 halted
+++ EBADE = 52, // Invalid exchange
+++ EBADR = 53, // Invalid request descriptor
+++ EXFULL = 54, // Exchange full
+++ ENOANO = 55, // No anode
+++ EBADRQC = 56, // Invalid request code
+++ EBADSLT = 57, // Invalid slot
+++
+++ EDEADLOCK = EDEADLK,
+++
+++ EBFONT = 59, // Bad font file format
+++ ENOSTR = 60, // Device not a stream
+++ ENODATA = 61, // No data available
+++ ETIME = 62, // Timer expired
+++ ENOSR = 63, // Out of streams resources
+++ ENONET = 64, // Machine is not on the network
+++ ENOPKG = 65, // Package not installed
+++ EREMOTE = 66, // Object is remote
+++ ENOLINK = 67, // Link has been severed
+++ EADV = 68, // Advertise error
+++ ESRMNT = 69, // Srmount error
+++ ECOMM = 70, // Communication error on send
+++ EPROTO = 71, // Protocol error
+++ EMULTIHOP = 72, // Multihop attempted
+++ EDOTDOT = 73, // RFS specific error
+++ EBADMSG = 74, // Not a data message
+++ EOVERFLOW = 75, // Value too large for defined data type
+++ ENOTUNIQ = 76, // Name not unique on network
+++ EBADFD = 77, // File descriptor in bad state
+++ EREMCHG = 78, // Remote address changed
+++ ELIBACC = 79, // Can not access a needed shared library
+++ ELIBBAD = 80, // Accessing a corrupted shared library
+++ ELIBSCN = 81, // .lib section in a.out corrupted
+++ ELIBMAX = 82, // Attempting to link in too many shared libraries
+++ ELIBEXEC = 83, // Cannot exec a shared library directly
+++ EILSEQ = 84, // Illegal byte sequence
+++ ERESTART = 85, // Interrupted system call should be restarted
+++ ESTRPIPE = 86, // Streams pipe error
+++ EUSERS = 87, // Too many users
+++ ENOTSOCK = 88, // Socket operation on non-socket
+++ EDESTADDRREQ = 89, // Destination address required
+++ EMSGSIZE = 90, // Message too long
+++ EPROTOTYPE = 91, // Protocol wrong type for socket
+++ ENOPROTOOPT = 92, // Protocol not available
+++ EPROTONOSUPPORT = 93, // Protocol not supported
+++ ESOCKTNOSUPPORT = 94, // Socket type not supported
+++ EOPNOTSUPP = 95, // Operation not supported on transport endpoint
+++ EPFNOSUPPORT = 96, // Protocol family not supported
+++ EAFNOSUPPORT = 97, // Address family not supported by protocol
+++ EADDRINUSE = 98, // Address already in use
+++ EADDRNOTAVAIL = 99, // Cannot assign requested address
+++ ENETDOWN = 100, // Network is down
+++ ENETUNREACH = 101, // Network is unreachable
+++ ENETRESET = 102, // Network dropped connection because of reset
+++ ECONNABORTED = 103, // Software caused connection abort
+++ ECONNRESET = 104, // Connection reset by peer
+++ ENOBUFS = 105, // No buffer space available
+++ EISCONN = 106, // Transport endpoint is already connected
+++ ENOTCONN = 107, // Transport endpoint is not connected
+++ ESHUTDOWN = 108, // Cannot send after transport endpoint shutdown
+++ ETOOMANYREFS = 109, // Too many references: cannot splice
+++ ETIMEDOUT = 110, // Connection timed out
+++ ECONNREFUSED = 111, // Connection refused
+++ EHOSTDOWN = 112, // Host is down
+++ EHOSTUNREACH = 113, // No route to host
+++ EALREADY = 114, // Operation already in progress
+++ EINPROGRESS = 115, // Operation now in progress
+++ ESTALE = 116, // Stale NFS file handle
+++ EUCLEAN = 117, // Structure needs cleaning
+++ ENOTNAM = 118, // Not a XENIX named type file
+++ ENAVAIL = 119, // No XENIX semaphores available
+++ EISNAM = 120, // Is a named type file
+++ EREMOTEIO = 121, // Remote I/O error
+++ EDQUOT = 122, // Quota exceeded
+++
+++ ENOMEDIUM = 123, // No medium found
+++ EMEDIUMTYPE = 124, // Wrong medium type
+++ }
+++
+++ #endregion
+++
+++ #region Classes
+++
+++ public sealed class FilePosition : IDisposable {
+++
+++ private static readonly int FilePositionDumpSize =
+++ Stdlib.DumpFilePosition (null, new HandleRef (null, IntPtr.Zero), 0);
+++
+++ private HandleRef pos;
+++
+++ public FilePosition ()
+++ {
+++ IntPtr p = Stdlib.CreateFilePosition ();
+++ if (p == IntPtr.Zero)
+++ throw new OutOfMemoryException ("Unable to malloc fpos_t!");
+++ pos = new HandleRef (this, p);
+++ }
+++
+++ internal HandleRef Handle {
+++ get {return pos;}
+++ }
+++
+++ public void Dispose ()
+++ {
+++ Cleanup ();
+++ GC.SuppressFinalize (this);
+++ }
+++
+++ private void Cleanup ()
+++ {
+++ if (pos.Handle != IntPtr.Zero) {
+++ Stdlib.free (pos.Handle);
+++ pos = new HandleRef (this, IntPtr.Zero);
+++ }
+++ }
+++
+++ public override string ToString ()
+++ {
+++ return "(" + base.ToString () + " " + GetDump () + ")";
+++ }
+++
+++ private string GetDump ()
+++ {
+++ if (FilePositionDumpSize <= 0)
+++ return "internal error";
+++
+++ StringBuilder buf = new StringBuilder (FilePositionDumpSize+1);
+++
+++ if (Stdlib.DumpFilePosition (buf, Handle, FilePositionDumpSize+1) <= 0)
+++ return "internal error dumping fpos_t";
+++
+++ return buf.ToString ();
+++ }
+++
+++ public override bool Equals (object obj)
+++ {
+++ if (obj == null || GetType() != obj.GetType())
+++ return false;
+++ return ToString().Equals (obj.ToString());
+++ }
+++
+++ public override int GetHashCode ()
+++ {
+++ return ToString ().GetHashCode ();
+++ }
+++
+++ ~FilePosition ()
+++ {
+++ Cleanup ();
+++ }
+++
+++ public static bool operator== (FilePosition lhs, FilePosition rhs)
+++ {
+++ return Object.Equals (lhs, rhs);
+++ }
+++
+++ public static bool operator!= (FilePosition lhs, FilePosition rhs)
+++ {
+++ return !Object.Equals (lhs, rhs);
+++ }
+++ }
+++
+++
+++ //
+++ // Right now using this attribute gives an assert because it
+++ // isn't implemented.
+++ //
+++#if NET_2_0 && UNMANAGED_FN_PTR_SUPPORT_FIXED
+++ [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
+++#endif
+++ public delegate void SignalHandler (int signal);
+++
+++#if !NET_2_0
+++ internal sealed class SignalWrapper {
+++ private IntPtr handler;
+++
+++ internal SignalWrapper (IntPtr handler)
+++ {
+++ this.handler = handler;
+++ }
+++
+++ public void InvokeSignalHandler (int signum)
+++ {
+++ Stdlib.InvokeSignalHandler (signum, handler);
+++ }
+++ }
+++#endif
+++
+++ internal class XPrintfFunctions
+++ {
+++ internal delegate object XPrintf (object[] parameters);
+++
+++ internal static XPrintf printf;
+++ internal static XPrintf fprintf;
+++ internal static XPrintf snprintf;
+++ internal static XPrintf syslog;
+++
+++ static XPrintfFunctions ()
+++ {
+++ CdeclFunction _printf = new CdeclFunction (Stdlib.LIBC, "printf", typeof(int));
+++ printf = new XPrintf (_printf.Invoke);
+++
+++ CdeclFunction _fprintf = new CdeclFunction (Stdlib.LIBC, "fprintf", typeof(int));
+++ fprintf = new XPrintf (_fprintf.Invoke);
+++
+++ CdeclFunction _snprintf = new CdeclFunction (Stdlib.MPH,
+++ "Mono_Posix_Stdlib_snprintf", typeof(int));
+++ snprintf = new XPrintf (_snprintf.Invoke);
+++
+++ CdeclFunction _syslog = new CdeclFunction (Syscall.LIBC, "syslog", typeof(void));
+++ syslog = new XPrintf (_syslog.Invoke);
+++ }
+++ }
+++
+++ //
+++ // Convention: Functions that are part of the C standard library go here.
+++ //
+++ // For example, the man page should say something similar to:
+++ //
+++ // CONFORMING TO
+++ // ISO 9899 (''ANSI C'')
+++ //
+++ // The intent is that members of this class should be portable to any system
+++ // supporting the C runtime (read: non-Unix, including Windows). Using
+++ // anything from Syscall is non-portable, but restricting yourself to just
+++ // Stdlib is intended to be portable.
+++ //
+++ public class Stdlib
+++ {
+++ internal const string LIBC = "msvcrt";
+++ internal const string MPH = "MonoPosixHelper";
+++
+++ internal Stdlib () {}
+++
+++ #region <errno.h> Declarations
+++ //
+++ // <errno.h> -- COMPLETE
+++ //
+++
+++ [CLSCompliant (false)]
+++ public static Errno GetLastError ()
+++ {
+++ int errno = Marshal.GetLastWin32Error ();
+++ return NativeConvert.ToErrno (errno);
+++ }
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_SetLastError")]
+++ private static extern void SetLastError (int error);
+++
+++ [CLSCompliant (false)]
+++ public static void SetLastError (Errno error)
+++ {
+++ int _error = NativeConvert.FromErrno (error);
+++ SetLastError (_error);
+++ }
+++ #endregion
+++
+++ //
+++ // <signal.h>
+++ //
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_InvokeSignalHandler")]
+++ internal static extern void InvokeSignalHandler (int signum, IntPtr handler);
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_SIG_DFL")]
+++ private static extern IntPtr GetDefaultSignal ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_SIG_ERR")]
+++ private static extern IntPtr GetErrorSignal ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_SIG_IGN")]
+++ private static extern IntPtr GetIgnoreSignal ();
+++
+++ private static readonly IntPtr _SIG_DFL = GetDefaultSignal ();
+++ private static readonly IntPtr _SIG_ERR = GetErrorSignal ();
+++ private static readonly IntPtr _SIG_IGN = GetIgnoreSignal ();
+++
+++ private static void _ErrorHandler (int signum)
+++ {
+++ Console.Error.WriteLine ("Error handler invoked for signum " +
+++ signum + ". Don't do that.");
+++ }
+++
+++ private static void _DefaultHandler (int signum)
+++ {
+++ Console.Error.WriteLine ("Default handler invoked for signum " +
+++ signum + ". Don't do that.");
+++ }
+++
+++ private static void _IgnoreHandler (int signum)
+++ {
+++ Console.Error.WriteLine ("Ignore handler invoked for signum " +
+++ signum + ". Don't do that.");
+++ }
+++
+++ [CLSCompliant (false)]
+++ public static readonly SignalHandler SIG_DFL = new SignalHandler (_DefaultHandler);
+++ [CLSCompliant (false)]
+++ public static readonly SignalHandler SIG_ERR = new SignalHandler (_ErrorHandler);
+++ [CLSCompliant (false)]
+++ public static readonly SignalHandler SIG_IGN = new SignalHandler (_IgnoreHandler);
+++
+++ private static readonly SignalHandler[] registered_signals;
+++
+++ static Stdlib ()
+++ {
+++ Array signals = Enum.GetValues(typeof(Signum));
+++ registered_signals = new SignalHandler [(int) signals.GetValue (signals.Length-1)];
+++ }
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="signal")]
+++ private static extern IntPtr sys_signal (int signum, SignalHandler handler);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="signal")]
+++ private static extern IntPtr sys_signal (int signum, IntPtr handler);
+++
+++ [CLSCompliant (false)]
+++ public static SignalHandler signal (Signum signum, SignalHandler handler)
+++ {
+++ int _sig = NativeConvert.FromSignum (signum);
+++
+++ lock (registered_signals) {
+++ registered_signals [(int) signum] = handler;
+++ }
+++
+++ IntPtr r;
+++ if (handler == SIG_DFL)
+++ r = sys_signal (_sig, _SIG_DFL);
+++ else if (handler == SIG_ERR)
+++ r = sys_signal (_sig, _SIG_ERR);
+++ else if (handler == SIG_IGN)
+++ r = sys_signal (_sig, _SIG_IGN);
+++ else
+++ r = sys_signal (_sig, handler);
+++ return TranslateHandler (r);
+++ }
+++
+++ private static SignalHandler TranslateHandler (IntPtr handler)
+++ {
+++ if (handler == _SIG_DFL)
+++ return SIG_DFL;
+++ if (handler == _SIG_ERR)
+++ return SIG_ERR;
+++ if (handler == _SIG_IGN)
+++ return SIG_IGN;
+++#if NET_2_0
+++ return (SignalHandler) Marshal.GetDelegateForFunctionPointer (handler, typeof(SignalHandler));
+++#else
+++ return new SignalHandler (new SignalWrapper (handler).InvokeSignalHandler);
+++#endif
+++ }
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, EntryPoint="raise")]
+++ private static extern int sys_raise (int sig);
+++
+++ [CLSCompliant (false)]
+++ public static int raise (Signum sig)
+++ {
+++ int _sig = NativeConvert.FromSignum (sig);
+++ return sys_raise (_sig);
+++ }
+++
+++ //
+++ // <stdio.h> -- COMPLETE except for :
+++ // - the scanf(3) family .
+++ // - vararg functions.
+++ // - Horribly unsafe functions (gets(3)).
+++ //
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib__IOFBF")]
+++ private static extern int GetFullyBuffered ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib__IOLBF")]
+++ private static extern int GetLineBuffered ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib__IONBF")]
+++ private static extern int GetNonBuffered ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_BUFSIZ")]
+++ private static extern int GetBufferSize ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_CreateFilePosition")]
+++ internal static extern IntPtr CreateFilePosition ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_DumpFilePosition")]
+++ internal static extern int DumpFilePosition (StringBuilder buf, HandleRef handle, int len);
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_EOF")]
+++ private static extern int GetEOF ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_FILENAME_MAX")]
+++ private static extern int GetFilenameMax ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_FOPEN_MAX")]
+++ private static extern int GetFopenMax ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_L_tmpnam")]
+++ private static extern int GetTmpnamLength ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_stdin")]
+++ private static extern IntPtr GetStandardInput ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_stdout")]
+++ private static extern IntPtr GetStandardOutput ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_stderr")]
+++ private static extern IntPtr GetStandardError ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_TMP_MAX")]
+++ private static extern int GetTmpMax ();
+++
+++ [CLSCompliant (false)]
+++ public static readonly int _IOFBF = GetFullyBuffered ();
+++ [CLSCompliant (false)]
+++ public static readonly int _IOLBF = GetLineBuffered ();
+++ [CLSCompliant (false)]
+++ public static readonly int _IONBF = GetNonBuffered ();
+++ [CLSCompliant (false)]
+++ public static readonly int BUFSIZ = GetBufferSize ();
+++ [CLSCompliant (false)]
+++ public static readonly int EOF = GetEOF ();
+++ [CLSCompliant (false)]
+++ public static readonly int FOPEN_MAX = GetFopenMax ();
+++ [CLSCompliant (false)]
+++ public static readonly int FILENAME_MAX = GetFilenameMax ();
+++ [CLSCompliant (false)]
+++ public static readonly int L_tmpnam = GetTmpnamLength ();
+++ public static readonly IntPtr stderr = GetStandardError ();
+++ public static readonly IntPtr stdin = GetStandardInput ();
+++ public static readonly IntPtr stdout = GetStandardOutput ();
+++ [CLSCompliant (false)]
+++ public static readonly int TMP_MAX = GetTmpMax ();
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int remove (string filename);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int rename (string oldpath, string newpath);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern IntPtr tmpfile ();
+++
+++ private static object tmpnam_lock = new object ();
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="tmpnam")]
+++ private static extern IntPtr sys_tmpnam (StringBuilder s);
+++
+++ [Obsolete ("Syscall.mkstemp() should be preferred.")]
+++ public static string tmpnam (StringBuilder s)
+++ {
+++ if (s != null && s.Capacity < L_tmpnam)
+++ throw new ArgumentOutOfRangeException ("s", "s.Capacity < L_tmpnam");
+++ lock (tmpnam_lock) {
+++ IntPtr r = sys_tmpnam (s);
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++
+++ [Obsolete ("Syscall.mkstemp() should be preferred.")]
+++ public static string tmpnam ()
+++ {
+++ lock (tmpnam_lock) {
+++ IntPtr r = sys_tmpnam (null);
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int fclose (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int fflush (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern IntPtr fopen (string path, string mode);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern IntPtr freopen (string path, string mode, IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern void setbuf (IntPtr stream, IntPtr buf);
+++
+++ [CLSCompliant (false)]
+++ public static unsafe void setbuf (IntPtr stream, byte* buf)
+++ {
+++ setbuf (stream, (IntPtr) buf);
+++ }
+++
+++ [CLSCompliant (false)]
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_setvbuf")]
+++ public static extern int setvbuf (IntPtr stream, IntPtr buf, int mode, ulong size);
+++
+++ [CLSCompliant (false)]
+++ public static unsafe int setvbuf (IntPtr stream, byte* buf, int mode, ulong size)
+++ {
+++ return setvbuf (stream, (IntPtr) buf, mode, size);
+++ }
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="fprintf")]
+++ private static extern int sys_fprintf (IntPtr stream, string format, string message);
+++
+++ public static int fprintf (IntPtr stream, string message)
+++ {
+++ return sys_fprintf (stream, "%s", message);
+++ }
+++
+++ [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
+++ "Use fprintf (IntPtr, string) instead.")]
+++ public static int fprintf (IntPtr stream, string format, params object[] parameters)
+++ {
+++ object[] _parameters = new object[checked(parameters.Length+2)];
+++ _parameters [0] = stream;
+++ _parameters [1] = format;
+++ Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
+++ return (int) XPrintfFunctions.fprintf (_parameters);
+++ }
+++
+++ /* SKIP: fscanf(3) */
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="printf")]
+++ private static extern int sys_printf (string format, string message);
+++
+++ public static int printf (string message)
+++ {
+++ return sys_printf ("%s", message);
+++ }
+++
+++ [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
+++ "Use printf (string) instead.")]
+++ public static int printf (string format, params object[] parameters)
+++ {
+++ object[] _parameters = new object[checked(parameters.Length+1)];
+++ _parameters [0] = format;
+++ Array.Copy (parameters, 0, _parameters, 1, parameters.Length);
+++ return (int) XPrintfFunctions.printf (_parameters);
+++ }
+++
+++ /* SKIP: scanf(3) */
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_snprintf")]
+++ private static extern int sys_snprintf (StringBuilder s, ulong n,
+++ string format, string message);
+++
+++ [CLSCompliant (false)]
+++ public static int snprintf (StringBuilder s, ulong n, string message)
+++ {
+++ if (n > (ulong) s.Capacity)
+++ throw new ArgumentOutOfRangeException ("n", "n must be <= s.Capacity");
+++ return sys_snprintf (s, n, "%s", message);
+++ }
+++
+++ public static int snprintf (StringBuilder s, string message)
+++ {
+++ return sys_snprintf (s, (ulong) s.Capacity, "%s", message);
+++ }
+++
+++ [CLSCompliant (false)]
+++ [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
+++ "Use snprintf (StringBuilder, string) instead.")]
+++ public static int snprintf (StringBuilder s, ulong n,
+++ string format, params object[] parameters)
+++ {
+++ if (n > (ulong) s.Capacity)
+++ throw new ArgumentOutOfRangeException ("n", "n must be <= s.Capacity");
+++
+++ object[] _parameters = new object[checked(parameters.Length+3)];
+++ _parameters [0] = s;
+++ _parameters [1] = n;
+++ _parameters [2] = format;
+++ Array.Copy (parameters, 0, _parameters, 3, parameters.Length);
+++ return (int) XPrintfFunctions.snprintf (_parameters);
+++ }
+++
+++ [CLSCompliant (false)]
+++ [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
+++ "Use snprintf (StringBuilder, string) instead.")]
+++ public static int snprintf (StringBuilder s,
+++ string format, params object[] parameters)
+++ {
+++ object[] _parameters = new object[checked(parameters.Length+3)];
+++ _parameters [0] = s;
+++ _parameters [1] = (ulong) s.Capacity;
+++ _parameters [2] = format;
+++ Array.Copy (parameters, 0, _parameters, 3, parameters.Length);
+++ return (int) XPrintfFunctions.snprintf (_parameters);
+++ }
+++
+++ /*
+++ * SKIP:
+++ * sprintf(3)
+++ * sscanf(3)
+++ * vfprintf(3)
+++ * vfscanf(3)
+++ * vprintf(3)
+++ * vscanf(3)
+++ * vsnprintf(3)
+++ * vsprint(3)
+++ * vsscanf(3)
+++ */
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int fgetc (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="fgets")]
+++ private static extern IntPtr sys_fgets (StringBuilder sb, int size, IntPtr stream);
+++
+++ public static StringBuilder fgets (StringBuilder sb, int size, IntPtr stream)
+++ {
+++ IntPtr r = sys_fgets (sb, size, stream);
+++ if (r == IntPtr.Zero)
+++ return null;
+++ return sb;
+++ }
+++
+++ public static StringBuilder fgets (StringBuilder sb, IntPtr stream)
+++ {
+++ return fgets (sb, sb.Capacity, stream);
+++ }
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int fputc (int c, IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int fputs (string s, IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int getc (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int getchar ();
+++
+++ /* SKIP: gets(3) */
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int putc (int c, IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int putchar (int c);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int puts (string s);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int ungetc (int c, IntPtr stream);
+++
+++ [CLSCompliant (false)]
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_fread")]
+++ public static extern ulong fread (IntPtr ptr, ulong size, ulong nmemb, IntPtr stream);
+++
+++ [CLSCompliant (false)]
+++ public static unsafe ulong fread (void* ptr, ulong size, ulong nmemb, IntPtr stream)
+++ {
+++ return fread ((IntPtr) ptr, size, nmemb, stream);
+++ }
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_fread")]
+++ private static extern ulong sys_fread ([Out] byte[] ptr,
+++ ulong size, ulong nmemb, IntPtr stream);
+++
+++ [CLSCompliant (false)]
+++ public static ulong fread (byte[] ptr, ulong size, ulong nmemb, IntPtr stream)
+++ {
+++ if ((size * nmemb) > (ulong) ptr.Length)
+++ throw new ArgumentOutOfRangeException ("nmemb");
+++ return sys_fread (ptr, size, nmemb, stream);
+++ }
+++
+++ [CLSCompliant (false)]
+++ public static ulong fread (byte[] ptr, IntPtr stream)
+++ {
+++ return fread (ptr, 1, (ulong) ptr.Length, stream);
+++ }
+++
+++ [CLSCompliant (false)]
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_fwrite")]
+++ public static extern ulong fwrite (IntPtr ptr, ulong size, ulong nmemb, IntPtr stream);
+++
+++ [CLSCompliant (false)]
+++ public static unsafe ulong fwrite (void* ptr, ulong size, ulong nmemb, IntPtr stream)
+++ {
+++ return fwrite ((IntPtr) ptr, size, nmemb, stream);
+++ }
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_fwrite")]
+++ private static extern ulong sys_fwrite (byte[] ptr,
+++ ulong size, ulong nmemb, IntPtr stream);
+++
+++ [CLSCompliant (false)]
+++ public static ulong fwrite (byte[] ptr, ulong size, ulong nmemb, IntPtr stream)
+++ {
+++ if ((size * nmemb) > (ulong) ptr.Length)
+++ throw new ArgumentOutOfRangeException ("nmemb");
+++ return sys_fwrite (ptr, size, nmemb, stream);
+++ }
+++
+++ [CLSCompliant (false)]
+++ public static ulong fwrite (byte[] ptr, IntPtr stream)
+++ {
+++ return fwrite (ptr, 1, (ulong) ptr.Length, stream);
+++ }
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_fgetpos")]
+++ private static extern int sys_fgetpos (IntPtr stream, HandleRef pos);
+++
+++ public static int fgetpos (IntPtr stream, FilePosition pos)
+++ {
+++ return sys_fgetpos (stream, pos.Handle);
+++ }
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_fseek")]
+++ private static extern int sys_fseek (IntPtr stream, long offset, int origin);
+++
+++ [CLSCompliant (false)]
+++ public static int fseek (IntPtr stream, long offset, SeekFlags origin)
+++ {
+++ int _origin = NativeConvert.FromSeekFlags (origin);
+++ return sys_fseek (stream, offset, _origin);
+++ }
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_fsetpos")]
+++ private static extern int sys_fsetpos (IntPtr stream, HandleRef pos);
+++
+++ public static int fsetpos (IntPtr stream, FilePosition pos)
+++ {
+++ return sys_fsetpos (stream, pos.Handle);
+++ }
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_ftell")]
+++ public static extern long ftell (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern void rewind (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern void clearerr (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern int feof (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern int ferror (IntPtr stream);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern void perror (string s);
+++
+++ //
+++ // <stdlib.h>
+++ //
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_EXIT_FAILURE")]
+++ private static extern int GetExitFailure();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_EXIT_SUCCESS")]
+++ private static extern int GetExitSuccess ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_MB_CUR_MAX")]
+++ private static extern int GetMbCurMax ();
+++
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ EntryPoint="Mono_Posix_Stdlib_RAND_MAX")]
+++ private static extern int GetRandMax ();
+++
+++ [CLSCompliant (false)]
+++ public static readonly int EXIT_FAILURE = GetExitFailure ();
+++ [CLSCompliant (false)]
+++ public static readonly int EXIT_SUCCESS = GetExitSuccess ();
+++ [CLSCompliant (false)]
+++ public static readonly int MB_CUR_MAX = GetMbCurMax ();
+++ [CLSCompliant (false)]
+++ public static readonly int RAND_MAX = GetRandMax ();
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern int rand ();
+++
+++ [CLSCompliant (false)]
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern void srand (uint seed);
+++
+++ // calloc(3):
+++ // void *calloc (size_t nmemb, size_t size);
+++ [CLSCompliant (false)]
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_calloc")]
+++ public static extern IntPtr calloc (ulong nmemb, ulong size);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern void free (IntPtr ptr);
+++
+++ // malloc(3):
+++ // void *malloc(size_t size);
+++ [CLSCompliant (false)]
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_malloc")]
+++ public static extern IntPtr malloc (ulong size);
+++
+++ // realloc(3):
+++ // void *realloc(void *ptr, size_t size);
+++ [CLSCompliant (false)]
+++ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="Mono_Posix_Stdlib_realloc")]
+++ public static extern IntPtr realloc (IntPtr ptr, ulong size);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern void abort ();
+++
+++ /* SKIP: atexit(3) -- the GC should have collected most references by the
+++ * time this runs, so no delegates should exist, making it pointless. */
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern void exit (int status);
+++
+++ [CLSCompliant (false)]
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl)]
+++ public static extern void _Exit (int status);
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, EntryPoint="getenv")]
+++ private static extern IntPtr sys_getenv (string name);
+++
+++ public static string getenv (string name)
+++ {
+++ IntPtr r = sys_getenv (name);
+++ return UnixMarshal.PtrToString (r);
+++ }
+++
+++ [CLSCompliant (false)]
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl, SetLastError=true)]
+++ public static extern int system (string @string);
+++
+++ //
+++ // <string.h>
+++ //
+++
+++ private static object strerror_lock = new object ();
+++
+++ [DllImport (LIBC, CallingConvention=CallingConvention.Cdecl,
+++ SetLastError=true, EntryPoint="strerror")]
+++ private static extern IntPtr sys_strerror (int errnum);
+++
+++ [CLSCompliant (false)]
+++ public static string strerror (Errno errnum)
+++ {
+++ int e = NativeConvert.FromErrno (errnum);
+++ lock (strerror_lock) {
+++ IntPtr r = sys_strerror (e);
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++ }
+++
+++ #endregion // Classes
+++}
+++
+++// vim: noexpandtab
--- /dev/null
--- /dev/null
--- /dev/null
+++//
+++// Mono.Unix/Syscall.cs
+++//
+++// Authors:
+++// Miguel de Icaza (miguel@novell.com)
+++// Jonathan Pryor (jonpryor@vt.edu)
+++//
+++// (C) 2003 Novell, Inc.
+++// (C) 2004-2005 Jonathan Pryor
+++//
+++// This file implements the low-level syscall interface to the POSIX
+++// subsystem.
+++//
+++// This file tries to stay close to the low-level API as much as possible
+++// using enumerations, structures and in a few cases, using existing .NET
+++// data types.
+++//
+++// Implementation notes:
+++//
+++// Since the values for the various constants on the API changes
+++// from system to system (even Linux on different architectures will
+++// have different values), we define our own set of values, and we
+++// use a set of C helper routines to map from the constants we define
+++// to the values of the native OS.
+++//
+++// Bitfields are flagged with the [Map] attribute, and a helper program
+++// generates a set of routines that we can call to convert from our value
+++// definitions to the value definitions expected by the OS; see
+++// NativeConvert for the conversion routines.
+++//
+++// Methods that require tuning are bound as `private sys_NAME' methods
+++// and then a `NAME' method is exposed.
+++//
+++
+++//
+++// Permission is hereby granted, free of charge, to any person obtaining
+++// a copy of this software and associated documentation files (the
+++// "Software"), to deal in the Software without restriction, including
+++// without limitation the rights to use, copy, modify, merge, publish,
+++// distribute, sublicense, and/or sell copies of the Software, and to
+++// permit persons to whom the Software is furnished to do so, subject to
+++// the following conditions:
+++//
+++// The above copyright notice and this permission notice shall be
+++// included in all copies or substantial portions of the Software.
+++//
+++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+++//
+++
+++using System;
+++using System.Collections;
+++using System.Runtime.InteropServices;
+++using System.Text;
+++using Mono.Unix.Native;
+++
+++[assembly:Mono.Unix.Native.HeaderAttribute (
+++ Includes=
+++ "sys/types.h," +
+++ "sys/stat.h," +
+++ "ah:sys/poll.h," +
+++ "ah:sys/wait.h," +
+++ "ah:sys/statvfs.h," +
+++ "ah:sys/xattr.h," +
+++ "unistd.h," +
+++ "fcntl.h," +
+++ "signal.h," +
+++ "ah:poll.h," +
+++ "ah:grp.h," +
+++ "errno.h," +
+++ "ah:syslog.h",
+++ Defines=
+++ "_GNU_SOURCE," +
+++ "_XOPEN_SOURCE"
+++)]
+++
+++namespace Mono.Unix.Native {
+++
+++ #region Enumerations
+++
+++ [Flags][Map]
+++ [CLSCompliant (false)]
+++ public enum SyslogOptions {
+++ LOG_PID = 0x01, // log the pid with each message
+++ LOG_CONS = 0x02, // log on the console if errors in sending
+++ LOG_ODELAY = 0x04, // delay open until first syslog (default)
+++ LOG_NDELAY = 0x08, // don't delay open
+++ LOG_NOWAIT = 0x10, // don't wait for console forks; DEPRECATED
+++ LOG_PERROR = 0x20 // log to stderr as well
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum SyslogFacility {
+++ LOG_KERN = 0 << 3,
+++ LOG_USER = 1 << 3,
+++ [Obsolete ("use SyslogFacility.LOG_USER")]
+++ LOG_USRE = 1 << 3,
+++ LOG_MAIL = 2 << 3,
+++ LOG_DAEMON = 3 << 3,
+++ LOG_AUTH = 4 << 3,
+++ LOG_SYSLOG = 5 << 3,
+++ LOG_LPR = 6 << 3,
+++ LOG_NEWS = 7 << 3,
+++ LOG_UUCP = 8 << 3,
+++ LOG_CRON = 9 << 3,
+++ LOG_AUTHPRIV = 10 << 3,
+++ LOG_FTP = 11 << 3,
+++ LOG_LOCAL0 = 16 << 3,
+++ LOG_LOCAL1 = 17 << 3,
+++ LOG_LOCAL2 = 18 << 3,
+++ LOG_LOCAL3 = 19 << 3,
+++ LOG_LOCAL4 = 20 << 3,
+++ LOG_LOCAL5 = 21 << 3,
+++ LOG_LOCAL6 = 22 << 3,
+++ LOG_LOCAL7 = 23 << 3,
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum SyslogLevel {
+++ LOG_EMERG = 0, // system is unusable
+++ LOG_ALERT = 1, // action must be taken immediately
+++ LOG_CRIT = 2, // critical conditions
+++ LOG_ERR = 3, // warning conditions
+++ LOG_WARNING = 4, // warning conditions
+++ LOG_NOTICE = 5, // normal but significant condition
+++ LOG_INFO = 6, // informational
+++ LOG_DEBUG = 7 // debug-level messages
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum OpenFlags : int {
+++ //
+++ // One of these
+++ //
+++ O_RDONLY = 0x00000000,
+++ O_WRONLY = 0x00000001,
+++ O_RDWR = 0x00000002,
+++
+++ //
+++ // Or-ed with zero or more of these
+++ //
+++ O_CREAT = 0x00000040,
+++ O_EXCL = 0x00000080,
+++ O_NOCTTY = 0x00000100,
+++ O_TRUNC = 0x00000200,
+++ O_APPEND = 0x00000400,
+++ O_NONBLOCK = 0x00000800,
+++ O_SYNC = 0x00001000,
+++
+++ //
+++ // These are non-Posix. Using them will result in errors/exceptions on
+++ // non-supported platforms.
+++ //
+++ // (For example, "C-wrapped" system calls -- calls with implementation in
+++ // MonoPosixHelper -- will return -1 with errno=EINVAL. C#-wrapped system
+++ // calls will generate an exception in NativeConvert, as the value can't be
+++ // converted on the target platform.)
+++ //
+++
+++ O_NOFOLLOW = 0x00020000,
+++ O_DIRECTORY = 0x00010000,
+++ O_DIRECT = 0x00004000,
+++ O_ASYNC = 0x00002000,
+++ O_LARGEFILE = 0x00008000
+++ }
+++
+++ // mode_t
+++ [Flags][Map]
+++ [CLSCompliant (false)]
+++ public enum FilePermissions : uint {
+++ S_ISUID = 0x0800, // Set user ID on execution
+++ S_ISGID = 0x0400, // Set gorup ID on execution
+++ S_ISVTX = 0x0200, // Save swapped text after use (sticky).
+++ S_IRUSR = 0x0100, // Read by owner
+++ S_IWUSR = 0x0080, // Write by owner
+++ S_IXUSR = 0x0040, // Execute by owner
+++ S_IRGRP = 0x0020, // Read by group
+++ S_IWGRP = 0x0010, // Write by group
+++ S_IXGRP = 0x0008, // Execute by group
+++ S_IROTH = 0x0004, // Read by other
+++ S_IWOTH = 0x0002, // Write by other
+++ S_IXOTH = 0x0001, // Execute by other
+++
+++ S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
+++ S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
+++ S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
+++ ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
+++ ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
+++ DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
+++
+++ // Device types
+++ // Why these are held in "mode_t" is beyond me...
+++ S_IFMT = 0xF000, // Bits which determine file type
+++ S_IFDIR = 0x4000, // Directory
+++ S_IFCHR = 0x2000, // Character device
+++ S_IFBLK = 0x6000, // Block device
+++ S_IFREG = 0x8000, // Regular file
+++ S_IFIFO = 0x1000, // FIFO
+++ S_IFLNK = 0xA000, // Symbolic link
+++ S_IFSOCK = 0xC000, // Socket
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum FcntlCommand : int {
+++ // Form /usr/include/bits/fcntl.h
+++ F_DUPFD = 0, // Duplicate file descriptor.
+++ F_GETFD = 1, // Get file descriptor flags.
+++ F_SETFD = 2, // Set file descriptor flags.
+++ F_GETFL = 3, // Get file status flags.
+++ F_SETFL = 4, // Set file status flags.
+++ F_GETLK = 12, // Get record locking info. [64]
+++ F_SETLK = 13, // Set record locking info (non-blocking). [64]
+++ F_SETLKW = 14, // Set record locking info (blocking). [64]
+++ F_SETOWN = 8, // Set owner of socket (receiver of SIGIO).
+++ F_GETOWN = 9, // Get owner of socket (receiver of SIGIO).
+++ F_SETSIG = 10, // Set number of signal to be sent.
+++ F_GETSIG = 11, // Get number of signal to be sent.
+++ F_SETLEASE = 1024, // Set a lease.
+++ F_GETLEASE = 1025, // Enquire what lease is active.
+++ F_NOTIFY = 1026, // Required notifications on a directory
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum LockType : short {
+++ F_RDLCK = 0, // Read lock.
+++ F_WRLCK = 1, // Write lock.
+++ F_UNLCK = 2, // Remove lock.
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum SeekFlags : short {
+++ // values liberally copied from /usr/include/unistd.h
+++ SEEK_SET = 0, // Seek from beginning of file.
+++ SEEK_CUR = 1, // Seek from current position.
+++ SEEK_END = 2, // Seek from end of file.
+++
+++ L_SET = SEEK_SET, // BSD alias for SEEK_SET
+++ L_INCR = SEEK_CUR, // BSD alias for SEEK_CUR
+++ L_XTND = SEEK_END, // BSD alias for SEEK_END
+++ }
+++
+++ [Map, Flags]
+++ [CLSCompliant (false)]
+++ public enum DirectoryNotifyFlags : int {
+++ // from /usr/include/bits/fcntl.h
+++ DN_ACCESS = 0x00000001, // File accessed.
+++ DN_MODIFY = 0x00000002, // File modified.
+++ DN_CREATE = 0x00000004, // File created.
+++ DN_DELETE = 0x00000008, // File removed.
+++ DN_RENAME = 0x00000010, // File renamed.
+++ DN_ATTRIB = 0x00000020, // File changed attributes.
+++ DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum PosixFadviseAdvice : int {
+++ POSIX_FADV_NORMAL = 0, // No further special treatment.
+++ POSIX_FADV_RANDOM = 1, // Expect random page references.
+++ POSIX_FADV_SEQUENTIAL = 2, // Expect sequential page references.
+++ POSIX_FADV_WILLNEED = 3, // Will need these pages.
+++ POSIX_FADV_DONTNEED = 4, // Don't need these pages.
+++ POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum PosixMadviseAdvice : int {
+++ POSIX_MADV_NORMAL = 0, // No further special treatment.
+++ POSIX_MADV_RANDOM = 1, // Expect random page references.
+++ POSIX_MADV_SEQUENTIAL = 2, // Expect sequential page references.
+++ POSIX_MADV_WILLNEED = 3, // Will need these pages.
+++ POSIX_MADV_DONTNEED = 4, // Don't need these pages.
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum Signum : int {
+++ SIGHUP = 1, // Hangup (POSIX).
+++ SIGINT = 2, // Interrupt (ANSI).
+++ SIGQUIT = 3, // Quit (POSIX).
+++ SIGILL = 4, // Illegal instruction (ANSI).
+++ SIGTRAP = 5, // Trace trap (POSIX).
+++ SIGABRT = 6, // Abort (ANSI).
+++ SIGIOT = 6, // IOT trap (4.2 BSD).
+++ SIGBUS = 7, // BUS error (4.2 BSD).
+++ SIGFPE = 8, // Floating-point exception (ANSI).
+++ SIGKILL = 9, // Kill, unblockable (POSIX).
+++ SIGUSR1 = 10, // User-defined signal 1 (POSIX).
+++ SIGSEGV = 11, // Segmentation violation (ANSI).
+++ SIGUSR2 = 12, // User-defined signal 2 (POSIX).
+++ SIGPIPE = 13, // Broken pipe (POSIX).
+++ SIGALRM = 14, // Alarm clock (POSIX).
+++ SIGTERM = 15, // Termination (ANSI).
+++ SIGSTKFLT = 16, // Stack fault.
+++ SIGCLD = SIGCHLD, // Same as SIGCHLD (System V).
+++ SIGCHLD = 17, // Child status has changed (POSIX).
+++ SIGCONT = 18, // Continue (POSIX).
+++ SIGSTOP = 19, // Stop, unblockable (POSIX).
+++ SIGTSTP = 20, // Keyboard stop (POSIX).
+++ SIGTTIN = 21, // Background read from tty (POSIX).
+++ SIGTTOU = 22, // Background write to tty (POSIX).
+++ SIGURG = 23, // Urgent condition on socket (4.2 BSD).
+++ SIGXCPU = 24, // CPU limit exceeded (4.2 BSD).
+++ SIGXFSZ = 25, // File size limit exceeded (4.2 BSD).
+++ SIGVTALRM = 26, // Virtual alarm clock (4.2 BSD).
+++ SIGPROF = 27, // Profiling alarm clock (4.2 BSD).
+++ SIGWINCH = 28, // Window size change (4.3 BSD, Sun).
+++ SIGPOLL = SIGIO, // Pollable event occurred (System V).
+++ SIGIO = 29, // I/O now possible (4.2 BSD).
+++ SIGPWR = 30, // Power failure restart (System V).
+++ SIGSYS = 31, // Bad system call.
+++ SIGUNUSED = 31
+++ }
+++
+++ [Flags][Map]
+++ [CLSCompliant (false)]
+++ public enum WaitOptions : int {
+++ WNOHANG = 1, // Don't block waiting
+++ WUNTRACED = 2, // Report status of stopped children
+++ }
+++
+++ [Flags][Map]
+++ [CLSCompliant (false)]
+++ public enum AccessModes : int {
+++ R_OK = 1,
+++ W_OK = 2,
+++ X_OK = 4,
+++ F_OK = 8,
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum PathConf : int {
+++ _PC_LINK_MAX,
+++ _PC_MAX_CANON,
+++ _PC_MAX_INPUT,
+++ _PC_NAME_MAX,
+++ _PC_PATH_MAX,
+++ _PC_PIPE_BUF,
+++ _PC_CHOWN_RESTRICTED,
+++ _PC_NO_TRUNC,
+++ _PC_VDISABLE,
+++ _PC_SYNC_IO,
+++ _PC_ASYNC_IO,
+++ _PC_PRIO_IO,
+++ _PC_SOCK_MAXBUF,
+++ _PC_FILESIZEBITS,
+++ _PC_REC_INCR_XFER_SIZE,
+++ _PC_REC_MAX_XFER_SIZE,
+++ _PC_REC_MIN_XFER_SIZE,
+++ _PC_REC_XFER_ALIGN,
+++ _PC_ALLOC_SIZE_MIN,
+++ _PC_SYMLINK_MAX,
+++ _PC_2_SYMLINKS
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum SysConf : int {
+++ _SC_ARG_MAX,
+++ _SC_CHILD_MAX,
+++ _SC_CLK_TCK,
+++ _SC_NGROUPS_MAX,
+++ _SC_OPEN_MAX,
+++ _SC_STREAM_MAX,
+++ _SC_TZNAME_MAX,
+++ _SC_JOB_CONTROL,
+++ _SC_SAVED_IDS,
+++ _SC_REALTIME_SIGNALS,
+++ _SC_PRIORITY_SCHEDULING,
+++ _SC_TIMERS,
+++ _SC_ASYNCHRONOUS_IO,
+++ _SC_PRIORITIZED_IO,
+++ _SC_SYNCHRONIZED_IO,
+++ _SC_FSYNC,
+++ _SC_MAPPED_FILES,
+++ _SC_MEMLOCK,
+++ _SC_MEMLOCK_RANGE,
+++ _SC_MEMORY_PROTECTION,
+++ _SC_MESSAGE_PASSING,
+++ _SC_SEMAPHORES,
+++ _SC_SHARED_MEMORY_OBJECTS,
+++ _SC_AIO_LISTIO_MAX,
+++ _SC_AIO_MAX,
+++ _SC_AIO_PRIO_DELTA_MAX,
+++ _SC_DELAYTIMER_MAX,
+++ _SC_MQ_OPEN_MAX,
+++ _SC_MQ_PRIO_MAX,
+++ _SC_VERSION,
+++ _SC_PAGESIZE,
+++ _SC_RTSIG_MAX,
+++ _SC_SEM_NSEMS_MAX,
+++ _SC_SEM_VALUE_MAX,
+++ _SC_SIGQUEUE_MAX,
+++ _SC_TIMER_MAX,
+++ /* Values for the argument to `sysconf'
+++ corresponding to _POSIX2_* symbols. */
+++ _SC_BC_BASE_MAX,
+++ _SC_BC_DIM_MAX,
+++ _SC_BC_SCALE_MAX,
+++ _SC_BC_STRING_MAX,
+++ _SC_COLL_WEIGHTS_MAX,
+++ _SC_EQUIV_CLASS_MAX,
+++ _SC_EXPR_NEST_MAX,
+++ _SC_LINE_MAX,
+++ _SC_RE_DUP_MAX,
+++ _SC_CHARCLASS_NAME_MAX,
+++ _SC_2_VERSION,
+++ _SC_2_C_BIND,
+++ _SC_2_C_DEV,
+++ _SC_2_FORT_DEV,
+++ _SC_2_FORT_RUN,
+++ _SC_2_SW_DEV,
+++ _SC_2_LOCALEDEF,
+++ _SC_PII,
+++ _SC_PII_XTI,
+++ _SC_PII_SOCKET,
+++ _SC_PII_INTERNET,
+++ _SC_PII_OSI,
+++ _SC_POLL,
+++ _SC_SELECT,
+++ _SC_UIO_MAXIOV,
+++ _SC_IOV_MAX = _SC_UIO_MAXIOV,
+++ _SC_PII_INTERNET_STREAM,
+++ _SC_PII_INTERNET_DGRAM,
+++ _SC_PII_OSI_COTS,
+++ _SC_PII_OSI_CLTS,
+++ _SC_PII_OSI_M,
+++ _SC_T_IOV_MAX,
+++ /* Values according to POSIX 1003.1c (POSIX threads). */
+++ _SC_THREADS,
+++ _SC_THREAD_SAFE_FUNCTIONS,
+++ _SC_GETGR_R_SIZE_MAX,
+++ _SC_GETPW_R_SIZE_MAX,
+++ _SC_LOGIN_NAME_MAX,
+++ _SC_TTY_NAME_MAX,
+++ _SC_THREAD_DESTRUCTOR_ITERATIONS,
+++ _SC_THREAD_KEYS_MAX,
+++ _SC_THREAD_STACK_MIN,
+++ _SC_THREAD_THREADS_MAX,
+++ _SC_THREAD_ATTR_STACKADDR,
+++ _SC_THREAD_ATTR_STACKSIZE,
+++ _SC_THREAD_PRIORITY_SCHEDULING,
+++ _SC_THREAD_PRIO_INHERIT,
+++ _SC_THREAD_PRIO_PROTECT,
+++ _SC_THREAD_PROCESS_SHARED,
+++ _SC_NPROCESSORS_CONF,
+++ _SC_NPROCESSORS_ONLN,
+++ _SC_PHYS_PAGES,
+++ _SC_AVPHYS_PAGES,
+++ _SC_ATEXIT_MAX,
+++ _SC_PASS_MAX,
+++ _SC_XOPEN_VERSION,
+++ _SC_XOPEN_XCU_VERSION,
+++ _SC_XOPEN_UNIX,
+++ _SC_XOPEN_CRYPT,
+++ _SC_XOPEN_ENH_I18N,
+++ _SC_XOPEN_SHM,
+++ _SC_2_CHAR_TERM,
+++ _SC_2_C_VERSION,
+++ _SC_2_UPE,
+++ _SC_XOPEN_XPG2,
+++ _SC_XOPEN_XPG3,
+++ _SC_XOPEN_XPG4,
+++ _SC_CHAR_BIT,
+++ _SC_CHAR_MAX,
+++ _SC_CHAR_MIN,
+++ _SC_INT_MAX,
+++ _SC_INT_MIN,
+++ _SC_LONG_BIT,
+++ _SC_WORD_BIT,
+++ _SC_MB_LEN_MAX,
+++ _SC_NZERO,
+++ _SC_SSIZE_MAX,
+++ _SC_SCHAR_MAX,
+++ _SC_SCHAR_MIN,
+++ _SC_SHRT_MAX,
+++ _SC_SHRT_MIN,
+++ _SC_UCHAR_MAX,
+++ _SC_UINT_MAX,
+++ _SC_ULONG_MAX,
+++ _SC_USHRT_MAX,
+++ _SC_NL_ARGMAX,
+++ _SC_NL_LANGMAX,
+++ _SC_NL_MSGMAX,
+++ _SC_NL_NMAX,
+++ _SC_NL_SETMAX,
+++ _SC_NL_TEXTMAX,
+++ _SC_XBS5_ILP32_OFF32,
+++ _SC_XBS5_ILP32_OFFBIG,
+++ _SC_XBS5_LP64_OFF64,
+++ _SC_XBS5_LPBIG_OFFBIG,
+++ _SC_XOPEN_LEGACY,
+++ _SC_XOPEN_REALTIME,
+++ _SC_XOPEN_REALTIME_THREADS,
+++ _SC_ADVISORY_INFO,
+++ _SC_BARRIERS,
+++ _SC_BASE,
+++ _SC_C_LANG_SUPPORT,
+++ _SC_C_LANG_SUPPORT_R,
+++ _SC_CLOCK_SELECTION,
+++ _SC_CPUTIME,
+++ _SC_THREAD_CPUTIME,
+++ _SC_DEVICE_IO,
+++ _SC_DEVICE_SPECIFIC,
+++ _SC_DEVICE_SPECIFIC_R,
+++ _SC_FD_MGMT,
+++ _SC_FIFO,
+++ _SC_PIPE,
+++ _SC_FILE_ATTRIBUTES,
+++ _SC_FILE_LOCKING,
+++ _SC_FILE_SYSTEM,
+++ _SC_MONOTONIC_CLOCK,
+++ _SC_MULTI_PROCESS,
+++ _SC_SINGLE_PROCESS,
+++ _SC_NETWORKING,
+++ _SC_READER_WRITER_LOCKS,
+++ _SC_SPIN_LOCKS,
+++ _SC_REGEXP,
+++ _SC_REGEX_VERSION,
+++ _SC_SHELL,
+++ _SC_SIGNALS,
+++ _SC_SPAWN,
+++ _SC_SPORADIC_SERVER,
+++ _SC_THREAD_SPORADIC_SERVER,
+++ _SC_SYSTEM_DATABASE,
+++ _SC_SYSTEM_DATABASE_R,
+++ _SC_TIMEOUTS,
+++ _SC_TYPED_MEMORY_OBJECTS,
+++ _SC_USER_GROUPS,
+++ _SC_USER_GROUPS_R,
+++ _SC_2_PBS,
+++ _SC_2_PBS_ACCOUNTING,
+++ _SC_2_PBS_LOCATE,
+++ _SC_2_PBS_MESSAGE,
+++ _SC_2_PBS_TRACK,
+++ _SC_SYMLOOP_MAX,
+++ _SC_STREAMS,
+++ _SC_2_PBS_CHECKPOINT,
+++ _SC_V6_ILP32_OFF32,
+++ _SC_V6_ILP32_OFFBIG,
+++ _SC_V6_LP64_OFF64,
+++ _SC_V6_LPBIG_OFFBIG,
+++ _SC_HOST_NAME_MAX,
+++ _SC_TRACE,
+++ _SC_TRACE_EVENT_FILTER,
+++ _SC_TRACE_INHERIT,
+++ _SC_TRACE_LOG,
+++ _SC_LEVEL1_ICACHE_SIZE,
+++ _SC_LEVEL1_ICACHE_ASSOC,
+++ _SC_LEVEL1_ICACHE_LINESIZE,
+++ _SC_LEVEL1_DCACHE_SIZE,
+++ _SC_LEVEL1_DCACHE_ASSOC,
+++ _SC_LEVEL1_DCACHE_LINESIZE,
+++ _SC_LEVEL2_CACHE_SIZE,
+++ _SC_LEVEL2_CACHE_ASSOC,
+++ _SC_LEVEL2_CACHE_LINESIZE,
+++ _SC_LEVEL3_CACHE_SIZE,
+++ _SC_LEVEL3_CACHE_ASSOC,
+++ _SC_LEVEL3_CACHE_LINESIZE,
+++ _SC_LEVEL4_CACHE_SIZE,
+++ _SC_LEVEL4_CACHE_ASSOC,
+++ _SC_LEVEL4_CACHE_LINESIZE
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum ConfStr : int {
+++ _CS_PATH, /* The default search path. */
+++ _CS_V6_WIDTH_RESTRICTED_ENVS,
+++ _CS_GNU_LIBC_VERSION,
+++ _CS_GNU_LIBPTHREAD_VERSION,
+++ _CS_LFS_CFLAGS = 1000,
+++ _CS_LFS_LDFLAGS,
+++ _CS_LFS_LIBS,
+++ _CS_LFS_LINTFLAGS,
+++ _CS_LFS64_CFLAGS,
+++ _CS_LFS64_LDFLAGS,
+++ _CS_LFS64_LIBS,
+++ _CS_LFS64_LINTFLAGS,
+++ _CS_XBS5_ILP32_OFF32_CFLAGS = 1100,
+++ _CS_XBS5_ILP32_OFF32_LDFLAGS,
+++ _CS_XBS5_ILP32_OFF32_LIBS,
+++ _CS_XBS5_ILP32_OFF32_LINTFLAGS,
+++ _CS_XBS5_ILP32_OFFBIG_CFLAGS,
+++ _CS_XBS5_ILP32_OFFBIG_LDFLAGS,
+++ _CS_XBS5_ILP32_OFFBIG_LIBS,
+++ _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
+++ _CS_XBS5_LP64_OFF64_CFLAGS,
+++ _CS_XBS5_LP64_OFF64_LDFLAGS,
+++ _CS_XBS5_LP64_OFF64_LIBS,
+++ _CS_XBS5_LP64_OFF64_LINTFLAGS,
+++ _CS_XBS5_LPBIG_OFFBIG_CFLAGS,
+++ _CS_XBS5_LPBIG_OFFBIG_LDFLAGS,
+++ _CS_XBS5_LPBIG_OFFBIG_LIBS,
+++ _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS,
+++ _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
+++ _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,
+++ _CS_POSIX_V6_ILP32_OFF32_LIBS,
+++ _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS,
+++ _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
+++ _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,
+++ _CS_POSIX_V6_ILP32_OFFBIG_LIBS,
+++ _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS,
+++ _CS_POSIX_V6_LP64_OFF64_CFLAGS,
+++ _CS_POSIX_V6_LP64_OFF64_LDFLAGS,
+++ _CS_POSIX_V6_LP64_OFF64_LIBS,
+++ _CS_POSIX_V6_LP64_OFF64_LINTFLAGS,
+++ _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS,
+++ _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS,
+++ _CS_POSIX_V6_LPBIG_OFFBIG_LIBS,
+++ _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
+++ }
+++
+++ [Map]
+++ [CLSCompliant (false)]
+++ public enum LockfCommand : int {
+++ F_ULOCK = 0, // Unlock a previously locked region.
+++ F_LOCK = 1, // Lock a region for exclusive use.
+++ F_TLOCK = 2, // Test and lock a region for exclusive use.
+++ F_TEST = 3, // Test a region for other process locks.
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum PollEvents : short {
+++ POLLIN = 0x0001, // There is data to read
+++ POLLPRI = 0x0002, // There is urgent data to read
+++ POLLOUT = 0x0004, // Writing now will not block
+++ POLLERR = 0x0008, // Error condition
+++ POLLHUP = 0x0010, // Hung up
+++ POLLNVAL = 0x0020, // Invalid request; fd not open
+++ // XPG4.2 definitions (via _XOPEN_SOURCE)
+++ POLLRDNORM = 0x0040, // Normal data bay be read
+++ POLLRDBAND = 0x0080, // Priority data may be read
+++ POLLWRNORM = 0x0100, // Writing now will not block
+++ POLLWRBAND = 0x0200, // Priority data may be written
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum XattrFlags : int {
+++ XATTR_AUTO = 0,
+++ XATTR_CREATE = 1,
+++ XATTR_REPLACE = 2,
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum MountFlags : ulong {
+++ ST_RDONLY = 1, // Mount read-only
+++ ST_NOSUID = 2, // Ignore suid and sgid bits
+++ ST_NODEV = 4, // Disallow access to device special files
+++ ST_SYNCHRONOUS = 16, // Writes are synced at once
+++ ST_MANDLOCK = 64, // Allow mandatory locks on an FS
+++ ST_WRITE = 128, // Write on file/directory/symlink
+++ ST_APPEND = 256, // Append-only file
+++ ST_IMMUTABLE = 512, // Immutable file
+++ ST_NOATIME = 1024, // Do not update access times
+++ ST_NODIRATIME = 2048, // Do not update directory access times
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum MmapFlags : int {
+++ MAP_SHARED = 0x01, // Share changes.
+++ MAP_PRIVATE = 0x02, // Changes are private.
+++ MAP_TYPE = 0x0f, // Mask for type of mapping.
+++ MAP_FIXED = 0x10, // Interpret addr exactly.
+++ MAP_FILE = 0,
+++ MAP_ANONYMOUS = 0x20, // Don't use a file.
+++ MAP_ANON = MAP_ANONYMOUS,
+++
+++ // These are Linux-specific.
+++ MAP_GROWSDOWN = 0x00100, // Stack-like segment.
+++ MAP_DENYWRITE = 0x00800, // ETXTBSY
+++ MAP_EXECUTABLE = 0x01000, // Mark it as an executable.
+++ MAP_LOCKED = 0x02000, // Lock the mapping.
+++ MAP_NORESERVE = 0x04000, // Don't check for reservations.
+++ MAP_POPULATE = 0x08000, // Populate (prefault) pagetables.
+++ MAP_NONBLOCK = 0x10000, // Do not block on IO.
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum MmapProts : int {
+++ PROT_READ = 0x1, // Page can be read.
+++ PROT_WRITE = 0x2, // Page can be written.
+++ PROT_EXEC = 0x4, // Page can be executed.
+++ PROT_NONE = 0x0, // Page can not be accessed.
+++ PROT_GROWSDOWN = 0x01000000, // Extend change to start of
+++ // growsdown vma (mprotect only).
+++ PROT_GROWSUP = 0x02000000, // Extend change to start of
+++ // growsup vma (mprotect only).
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum MsyncFlags : int {
+++ MS_ASYNC = 0x1, // Sync memory asynchronously.
+++ MS_SYNC = 0x4, // Synchronous memory sync.
+++ MS_INVALIDATE = 0x2, // Invalidate the caches.
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum MlockallFlags : int {
+++ MCL_CURRENT = 0x1, // Lock all currently mapped pages.
+++ MCL_FUTURE = 0x2, // Lock all additions to address
+++ }
+++
+++ [Map][Flags]
+++ [CLSCompliant (false)]
+++ public enum MremapFlags : ulong {
+++ MREMAP_MAYMOVE = 0x1,
+++ }
+++
+++ #endregion
+++
+++ #region Structures
+++
+++ public struct Flock {
+++ [CLSCompliant (false)]
+++ public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
+++ [CLSCompliant (false)]
+++ public SeekFlags l_whence; // How to interpret l_start
+++ public /* off_t */ long l_start; // Starting offset for lock
+++ public /* off_t */ long l_len; // Number of bytes to lock
+++ public /* pid_t */ int l_pid; // PID of process blocking our lock (F_GETLK only)
+++ }
+++
+++ [StructLayout(LayoutKind.Sequential)]
+++ public struct Pollfd {
+++ public int fd;
+++ [CLSCompliant (false)]
+++ public PollEvents events;
+++ [CLSCompliant (false)]
+++ public PollEvents revents;
+++ }
+++
+++ public struct Stat {
+++ [CLSCompliant (false)]
+++ public /* dev_t */ ulong st_dev; // device
+++ [CLSCompliant (false)]
+++ public /* ino_t */ ulong st_ino; // inode
+++ [CLSCompliant (false)]
+++ public FilePermissions st_mode; // protection
+++ [CLSCompliant (false)]
+++ private uint _padding_; // padding for structure alignment
+++ [CLSCompliant (false)]
+++ public /* nlink_t */ ulong st_nlink; // number of hard links
+++ [CLSCompliant (false)]
+++ public /* uid_t */ uint st_uid; // user ID of owner
+++ [CLSCompliant (false)]
+++ public /* gid_t */ uint st_gid; // group ID of owner
+++ [CLSCompliant (false)]
+++ public /* dev_t */ ulong st_rdev; // device type (if inode device)
+++ public /* off_t */ long st_size; // total size, in bytes
+++ public /* blksize_t */ long st_blksize; // blocksize for filesystem I/O
+++ public /* blkcnt_t */ long st_blocks; // number of blocks allocated
+++ public /* time_t */ long st_atime; // time of last access
+++ public /* time_t */ long st_mtime; // time of last modification
+++ public /* time_t */ long st_ctime; // time of last status change
+++ }
+++
+++ [CLSCompliant (false)]
+++ public struct Statvfs {
+++ public ulong f_bsize; // file system block size
+++ public ulong f_frsize; // fragment size
+++ public /* fsblkcnt_t */ ulong f_blocks; // size of fs in f_frsize units
+++ public /* fsblkcnt_t */ ulong f_bfree; // # free blocks
+++ public /* fsblkcnt_t */ ulong f_bavail; // # free blocks for non-root
+++ public /* fsfilcnt_t */ ulong f_files; // # inodes
+++ public /* fsfilcnt_t */ ulong f_ffree; // # free inodes
+++ public /* fsfilcnt_t */ ulong f_favail; // # free inodes for non-root
+++ public ulong f_fsid; // file system id
+++ public MountFlags f_flag; // mount flags
+++ public ulong f_namemax; // maximum filename length
+++ }
+++
+++ public struct Timeval {
+++ public /* time_t */ long tv_sec; // seconds
+++ public /* suseconds_t */ long tv_usec; // microseconds
+++ }
+++
+++ public struct Timezone {
+++ public int tz_minuteswest; // minutes W of Greenwich
+++ private int tz_dsttime; // type of dst correction (OBSOLETE)
+++ }
+++
+++ public struct Utimbuf {
+++ public /* time_t */ long actime; // access time
+++ public /* time_t */ long modtime; // modification time
+++ }
+++
+++ #endregion
+++
+++ #region Classes
+++
+++ [CLSCompliant (false)]
+++ public sealed class Dirent
+++ {
+++ [CLSCompliant (false)]
+++ public /* ino_t */ ulong d_ino;
+++ public /* off_t */ long d_off;
+++ [CLSCompliant (false)]
+++ public ushort d_reclen;
+++ public byte d_type;
+++ public string d_name;
+++
+++ public override int GetHashCode ()
+++ {
+++ return d_ino.GetHashCode () ^ d_off.GetHashCode () ^
+++ d_reclen.GetHashCode () ^ d_type.GetHashCode () ^
+++ d_name.GetHashCode ();
+++ }
+++
+++ public override bool Equals (object obj)
+++ {
+++ if (obj == null || GetType() != obj.GetType())
+++ return false;
+++ Dirent d = (Dirent) obj;
+++ return d.d_ino == d_ino && d.d_off == d_off &&
+++ d.d_reclen == d_reclen && d.d_type == d_type &&
+++ d.d_name == d_name;
+++ }
+++
+++ public override string ToString ()
+++ {
+++ return d_name;
+++ }
+++
+++ public static bool operator== (Dirent lhs, Dirent rhs)
+++ {
+++ return Object.Equals (lhs, rhs);
+++ }
+++
+++ public static bool operator!= (Dirent lhs, Dirent rhs)
+++ {
+++ return !Object.Equals (lhs, rhs);
+++ }
+++ }
+++
+++ public sealed class Fstab
+++ {
+++ public string fs_spec;
+++ public string fs_file;
+++ public string fs_vfstype;
+++ public string fs_mntops;
+++ public string fs_type;
+++ public int fs_freq;
+++ public int fs_passno;
+++
+++ public override int GetHashCode ()
+++ {
+++ return fs_spec.GetHashCode () ^ fs_file.GetHashCode () ^
+++ fs_vfstype.GetHashCode () ^ fs_mntops.GetHashCode () ^
+++ fs_type.GetHashCode () ^ fs_freq ^ fs_passno;
+++ }
+++
+++ public override bool Equals (object obj)
+++ {
+++ if (obj == null || GetType() != obj.GetType())
+++ return false;
+++ Fstab f = (Fstab) obj;
+++ return f.fs_spec == fs_spec && f.fs_file == fs_file &&
+++ f.fs_vfstype == fs_vfstype && f.fs_mntops == fs_mntops &&
+++ f.fs_type == fs_type && f.fs_freq == fs_freq &&
+++ f.fs_passno == fs_passno;
+++ }
+++
+++ public override string ToString ()
+++ {
+++ return fs_spec;
+++ }
+++
+++ public static bool operator== (Fstab lhs, Fstab rhs)
+++ {
+++ return Object.Equals (lhs, rhs);
+++ }
+++
+++ public static bool operator!= (Fstab lhs, Fstab rhs)
+++ {
+++ return !Object.Equals (lhs, rhs);
+++ }
+++ }
+++
+++ public sealed class Group
+++ {
+++ public string gr_name;
+++ public string gr_passwd;
+++ [CLSCompliant (false)]
+++ public /* gid_t */ uint gr_gid;
+++ public string[] gr_mem;
+++
+++ public override int GetHashCode ()
+++ {
+++ int memhc = 0;
+++ for (int i = 0; i < gr_mem.Length; ++i)
+++ memhc ^= gr_mem[i].GetHashCode ();
+++
+++ return gr_name.GetHashCode () ^ gr_passwd.GetHashCode () ^
+++ gr_gid.GetHashCode () ^ memhc;
+++ }
+++
+++ public override bool Equals (object obj)
+++ {
+++ if (obj == null || GetType() != obj.GetType())
+++ return false;
+++ Group g = (Group) obj;
+++ if (g.gr_gid != gr_gid)
+++ return false;
+++ if (g.gr_gid == gr_gid && g.gr_name == gr_name &&
+++ g.gr_passwd == gr_passwd) {
+++ if (g.gr_mem == gr_mem)
+++ return true;
+++ if (g.gr_mem == null || gr_mem == null)
+++ return false;
+++ if (g.gr_mem.Length != gr_mem.Length)
+++ return false;
+++ for (int i = 0; i < gr_mem.Length; ++i)
+++ if (gr_mem[i] != g.gr_mem[i])
+++ return false;
+++ return true;
+++ }
+++ return false;
+++ }
+++
+++ // Generate string in /etc/group format
+++ public override string ToString ()
+++ {
+++ StringBuilder sb = new StringBuilder ();
+++ sb.AppendFormat ("{0}:{1}:{2}:", gr_name, gr_passwd, gr_gid);
+++ GetMembers (sb, gr_mem);
+++ return sb.ToString ();
+++ }
+++
+++ private static void GetMembers (StringBuilder sb, string[] members)
+++ {
+++ if (members.Length > 0)
+++ sb.Append (members[0]);
+++ for (int i = 1; i < members.Length; ++i) {
+++ sb.Append (",");
+++ sb.Append (members[i]);
+++ }
+++ }
+++
+++ public static bool operator== (Group lhs, Group rhs)
+++ {
+++ return Object.Equals (lhs, rhs);
+++ }
+++
+++ public static bool operator!= (Group lhs, Group rhs)
+++ {
+++ return !Object.Equals (lhs, rhs);
+++ }
+++ }
+++
+++ public sealed class Passwd
+++ {
+++ public string pw_name;
+++ public string pw_passwd;
+++ [CLSCompliant (false)]
+++ public /* uid_t */ uint pw_uid;
+++ [CLSCompliant (false)]
+++ public /* gid_t */ uint pw_gid;
+++ public string pw_gecos;
+++ public string pw_dir;
+++ public string pw_shell;
+++
+++ public override int GetHashCode ()
+++ {
+++ return pw_name.GetHashCode () ^ pw_passwd.GetHashCode () ^
+++ pw_uid.GetHashCode () ^ pw_gid.GetHashCode () ^
+++ pw_gecos.GetHashCode () ^ pw_dir.GetHashCode () ^
+++ pw_dir.GetHashCode () ^ pw_shell.GetHashCode ();
+++ }
+++
+++ public override bool Equals (object obj)
+++ {
+++ if (obj == null || GetType() != obj.GetType())
+++ return false;
+++ Passwd p = (Passwd) obj;
+++ return p.pw_uid == pw_uid && p.pw_gid == pw_gid && p.pw_name == pw_name &&
+++ p.pw_passwd == pw_passwd && p.pw_gecos == pw_gecos &&
+++ p.pw_dir == pw_dir && p.pw_shell == pw_shell;
+++ }
+++
+++ // Generate string in /etc/passwd format
+++ public override string ToString ()
+++ {
+++ return string.Format ("{0}:{1}:{2}:{3}:{4}:{5}:{6}",
+++ pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell);
+++ }
+++
+++ public static bool operator== (Passwd lhs, Passwd rhs)
+++ {
+++ return Object.Equals (lhs, rhs);
+++ }
+++
+++ public static bool operator!= (Passwd lhs, Passwd rhs)
+++ {
+++ return !Object.Equals (lhs, rhs);
+++ }
+++ }
+++
+++ //
+++ // Convention: Functions *not* part of the standard C library AND part of
+++ // a POSIX and/or Unix standard (X/Open, SUS, XPG, etc.) go here.
+++ //
+++ // For example, the man page should be similar to:
+++ //
+++ // CONFORMING TO (or CONFORMS TO)
+++ // XPG2, SUSv2, POSIX, etc.
+++ //
+++ // BSD- and GNU-specific exports can also be placed here.
+++ //
+++ // Non-POSIX/XPG/etc. functions can also be placed here if:
+++ // (a) They'd be likely to be covered in a Steven's-like book
+++ // (b) The functions would be present in libc.so (or equivalent).
+++ //
+++ // If a function has its own library, that's a STRONG indicator that the
+++ // function should get a different binding, probably in its own assembly,
+++ // so that package management can work sanely. (That is, we'd like to avoid
+++ // scenarios where FooLib.dll is installed, but it requires libFooLib.so to
+++ // run, and libFooLib.so doesn't exist. That would be confusing.)
+++ //
+++ // The only methods in here should be:
+++ // (1) low-level functions
+++ // (2) "Trivial" function overloads. For example, if the parameters to a
+++ // function are related (e.g. getgroups(2))
+++ // (3) The return type SHOULD NOT be changed. If you want to provide a
+++ // convenience function with a nicer return type, place it into one of
+++ // the Mono.Unix.Unix* wrapper classes, and give it a .NET-styled name.
+++ // (4) Exceptions SHOULD NOT be thrown. EXCEPTIONS:
+++ // - If you're wrapping *broken* methods which make assumptions about
+++ // input data, such as that an argument refers to N bytes of data.
+++ // This is currently limited to cuserid(3) and encrypt(3).
+++ // - If you call functions which themselves generate exceptions.
+++ // This is the case for using NativeConvert, which will throw an
+++ // exception if an invalid/unsupported value is used.
+++ //
+++ // Naming Conventions:
+++ // - Syscall method names should have the same name as the function being
+++ // wrapped (e.g. Syscall.read ==> read(2)). This allows people to
+++ // consult the appropriate man page if necessary.
+++ // - Methods need not have the same arguments IF this simplifies or
+++ // permits correct usage. The current example is syslog, in which
+++ // syslog(3)'s single `priority' argument is split into SyslogFacility
+++ // and SyslogLevel arguments.
+++ // - Type names (structures, classes, enumerations) are always PascalCased.
+++ // - Enumerations are named as <MethodName><ArgumentName>, and are located
+++ // in the Mono.Unix namespace. For readability, if ArgumentName is
+++ // "cmd", use Command instead. For example, fcntl(2) takes a
+++ // FcntlCommand argument. This naming convention is to provide an
+++ // assocation between an enumeration and where it should be used, and
+++ // allows a single method to accept multiple different enumerations
+++ // (see mmap(2), which takes MmapProts and MmapFlags).
+++ // - EXCEPTION: if an enumeration is shared between multiple different
+++ // methods, AND/OR the "obvious" enumeration name conflicts with an
+++ // existing .NET type, a more appropriate name should be used.
+++ // Example: FilePermissions
+++ // - EXCEPTION: [Flags] enumerations should get plural names to follow
+++ // .NET name guidelines. Usually this doesn't result in a change
+++ // (OpenFlags is the `flags' parameter for open(2)), but it can
+++ // (mmap(2) prot ==> MmapProts, access(2) mode ==> AccessModes).
+++ // - Enumerations should have the [Map] and (optional) [Flags] attributes.
+++ // [Map] is required for make-map to find the type and generate the
+++ // appropriate NativeConvert conversion functions.
+++ // - Enumeration contents should match the original Unix names. This helps
+++ // with documentation (the existing man pages are still useful), and is
+++ // required for use with the make-map generation program.
+++ // - Structure names should be the PascalCased version of the actual
+++ // structure name (struct flock ==> Flock). Structure members should
+++ // have the same names, or a (reasonably) portable subset (Dirent being
+++ // the poster child for questionable members).
+++ // - Whether the managed type should be a reference type (class) or a
+++ // value type (struct) should be determined on a case-by-case basis:
+++ // if you ever need to be able to use NULL for it (such as with Dirent,
+++ // Group, Passwd, as these are method return types and `null' is used
+++ // to signify the end), it should be a reference type; otherwise, use
+++ // your discretion, and keep any expected usage patterns in mind.
+++ // - Syscall should be a Single Point Of Truth (SPOT). There should be
+++ // only ONE way to do anything. By convention, the Linux function names
+++ // are used, but that need not always be the case (use your discretion).
+++ // It SHOULD NOT be required that developers know what platform they're
+++ // on, and choose among a set of similar functions. In short, anything
+++ // that requires a platform check is BAD -- Mono.Unix is a wrapper, and
+++ // we can afford to clean things up whenever possible.
+++ // - Examples:
+++ // - Syscall.statfs: Solaris/Mac OS X provide statfs(2), Linux provides
+++ // statvfs(2). MonoPosixHelper will "thunk" between the two,
+++ // exporting a statvfs that works across platforms.
+++ // - Syscall.getfsent: Glibc export which Solaris lacks, while Solaris
+++ // instead provides getvfsent(3). MonoPosixHelper provides wrappers
+++ // to convert getvfsent(3) into Fstab data.
+++ // - Exception: If it isn't possible to cleanly wrap platforms, then the
+++ // method shouldn't be exported. The user will be expected to do their
+++ // own platform check and their own DllImports.
+++ // Examples: mount(2), umount(2), etc.
+++ // - Note: if a platform doesn't support a function AT ALL, the
+++ // MonoPosixHelper wrapper won't be compiled, resulting in a
+++ // EntryPointNotFoundException. This is also consistent with a missing
+++ // P/Invoke into libc.so.
+++ //
+++ [CLSCompliant (false)]
+++ public sealed class Syscall : Stdlib
+++ {
+++ new internal const string LIBC = "libc";
+++ private const string CRYPT = "crypt";
+++
+++ private Syscall () {}
+++
+++ //
+++ // <aio.h>
+++ //
+++
+++ // TODO: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3),
+++ // aio_return(3), aio_suspend(3), aio_write(3)
+++ //
+++ // Then update UnixStream.BeginRead to use the aio* functions.
+++
+++
+++ #region <attr/xattr.h> Declarations
+++ //
+++ // <attr/xattr.h> -- COMPLETE
+++ //
+++
+++ // setxattr(2)
+++ // int setxattr (const char *path, const char *name,
+++ // const void *value, size_t size, int flags);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_setxattr")]
+++ public static extern int setxattr (string path, string name, byte[] value, ulong size, XattrFlags flags);
+++
+++ public static int setxattr (string path, string name, byte [] value, ulong size)
+++ {
+++ return setxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
+++ }
+++
+++ public static int setxattr (string path, string name, byte [] value, XattrFlags flags)
+++ {
+++ return setxattr (path, name, value, (ulong) value.Length, flags);
+++ }
+++
+++ public static int setxattr (string path, string name, byte [] value)
+++ {
+++ return setxattr (path, name, value, (ulong) value.Length);
+++ }
+++
+++ // lsetxattr(2)
+++ // int lsetxattr (const char *path, const char *name,
+++ // const void *value, size_t size, int flags);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_lsetxattr")]
+++ public static extern int lsetxattr (string path, string name, byte[] value, ulong size, XattrFlags flags);
+++
+++ public static int lsetxattr (string path, string name, byte [] value, ulong size)
+++ {
+++ return lsetxattr (path, name, value, size, XattrFlags.XATTR_AUTO);
+++ }
+++
+++ public static int lsetxattr (string path, string name, byte [] value, XattrFlags flags)
+++ {
+++ return lsetxattr (path, name, value, (ulong) value.Length, flags);
+++ }
+++
+++ public static int lsetxattr (string path, string name, byte [] value)
+++ {
+++ return lsetxattr (path, name, value, (ulong) value.Length);
+++ }
+++
+++ // fsetxattr(2)
+++ // int fsetxattr (int fd, const char *name,
+++ // const void *value, size_t size, int flags);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fsetxattr")]
+++ public static extern int fsetxattr (int fd, string name, byte[] value, ulong size, XattrFlags flags);
+++
+++ public static int fsetxattr (int fd, string name, byte [] value, ulong size)
+++ {
+++ return fsetxattr (fd, name, value, size, XattrFlags.XATTR_AUTO);
+++ }
+++
+++ public static int fsetxattr (int fd, string name, byte [] value, XattrFlags flags)
+++ {
+++ return fsetxattr (fd, name, value, (ulong) value.Length, flags);
+++ }
+++
+++ public static int fsetxattr (int fd, string name, byte [] value)
+++ {
+++ return fsetxattr (fd, name, value, (ulong) value.Length);
+++ }
+++
+++ // getxattr(2)
+++ // ssize_t getxattr (const char *path, const char *name,
+++ // void *value, size_t size);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getxattr")]
+++ public static extern long getxattr (string path, string name, byte[] value, ulong size);
+++
+++ public static long getxattr (string path, string name, byte [] value)
+++ {
+++ return getxattr (path, name, value, (ulong) value.Length);
+++ }
+++
+++ public static long getxattr (string path, string name, out byte [] value)
+++ {
+++ value = null;
+++ long size = getxattr (path, name, value, 0);
+++ if (size <= 0)
+++ return size;
+++
+++ value = new byte [size];
+++ return getxattr (path, name, value, (ulong) size);
+++ }
+++
+++ // lgetxattr(2)
+++ // ssize_t lgetxattr (const char *path, const char *name,
+++ // void *value, size_t size);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_lgetxattr")]
+++ public static extern long lgetxattr (string path, string name, byte[] value, ulong size);
+++
+++ public static long lgetxattr (string path, string name, byte [] value)
+++ {
+++ return lgetxattr (path, name, value, (ulong) value.Length);
+++ }
+++
+++ public static long lgetxattr (string path, string name, out byte [] value)
+++ {
+++ value = null;
+++ long size = lgetxattr (path, name, value, 0);
+++ if (size <= 0)
+++ return size;
+++
+++ value = new byte [size];
+++ return lgetxattr (path, name, value, (ulong) size);
+++ }
+++
+++ // fgetxattr(2)
+++ // ssize_t fgetxattr (int fd, const char *name, void *value, size_t size);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fgetxattr")]
+++ public static extern long fgetxattr (int fd, string name, byte[] value, ulong size);
+++
+++ public static long fgetxattr (int fd, string name, byte [] value)
+++ {
+++ return fgetxattr (fd, name, value, (ulong) value.Length);
+++ }
+++
+++ public static long fgetxattr (int fd, string name, out byte [] value)
+++ {
+++ value = null;
+++ long size = fgetxattr (fd, name, value, 0);
+++ if (size <= 0)
+++ return size;
+++
+++ value = new byte [size];
+++ return fgetxattr (fd, name, value, (ulong) size);
+++ }
+++
+++ // listxattr(2)
+++ // ssize_t listxattr (const char *path, char *list, size_t size);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_listxattr")]
+++ public static extern long listxattr (string path, byte[] list, ulong size);
+++
+++ // Slight modification: returns 0 on success, negative on error
+++ public static long listxattr (string path, Encoding encoding, out string [] values)
+++ {
+++ values = null;
+++ long size = listxattr (path, null, 0);
+++ if (size == 0)
+++ values = new string [0];
+++ if (size <= 0)
+++ return (int) size;
+++
+++ byte[] list = new byte [size];
+++ long ret = listxattr (path, list, (ulong) size);
+++ if (ret < 0)
+++ return (int) ret;
+++
+++ string [] output = encoding.GetString (list).Split((char) 0);
+++ values = new string [output.Length - 1];
+++ Array.Copy (output, 0, values, 0, output.Length - 1);
+++ return 0;
+++ }
+++
+++ // llistxattr(2)
+++ // ssize_t llistxattr (const char *path, char *list, size_t size);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_llistxattr")]
+++ public static extern long llistxattr (string path, byte[] list, ulong size);
+++
+++ // Slight modification: returns 0 on success, negative on error
+++ public static long llistxattr (string path, Encoding encoding, out string [] values)
+++ {
+++ values = null;
+++ long size = llistxattr (path, null, 0);
+++ if (size == 0)
+++ values = new string [0];
+++ if (size <= 0)
+++ return (int) size;
+++
+++ byte[] list = new byte [size];
+++ long ret = llistxattr (path, list, (ulong) size);
+++ if (ret < 0)
+++ return (int) ret;
+++
+++ string [] output = encoding.GetString (list).Split((char) 0);
+++ values = new string [output.Length - 1];
+++ Array.Copy (output, 0, values, 0, output.Length - 1);
+++ return 0;
+++ }
+++
+++ // flistxattr(2)
+++ // ssize_t flistxattr (int fd, char *list, size_t size);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_flistxattr")]
+++ public static extern long flistxattr (int fd, byte[] list, ulong size);
+++
+++ // Slight modification: returns 0 on success, negative on error
+++ public static long flistxattr (int fd, Encoding encoding, out string [] values)
+++ {
+++ values = null;
+++ long size = flistxattr (fd, null, 0);
+++ if (size == 0)
+++ values = new string [0];
+++ if (size <= 0)
+++ return (int) size;
+++
+++ byte[] list = new byte [size];
+++ long ret = flistxattr (fd, list, (ulong) size);
+++ if (ret < 0)
+++ return (int) ret;
+++
+++ string [] output = encoding.GetString (list).Split((char) 0);
+++ values = new string [output.Length - 1];
+++ Array.Copy (output, 0, values, 0, output.Length - 1);
+++ return 0;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_removexattr")]
+++ public static extern int removexattr (string path, string name);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_lremovexattr")]
+++ public static extern int lremovexattr (string path, string name);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fremovexattr")]
+++ public static extern int fremovexattr (int fd, string name);
+++ #endregion
+++
+++ #region <dirent.h> Declarations
+++ //
+++ // <dirent.h>
+++ //
+++ // TODO: scandir(3), alphasort(3), versionsort(3), getdirentries(3)
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern IntPtr opendir (string name);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int closedir (IntPtr dir);
+++
+++ // seekdir(3):
+++ // void seekdir (DIR *dir, off_t offset);
+++ // Slight modification. Returns -1 on error, 0 on success.
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_seekdir")]
+++ public static extern int seekdir (IntPtr dir, long offset);
+++
+++ // telldir(3)
+++ // off_t telldir(DIR *dir);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_telldir")]
+++ public static extern long telldir (IntPtr dir);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern void rewinddir (IntPtr dir);
+++
+++ private struct _Dirent {
+++ public /* ino_t */ ulong d_ino;
+++ public /* off_t */ long d_off;
+++ public ushort d_reclen;
+++ public byte d_type;
+++ public IntPtr d_name;
+++ }
+++
+++ private static void CopyDirent (Dirent to, ref _Dirent from)
+++ {
+++ try {
+++ to.d_ino = from.d_ino;
+++ to.d_off = from.d_off;
+++ to.d_reclen = from.d_reclen;
+++ to.d_type = from.d_type;
+++ to.d_name = UnixMarshal.PtrToString (from.d_name);
+++ }
+++ finally {
+++ Stdlib.free (from.d_name);
+++ from.d_name = IntPtr.Zero;
+++ }
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_readdir")]
+++ private static extern int sys_readdir (IntPtr dir, out _Dirent dentry);
+++
+++ public static Dirent readdir (IntPtr dir)
+++ {
+++ _Dirent dentry;
+++ int r = sys_readdir (dir, out dentry);
+++ if (r != 0)
+++ return null;
+++ Dirent d = new Dirent ();
+++ CopyDirent (d, ref dentry);
+++ return d;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_readdir_r")]
+++ private static extern int sys_readdir_r (IntPtr dirp, out _Dirent entry, out IntPtr result);
+++
+++ public static int readdir_r (IntPtr dirp, Dirent entry, out IntPtr result)
+++ {
+++ entry.d_ino = 0;
+++ entry.d_off = 0;
+++ entry.d_reclen = 0;
+++ entry.d_type = 0;
+++ entry.d_name = null;
+++
+++ _Dirent _d;
+++ int r = sys_readdir_r (dirp, out _d, out result);
+++
+++ if (r == 0 && result != IntPtr.Zero) {
+++ CopyDirent (entry, ref _d);
+++ }
+++
+++ return r;
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int dirfd (IntPtr dir);
+++ #endregion
+++
+++ #region <fcntl.h> Declarations
+++ //
+++ // <fcntl.h> -- COMPLETE
+++ //
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fcntl")]
+++ public static extern int fcntl (int fd, FcntlCommand cmd);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fcntl_arg")]
+++ public static extern int fcntl (int fd, FcntlCommand cmd, long arg);
+++
+++ public static int fcntl (int fd, FcntlCommand cmd, DirectoryNotifyFlags arg)
+++ {
+++ if (cmd != FcntlCommand.F_NOTIFY) {
+++ SetLastError (Errno.EINVAL);
+++ return -1;
+++ }
+++ long _arg = NativeConvert.FromDirectoryNotifyFlags (arg);
+++ return fcntl (fd, FcntlCommand.F_NOTIFY, _arg);
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fcntl_lock")]
+++ public static extern int fcntl (int fd, FcntlCommand cmd, ref Flock @lock);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_open")]
+++ public static extern int open (string pathname, OpenFlags flags);
+++
+++ // open(2)
+++ // int open(const char *pathname, int flags, mode_t mode);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_open_mode")]
+++ public static extern int open (string pathname, OpenFlags flags, FilePermissions mode);
+++
+++ // creat(2)
+++ // int creat(const char *pathname, mode_t mode);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_creat")]
+++ public static extern int creat (string pathname, FilePermissions mode);
+++
+++ // posix_fadvise(2)
+++ // int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_posix_fadvise")]
+++ public static extern int posix_fadvise (int fd, long offset,
+++ long len, PosixFadviseAdvice advice);
+++
+++ // posix_fallocate(P)
+++ // int posix_fallocate(int fd, off_t offset, size_t len);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_posix_fallocate")]
+++ public static extern int posix_fallocate (int fd, long offset, ulong len);
+++ #endregion
+++
+++ #region <fstab.h> Declarations
+++ //
+++ // <fstab.h> -- COMPLETE
+++ //
+++ private struct _Fstab {
+++ public IntPtr fs_spec;
+++ public IntPtr fs_file;
+++ public IntPtr fs_vfstype;
+++ public IntPtr fs_mntops;
+++ public IntPtr fs_type;
+++ public int fs_freq;
+++ public int fs_passno;
+++ public IntPtr _fs_buf_;
+++ }
+++
+++ private static void CopyFstab (Fstab to, ref _Fstab from)
+++ {
+++ try {
+++ to.fs_spec = UnixMarshal.PtrToString (from.fs_spec);
+++ to.fs_file = UnixMarshal.PtrToString (from.fs_file);
+++ to.fs_vfstype = UnixMarshal.PtrToString (from.fs_vfstype);
+++ to.fs_mntops = UnixMarshal.PtrToString (from.fs_mntops);
+++ to.fs_type = UnixMarshal.PtrToString (from.fs_type);
+++ to.fs_freq = from.fs_freq;
+++ to.fs_passno = from.fs_passno;
+++ }
+++ finally {
+++ Stdlib.free (from._fs_buf_);
+++ from._fs_buf_ = IntPtr.Zero;
+++ }
+++ }
+++
+++ internal static object fstab_lock = new object ();
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_endfsent")]
+++ private static extern void sys_endfsent ();
+++
+++ public static void endfsent ()
+++ {
+++ lock (fstab_lock) {
+++ sys_endfsent ();
+++ }
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getfsent")]
+++ private static extern int sys_getfsent (out _Fstab fs);
+++
+++ public static Fstab getfsent ()
+++ {
+++ _Fstab fsbuf;
+++ int r;
+++ lock (fstab_lock) {
+++ r = sys_getfsent (out fsbuf);
+++ }
+++ if (r != 0)
+++ return null;
+++ Fstab fs = new Fstab ();
+++ CopyFstab (fs, ref fsbuf);
+++ return fs;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getfsfile")]
+++ private static extern int sys_getfsfile (string mount_point, out _Fstab fs);
+++
+++ public static Fstab getfsfile (string mount_point)
+++ {
+++ _Fstab fsbuf;
+++ int r;
+++ lock (fstab_lock) {
+++ r = sys_getfsfile (mount_point, out fsbuf);
+++ }
+++ if (r != 0)
+++ return null;
+++ Fstab fs = new Fstab ();
+++ CopyFstab (fs, ref fsbuf);
+++ return fs;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getfsspec")]
+++ private static extern int sys_getfsspec (string special_file, out _Fstab fs);
+++
+++ public static Fstab getfsspec (string special_file)
+++ {
+++ _Fstab fsbuf;
+++ int r;
+++ lock (fstab_lock) {
+++ r = sys_getfsspec (special_file, out fsbuf);
+++ }
+++ if (r != 0)
+++ return null;
+++ Fstab fs = new Fstab ();
+++ CopyFstab (fs, ref fsbuf);
+++ return fs;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_setfsent")]
+++ private static extern int sys_setfsent ();
+++
+++ public static int setfsent ()
+++ {
+++ lock (fstab_lock) {
+++ return sys_setfsent ();
+++ }
+++ }
+++
+++ #endregion
+++
+++ #region <grp.h> Declarations
+++ //
+++ // <grp.h>
+++ //
+++ // TODO: putgrent(3), fgetgrent_r(), getgrouplist(2), initgroups(3)
+++
+++ // setgroups(2)
+++ // int setgroups (size_t size, const gid_t *list);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_setgroups")]
+++ public static extern int setgroups (ulong size, uint[] list);
+++
+++ public static int setgroups (uint [] list)
+++ {
+++ return setgroups ((ulong) list.Length, list);
+++ }
+++
+++ private struct _Group
+++ {
+++ public IntPtr gr_name;
+++ public IntPtr gr_passwd;
+++ public /* gid_t */ uint gr_gid;
+++ public int _gr_nmem_;
+++ public IntPtr gr_mem;
+++ public IntPtr _gr_buf_;
+++ }
+++
+++ private static void CopyGroup (Group to, ref _Group from)
+++ {
+++ try {
+++ to.gr_gid = from.gr_gid;
+++ to.gr_name = UnixMarshal.PtrToString (from.gr_name);
+++ to.gr_passwd = UnixMarshal.PtrToString (from.gr_passwd);
+++ to.gr_mem = UnixMarshal.PtrToStringArray (from._gr_nmem_, from.gr_mem);
+++ }
+++ finally {
+++ Stdlib.free (from.gr_mem);
+++ Stdlib.free (from._gr_buf_);
+++ from.gr_mem = IntPtr.Zero;
+++ from._gr_buf_ = IntPtr.Zero;
+++ }
+++ }
+++
+++ internal static object grp_lock = new object ();
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getgrnam")]
+++ private static extern int sys_getgrnam (string name, out _Group group);
+++
+++ public static Group getgrnam (string name)
+++ {
+++ _Group group;
+++ int r;
+++ lock (grp_lock) {
+++ r = sys_getgrnam (name, out group);
+++ }
+++ if (r != 0)
+++ return null;
+++ Group gr = new Group ();
+++ CopyGroup (gr, ref group);
+++ return gr;
+++ }
+++
+++ // getgrgid(3)
+++ // struct group *getgrgid(gid_t gid);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getgrgid")]
+++ private static extern int sys_getgrgid (uint uid, out _Group group);
+++
+++ public static Group getgrgid (uint uid)
+++ {
+++ _Group group;
+++ int r;
+++ lock (grp_lock) {
+++ r = sys_getgrgid (uid, out group);
+++ }
+++ if (r != 0)
+++ return null;
+++ Group gr = new Group ();
+++ CopyGroup (gr, ref group);
+++ return gr;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getgrnam_r")]
+++ private static extern int sys_getgrnam_r (string name, out _Group grbuf, out IntPtr grbufp);
+++
+++ public static int getgrnam_r (string name, Group grbuf, out Group grbufp)
+++ {
+++ grbufp = null;
+++ _Group group;
+++ IntPtr _grbufp;
+++ int r = sys_getgrnam_r (name, out group, out _grbufp);
+++ if (r == 0 && _grbufp != IntPtr.Zero) {
+++ CopyGroup (grbuf, ref group);
+++ grbufp = grbuf;
+++ }
+++ return r;
+++ }
+++
+++ // getgrgid_r(3)
+++ // int getgrgid_r(gid_t gid, struct group *gbuf, char *buf,
+++ // size_t buflen, struct group **gbufp);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getgrgid_r")]
+++ private static extern int sys_getgrgid_r (uint uid, out _Group grbuf, out IntPtr grbufp);
+++
+++ public static int getgrgid_r (uint uid, Group grbuf, out Group grbufp)
+++ {
+++ grbufp = null;
+++ _Group group;
+++ IntPtr _grbufp;
+++ int r = sys_getgrgid_r (uid, out group, out _grbufp);
+++ if (r == 0 && _grbufp != IntPtr.Zero) {
+++ CopyGroup (grbuf, ref group);
+++ grbufp = grbuf;
+++ }
+++ return r;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getgrent")]
+++ private static extern int sys_getgrent (out _Group grbuf);
+++
+++ public static Group getgrent ()
+++ {
+++ _Group group;
+++ int r;
+++ lock (grp_lock) {
+++ r = sys_getgrent (out group);
+++ }
+++ if (r != 0)
+++ return null;
+++ Group gr = new Group();
+++ CopyGroup (gr, ref group);
+++ return gr;
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="setgrent")]
+++ private static extern void sys_setgrent ();
+++
+++ public static void setgrent ()
+++ {
+++ lock (grp_lock) {
+++ sys_setgrent ();
+++ }
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="endgrent")]
+++ private static extern void sys_endgrent ();
+++
+++ public static void endgrent ()
+++ {
+++ lock (grp_lock) {
+++ sys_endgrent ();
+++ }
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fgetgrent")]
+++ private static extern int sys_fgetgrent (IntPtr stream, out _Group grbuf);
+++
+++ public static Group fgetgrent (IntPtr stream)
+++ {
+++ _Group group;
+++ int r;
+++ lock (grp_lock) {
+++ r = sys_fgetgrent (stream, out group);
+++ }
+++ if (r != 0)
+++ return null;
+++ Group gr = new Group ();
+++ CopyGroup (gr, ref group);
+++ return gr;
+++ }
+++ #endregion
+++
+++ #region <pwd.h> Declarations
+++ //
+++ // <pwd.h>
+++ //
+++ // TODO: putpwent(3), fgetpwent_r()
+++ //
+++ // SKIPPING: getpw(3): it's dangerous. Use getpwuid(3) instead.
+++
+++ private struct _Passwd
+++ {
+++ public IntPtr pw_name;
+++ public IntPtr pw_passwd;
+++ public /* uid_t */ uint pw_uid;
+++ public /* gid_t */ uint pw_gid;
+++ public IntPtr pw_gecos;
+++ public IntPtr pw_dir;
+++ public IntPtr pw_shell;
+++ public IntPtr _pw_buf_;
+++ }
+++
+++ private static void CopyPasswd (Passwd to, ref _Passwd from)
+++ {
+++ try {
+++ to.pw_name = UnixMarshal.PtrToString (from.pw_name);
+++ to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
+++ to.pw_uid = from.pw_uid;
+++ to.pw_gid = from.pw_gid;
+++ to.pw_gecos = UnixMarshal.PtrToString (from.pw_gecos);
+++ to.pw_dir = UnixMarshal.PtrToString (from.pw_dir);
+++ to.pw_shell = UnixMarshal.PtrToString (from.pw_shell);
+++ }
+++ finally {
+++ Stdlib.free (from._pw_buf_);
+++ from._pw_buf_ = IntPtr.Zero;
+++ }
+++ }
+++
+++ internal static object pwd_lock = new object ();
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getpwnam")]
+++ private static extern int sys_getpwnam (string name, out _Passwd passwd);
+++
+++ public static Passwd getpwnam (string name)
+++ {
+++ _Passwd passwd;
+++ int r;
+++ lock (pwd_lock) {
+++ r = sys_getpwnam (name, out passwd);
+++ }
+++ if (r != 0)
+++ return null;
+++ Passwd pw = new Passwd ();
+++ CopyPasswd (pw, ref passwd);
+++ return pw;
+++ }
+++
+++ // getpwuid(3)
+++ // struct passwd *getpwnuid(uid_t uid);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getpwuid")]
+++ private static extern int sys_getpwuid (uint uid, out _Passwd passwd);
+++
+++ public static Passwd getpwuid (uint uid)
+++ {
+++ _Passwd passwd;
+++ int r;
+++ lock (pwd_lock) {
+++ r = sys_getpwuid (uid, out passwd);
+++ }
+++ if (r != 0)
+++ return null;
+++ Passwd pw = new Passwd ();
+++ CopyPasswd (pw, ref passwd);
+++ return pw;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getpwnam_r")]
+++ private static extern int sys_getpwnam_r (string name, out _Passwd pwbuf, out IntPtr pwbufp);
+++
+++ public static int getpwnam_r (string name, Passwd pwbuf, out Passwd pwbufp)
+++ {
+++ pwbufp = null;
+++ _Passwd passwd;
+++ IntPtr _pwbufp;
+++ int r = sys_getpwnam_r (name, out passwd, out _pwbufp);
+++ if (r == 0 && _pwbufp != IntPtr.Zero) {
+++ CopyPasswd (pwbuf, ref passwd);
+++ pwbufp = pwbuf;
+++ }
+++ return r;
+++ }
+++
+++ // getpwuid_r(3)
+++ // int getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t
+++ // buflen, struct passwd **pwbufp);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getpwuid_r")]
+++ private static extern int sys_getpwuid_r (uint uid, out _Passwd pwbuf, out IntPtr pwbufp);
+++
+++ public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
+++ {
+++ pwbufp = null;
+++ _Passwd passwd;
+++ IntPtr _pwbufp;
+++ int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
+++ if (r == 0 && _pwbufp != IntPtr.Zero) {
+++ CopyPasswd (pwbuf, ref passwd);
+++ pwbufp = pwbuf;
+++ }
+++ return r;
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getpwent")]
+++ private static extern int sys_getpwent (out _Passwd pwbuf);
+++
+++ public static Passwd getpwent ()
+++ {
+++ _Passwd passwd;
+++ int r;
+++ lock (pwd_lock) {
+++ r = sys_getpwent (out passwd);
+++ }
+++ if (r != 0)
+++ return null;
+++ Passwd pw = new Passwd ();
+++ CopyPasswd (pw, ref passwd);
+++ return pw;
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="setpwent")]
+++ private static extern void sys_setpwent ();
+++
+++ public static void setpwent ()
+++ {
+++ lock (pwd_lock) {
+++ sys_setpwent ();
+++ }
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="endpwent")]
+++ private static extern void sys_endpwent ();
+++
+++ public static void endpwent ()
+++ {
+++ lock (pwd_lock) {
+++ sys_endpwent ();
+++ }
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fgetpwent")]
+++ private static extern int sys_fgetpwent (IntPtr stream, out _Passwd pwbuf);
+++
+++ public static Passwd fgetpwent (IntPtr stream)
+++ {
+++ _Passwd passwd;
+++ int r;
+++ lock (pwd_lock) {
+++ r = sys_fgetpwent (stream, out passwd);
+++ }
+++ if (r != 0)
+++ return null;
+++ Passwd pw = new Passwd ();
+++ CopyPasswd (pw, ref passwd);
+++ return pw;
+++ }
+++ #endregion
+++
+++ #region <signal.h> Declarations
+++ //
+++ // <signal.h>
+++ //
+++ [DllImport (LIBC, SetLastError=true)]
+++ private static extern void psignal (int sig, string s);
+++
+++ public static void psignal (Signum sig, string s)
+++ {
+++ int signum = NativeConvert.FromSignum (sig);
+++ psignal (signum, s);
+++ }
+++
+++ // kill(2)
+++ // int kill(pid_t pid, int sig);
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="kill")]
+++ private static extern int sys_kill (int pid, int sig);
+++
+++ public static int kill (int pid, Signum sig)
+++ {
+++ int _sig = NativeConvert.FromSignum (sig);
+++ return sys_kill (pid, _sig);
+++ }
+++
+++ private static object signal_lock = new object ();
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="strsignal")]
+++ private static extern IntPtr sys_strsignal (int sig);
+++
+++ public static string strsignal (Signum sig)
+++ {
+++ int s = NativeConvert.FromSignum (sig);
+++ lock (signal_lock) {
+++ IntPtr r = sys_strsignal (s);
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++
+++ // TODO: sigaction(2)
+++ // TODO: sigsuspend(2)
+++ // TODO: sigpending(2)
+++
+++ #endregion
+++
+++ #region <stdio.h> Declarations
+++ //
+++ // <stdio.h>
+++ //
+++ [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
+++ private static extern int _L_ctermid ();
+++
+++ public static readonly int L_ctermid = _L_ctermid ();
+++
+++ [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
+++ private static extern int _L_cuserid ();
+++
+++ public static readonly int L_cuserid = _L_cuserid ();
+++
+++ internal static object getlogin_lock = new object ();
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="cuserid")]
+++ private static extern IntPtr sys_cuserid ([Out] StringBuilder @string);
+++
+++ [Obsolete ("\"Nobody knows precisely what cuserid() does... " +
+++ "DO NOT USE cuserid().\n" +
+++ "`string' must hold L_cuserid characters. Use getlogin_r instead.")]
+++ public static string cuserid (StringBuilder @string)
+++ {
+++ if (@string.Capacity < L_cuserid) {
+++ throw new ArgumentOutOfRangeException ("string", "string.Capacity < L_cuserid");
+++ }
+++ lock (getlogin_lock) {
+++ IntPtr r = sys_cuserid (@string);
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++
+++ #endregion
+++
+++ #region <stdlib.h> Declarations
+++ //
+++ // <stdlib.h>
+++ //
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int mkstemp (StringBuilder template);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int ttyslot ();
+++
+++ [DllImport (CRYPT, SetLastError=true)]
+++ public static extern void setkey (string key);
+++
+++ #endregion
+++
+++ #region <string.h> Declarations
+++ //
+++ // <string.h>
+++ //
+++
+++ // strerror_r(3)
+++ // int strerror_r(int errnum, char *buf, size_t n);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_strerror_r")]
+++ private static extern int sys_strerror_r (int errnum,
+++ [Out] StringBuilder buf, ulong n);
+++
+++ public static int strerror_r (Errno errnum, StringBuilder buf, ulong n)
+++ {
+++ int e = NativeConvert.FromErrno (errnum);
+++ return sys_strerror_r (e, buf, n);
+++ }
+++
+++ public static int strerror_r (Errno errnum, StringBuilder buf)
+++ {
+++ return strerror_r (errnum, buf, (ulong) buf.Capacity);
+++ }
+++
+++ #endregion
+++
+++ #region <sys/mman.h> Declarations
+++ //
+++ // <sys/mman.h>
+++ //
+++
+++ // posix_madvise(P)
+++ // int posix_madvise(void *addr, size_t len, int advice);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_posix_madvise")]
+++ public static extern int posix_madvise (IntPtr addr, ulong len,
+++ PosixMadviseAdvice advice);
+++
+++ public static readonly IntPtr MAP_FAILED = unchecked((IntPtr)(-1));
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_mmap")]
+++ public static extern IntPtr mmap (IntPtr start, ulong length,
+++ MmapProts prot, MmapFlags flags, int fd, long offset);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_munmap")]
+++ public static extern int munmap (IntPtr start, ulong length);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_mprotect")]
+++ public static extern int mprotect (IntPtr start, ulong len, MmapProts prot);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_msync")]
+++ public static extern int msync (IntPtr start, ulong len, MsyncFlags flags);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_mlock")]
+++ public static extern int mlock (IntPtr start, ulong len);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_munlock")]
+++ public static extern int munlock (IntPtr start, ulong len);
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="mlockall")]
+++ private static extern int sys_mlockall (int flags);
+++
+++ public static int mlockall (MlockallFlags flags)
+++ {
+++ int _flags = NativeConvert.FromMlockallFlags (flags);
+++ return sys_mlockall (_flags);
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int munlockall ();
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_mremap")]
+++ public static extern IntPtr mremap (IntPtr old_address, ulong old_size,
+++ ulong new_size, MremapFlags flags);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_mincore")]
+++ public static extern int mincore (IntPtr start, ulong length, byte[] vec);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_remap_file_pages")]
+++ public static extern int remap_file_pages (IntPtr start, ulong size,
+++ MmapProts prot, long pgoff, MmapFlags flags);
+++
+++ #endregion
+++
+++ #region <sys/poll.h> Declarations
+++ //
+++ // <sys/poll.h> -- COMPLETE
+++ //
+++
+++ private struct _pollfd {
+++ public int fd;
+++ public short events;
+++ public short revents;
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="poll")]
+++ private static extern int sys_poll (_pollfd[] ufds, uint nfds, int timeout);
+++
+++ public static int poll (Pollfd [] fds, uint nfds, int timeout)
+++ {
+++ if (fds.Length < nfds)
+++ throw new ArgumentOutOfRangeException ("fds", "Must refer to at least `nfds' elements");
+++
+++ _pollfd[] send = new _pollfd[nfds];
+++
+++ for (int i = 0; i < send.Length; i++) {
+++ send [i].fd = fds [i].fd;
+++ send [i].events = NativeConvert.FromPollEvents (fds [i].events);
+++ }
+++
+++ int r = sys_poll (send, nfds, timeout);
+++
+++ for (int i = 0; i < send.Length; i++) {
+++ fds [i].revents = NativeConvert.ToPollEvents (send [i].revents);
+++ }
+++
+++ return r;
+++ }
+++
+++ public static int poll (Pollfd [] fds, int timeout)
+++ {
+++ return poll (fds, (uint) fds.Length, timeout);
+++ }
+++
+++ //
+++ // <sys/ptrace.h>
+++ //
+++
+++ // TODO: ptrace(2)
+++
+++ //
+++ // <sys/resource.h>
+++ //
+++
+++ // TODO: setrlimit(2)
+++ // TODO: getrlimit(2)
+++ // TODO: getrusage(2)
+++
+++ #endregion
+++
+++ #region <sys/sendfile.h> Declarations
+++ //
+++ // <sys/sendfile.h> -- COMPLETE
+++ //
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_sendfile")]
+++ public static extern long sendfile (int out_fd, int in_fd,
+++ ref long offset, ulong count);
+++
+++ #endregion
+++
+++ #region <sys/stat.h> Declarations
+++ //
+++ // <sys/stat.h> -- COMPLETE
+++ //
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_stat")]
+++ public static extern int stat (string file_name, out Stat buf);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fstat")]
+++ public static extern int fstat (int filedes, out Stat buf);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_lstat")]
+++ public static extern int lstat (string file_name, out Stat buf);
+++
+++ // TODO:
+++ // S_ISDIR, S_ISCHR, S_ISBLK, S_ISREG, S_ISFIFO, S_ISLNK, S_ISSOCK
+++ // All take FilePermissions
+++
+++ // chmod(2)
+++ // int chmod(const char *path, mode_t mode);
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="chmod")]
+++ private static extern int sys_chmod (string path, uint mode);
+++
+++ public static int chmod (string path, FilePermissions mode)
+++ {
+++ uint _mode = NativeConvert.FromFilePermissions (mode);
+++ return sys_chmod (path, _mode);
+++ }
+++
+++ // fchmod(2)
+++ // int chmod(int filedes, mode_t mode);
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="fchmod")]
+++ private static extern int sys_fchmod (int filedes, uint mode);
+++
+++ public static int fchmod (int filedes, FilePermissions mode)
+++ {
+++ uint _mode = NativeConvert.FromFilePermissions (mode);
+++ return sys_fchmod (filedes, _mode);
+++ }
+++
+++ // umask(2)
+++ // mode_t umask(mode_t mask);
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="umask")]
+++ private static extern uint sys_umask (uint mask);
+++
+++ public static FilePermissions umask (FilePermissions mask)
+++ {
+++ uint _mask = NativeConvert.FromFilePermissions (mask);
+++ uint r = sys_umask (_mask);
+++ return NativeConvert.ToFilePermissions (r);
+++ }
+++
+++ // mkdir(2)
+++ // int mkdir(const char *pathname, mode_t mode);
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="mkdir")]
+++ private static extern int sys_mkdir (string oldpath, uint mode);
+++
+++ public static int mkdir (string oldpath, FilePermissions mode)
+++ {
+++ uint _mode = NativeConvert.FromFilePermissions (mode);
+++ return sys_mkdir (oldpath, _mode);
+++ }
+++
+++ // mknod(2)
+++ // int mknod (const char *pathname, mode_t mode, dev_t dev);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_mknod")]
+++ public static extern int mknod (string pathname, FilePermissions mode, ulong dev);
+++
+++ // mkfifo(3)
+++ // int mkfifo(const char *pathname, mode_t mode);
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="mkfifo")]
+++ private static extern int sys_mkfifo (string pathname, uint mode);
+++
+++ public static int mkfifo (string pathname, FilePermissions mode)
+++ {
+++ uint _mode = NativeConvert.FromFilePermissions (mode);
+++ return sys_mkfifo (pathname, _mode);
+++ }
+++
+++ #endregion
+++
+++ #region <sys/stat.h> Declarations
+++ //
+++ // <sys/statvfs.h>
+++ //
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_statvfs")]
+++ public static extern int statvfs (string path, out Statvfs buf);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fstatvfs")]
+++ public static extern int fstatvfs (int fd, out Statvfs buf);
+++
+++ #endregion
+++
+++ #region <sys/time.h> Declarations
+++ //
+++ // <sys/time.h>
+++ //
+++ // TODO: adjtime(), getitimer(2), setitimer(2), lutimes(), futimes()
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_gettimeofday")]
+++ public static extern int gettimeofday (out Timeval tv, out Timezone tz);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_gettimeofday")]
+++ private static extern int gettimeofday (out Timeval tv, IntPtr ignore);
+++
+++ public static int gettimeofday (out Timeval tv)
+++ {
+++ return gettimeofday (out tv, IntPtr.Zero);
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_gettimeofday")]
+++ private static extern int gettimeofday (IntPtr ignore, out Timezone tz);
+++
+++ public static int gettimeofday (out Timezone tz)
+++ {
+++ return gettimeofday (IntPtr.Zero, out tz);
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_settimeofday")]
+++ public static extern int settimeofday (ref Timeval tv, ref Timezone tz);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_gettimeofday")]
+++ private static extern int settimeofday (ref Timeval tv, IntPtr ignore);
+++
+++ public static int settimeofday (ref Timeval tv)
+++ {
+++ return settimeofday (ref tv, IntPtr.Zero);
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_utimes")]
+++ public static extern int utimes (string filename, ref Timeval tvp);
+++
+++ #endregion
+++
+++ //
+++ // <sys/timeb.h>
+++ //
+++
+++ // TODO: ftime(3)
+++
+++ //
+++ // <sys/times.h>
+++ //
+++
+++ // TODO: times(2)
+++
+++ //
+++ // <sys/utsname.h>
+++ //
+++
+++ // TODO: uname(2)
+++
+++ #region <sys/wait.h> Declarations
+++ //
+++ // <sys/wait.h>
+++ //
+++
+++ // wait(2)
+++ // pid_t wait(int *status);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int wait (out int status);
+++
+++ // waitpid(2)
+++ // pid_t waitpid(pid_t pid, int *status, int options);
+++ [DllImport (LIBC, SetLastError=true)]
+++ private static extern int waitpid (int pid, out int status, int options);
+++
+++ public static int waitpid (int pid, out int status, WaitOptions options)
+++ {
+++ int _options = NativeConvert.FromWaitOptions (options);
+++ return waitpid (pid, out status, _options);
+++ }
+++
+++ [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFEXITED")]
+++ private static extern int _WIFEXITED (int status);
+++
+++ public static bool WIFEXITED (int status)
+++ {
+++ return _WIFEXITED (status) != 0;
+++ }
+++
+++ [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WEXITSTATUS")]
+++ public static extern int WEXITSTATUS (int status);
+++
+++ [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSIGNALED")]
+++ private static extern int _WIFSIGNALED (int status);
+++
+++ public static bool WIFSIGNALED (int status)
+++ {
+++ return _WIFSIGNALED (status) != 0;
+++ }
+++
+++ [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WTERMSIG")]
+++ private static extern int _WTERMSIG (int status);
+++
+++ public static Signum WTERMSIG (int status)
+++ {
+++ int r = _WTERMSIG (status);
+++ return NativeConvert.ToSignum (r);
+++ }
+++
+++ [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WIFSTOPPED")]
+++ private static extern int _WIFSTOPPED (int status);
+++
+++ public static bool WIFSTOPPED (int status)
+++ {
+++ return _WIFSTOPPED (status) != 0;
+++ }
+++
+++ [DllImport (MPH, EntryPoint="Mono_Posix_Syscall_WSTOPSIG")]
+++ private static extern int _WSTOPSIG (int status);
+++
+++ public static Signum WSTOPSIG (int status)
+++ {
+++ int r = _WSTOPSIG (status);
+++ return NativeConvert.ToSignum (r);
+++ }
+++
+++ //
+++ // <termios.h>
+++ //
+++
+++ #endregion
+++
+++ #region <syslog.h> Declarations
+++ //
+++ // <syslog.h>
+++ //
+++
+++ [DllImport (LIBC, EntryPoint="openlog")]
+++ private static extern void sys_openlog (IntPtr ident, int option, int facility);
+++
+++ public static void openlog (IntPtr ident, SyslogOptions option,
+++ SyslogFacility defaultFacility)
+++ {
+++ int _option = NativeConvert.FromSyslogOptions (option);
+++ int _facility = NativeConvert.FromSyslogFacility (defaultFacility);
+++
+++ sys_openlog (ident, _option, _facility);
+++ }
+++
+++ [DllImport (LIBC, EntryPoint="syslog")]
+++ private static extern void sys_syslog (int priority, string message);
+++
+++ public static void syslog (SyslogFacility facility, SyslogLevel level, string message)
+++ {
+++ int _facility = NativeConvert.FromSyslogFacility (facility);
+++ int _level = NativeConvert.FromSyslogLevel (level);
+++ sys_syslog (_facility | _level, GetSyslogMessage (message));
+++ }
+++
+++ public static void syslog (SyslogLevel level, string message)
+++ {
+++ int _level = NativeConvert.FromSyslogLevel (level);
+++ sys_syslog (_level, GetSyslogMessage (message));
+++ }
+++
+++ private static string GetSyslogMessage (string message)
+++ {
+++ return UnixMarshal.EscapeFormatString (message, new char[]{'m'});
+++ }
+++
+++ [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
+++ "Use syslog(SyslogFacility, SyslogLevel, string) instead.")]
+++ public static void syslog (SyslogFacility facility, SyslogLevel level,
+++ string format, params object[] parameters)
+++ {
+++ int _facility = NativeConvert.FromSyslogFacility (facility);
+++ int _level = NativeConvert.FromSyslogLevel (level);
+++
+++ object[] _parameters = new object[checked(parameters.Length+2)];
+++ _parameters [0] = _facility | _level;
+++ _parameters [1] = format;
+++ Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
+++ XPrintfFunctions.syslog (_parameters);
+++ }
+++
+++ [Obsolete ("Not necessarily portable due to cdecl restrictions.\n" +
+++ "Use syslog(SyslogLevel, string) instead.")]
+++ public static void syslog (SyslogLevel level, string format,
+++ params object[] parameters)
+++ {
+++ int _level = NativeConvert.FromSyslogLevel (level);
+++
+++ object[] _parameters = new object[checked(parameters.Length+2)];
+++ _parameters [0] = _level;
+++ _parameters [1] = format;
+++ Array.Copy (parameters, 0, _parameters, 2, parameters.Length);
+++ XPrintfFunctions.syslog (_parameters);
+++ }
+++
+++ [DllImport (LIBC)]
+++ public static extern void closelog ();
+++
+++ [DllImport (LIBC, EntryPoint="setlogmask")]
+++ private static extern int sys_setlogmask (int mask);
+++
+++ public static int setlogmask (SyslogLevel mask)
+++ {
+++ int _mask = NativeConvert.FromSyslogLevel (mask);
+++ return sys_setlogmask (_mask);
+++ }
+++
+++ #endregion
+++
+++ #region <time.h> Declarations
+++
+++ //
+++ // <time.h>
+++ //
+++
+++ // stime(2)
+++ // int stime(time_t *t);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_stime")]
+++ public static extern int stime (ref long t);
+++
+++ // time(2)
+++ // time_t time(time_t *t);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_time")]
+++ public static extern long time (out long t);
+++
+++ //
+++ // <ulimit.h>
+++ //
+++
+++ // TODO: ulimit(3)
+++
+++ #endregion
+++
+++ #region <unistd.h> Declarations
+++ //
+++ // <unistd.h>
+++ //
+++ // TODO: euidaccess(), usleep(3), get_current_dir_name(), group_member(),
+++ // other TODOs listed below.
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="access")]
+++ private static extern int sys_access (string pathname, int mode);
+++
+++ public static int access (string pathname, AccessModes mode)
+++ {
+++ int _mode = NativeConvert.FromAccessModes (mode);
+++ return sys_access (pathname, _mode);
+++ }
+++
+++ // lseek(2)
+++ // off_t lseek(int filedes, off_t offset, int whence);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_lseek")]
+++ private static extern long sys_lseek (int fd, long offset, int whence);
+++
+++ public static long lseek (int fd, long offset, SeekFlags whence)
+++ {
+++ short _whence = NativeConvert.FromSeekFlags (whence);
+++ return sys_lseek (fd, offset, _whence);
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int close (int fd);
+++
+++ // read(2)
+++ // ssize_t read(int fd, void *buf, size_t count);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_read")]
+++ public static extern long read (int fd, IntPtr buf, ulong count);
+++
+++ public static unsafe long read (int fd, void *buf, ulong count)
+++ {
+++ return read (fd, (IntPtr) buf, count);
+++ }
+++
+++ // write(2)
+++ // ssize_t write(int fd, const void *buf, size_t count);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_write")]
+++ public static extern long write (int fd, IntPtr buf, ulong count);
+++
+++ public static unsafe long write (int fd, void *buf, ulong count)
+++ {
+++ return write (fd, (IntPtr) buf, count);
+++ }
+++
+++ // pread(2)
+++ // ssize_t pread(int fd, void *buf, size_t count, off_t offset);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_pread")]
+++ public static extern long pread (int fd, IntPtr buf, ulong count, long offset);
+++
+++ public static unsafe long pread (int fd, void *buf, ulong count, long offset)
+++ {
+++ return pread (fd, (IntPtr) buf, count, offset);
+++ }
+++
+++ // pwrite(2)
+++ // ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_pwrite")]
+++ public static extern long pwrite (int fd, IntPtr buf, ulong count, long offset);
+++
+++ public static unsafe long pwrite (int fd, void *buf, ulong count, long offset)
+++ {
+++ return pwrite (fd, (IntPtr) buf, count, offset);
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_pipe")]
+++ public static extern int pipe (out int reading, out int writing);
+++
+++ public static int pipe (int[] filedes)
+++ {
+++ if (filedes == null || filedes.Length != 2) {
+++ // TODO: set errno
+++ return -1;
+++ }
+++ int reading, writing;
+++ int r = pipe (out reading, out writing);
+++ filedes[0] = reading;
+++ filedes[1] = writing;
+++ return r;
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern uint alarm (uint seconds);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern uint sleep (uint seconds);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern uint ualarm (uint usecs, uint interval);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int pause ();
+++
+++ // chown(2)
+++ // int chown(const char *path, uid_t owner, gid_t group);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int chown (string path, uint owner, uint group);
+++
+++ // fchown(2)
+++ // int fchown(int fd, uid_t owner, gid_t group);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int fchown (int fd, uint owner, uint group);
+++
+++ // lchown(2)
+++ // int lchown(const char *path, uid_t owner, gid_t group);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int lchown (string path, uint owner, uint group);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int chdir (string path);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int fchdir (int fd);
+++
+++ // getcwd(3)
+++ // char *getcwd(char *buf, size_t size);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getcwd")]
+++ public static extern IntPtr getcwd ([Out] StringBuilder buf, ulong size);
+++
+++ public static StringBuilder getcwd (StringBuilder buf)
+++ {
+++ getcwd (buf, (ulong) buf.Capacity);
+++ return buf;
+++ }
+++
+++ // getwd(2) is deprecated; don't expose it.
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int dup (int fd);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int dup2 (int fd, int fd2);
+++
+++ // TODO: does Mono marshal arrays properly?
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int execve (string path, string[] argv, string[] envp);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int fexecve (int fd, string[] argv, string[] envp);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int execv (string path, string[] argv);
+++
+++ // TODO: execle, execl, execlp
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int execvp (string path, string[] argv);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int nice (int inc);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ [CLSCompliant (false)]
+++ public static extern int _exit (int status);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_fpathconf")]
+++ public static extern long fpathconf (int filedes, PathConf name);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_pathconf")]
+++ public static extern long pathconf (string path, PathConf name);
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_sysconf")]
+++ public static extern long sysconf (SysConf name);
+++
+++ // confstr(3)
+++ // size_t confstr(int name, char *buf, size_t len);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_confstr")]
+++ public static extern ulong confstr (ConfStr name, [Out] StringBuilder buf, ulong len);
+++
+++ // getpid(2)
+++ // pid_t getpid(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getpid ();
+++
+++ // getppid(2)
+++ // pid_t getppid(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getppid ();
+++
+++ // setpgid(2)
+++ // int setpgid(pid_t pid, pid_t pgid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setpgid (int pid, int pgid);
+++
+++ // getpgid(2)
+++ // pid_t getpgid(pid_t pid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getpgid (int pid);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setpgrp ();
+++
+++ // getpgrp(2)
+++ // pid_t getpgrp(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getpgrp ();
+++
+++ // setsid(2)
+++ // pid_t setsid(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setsid ();
+++
+++ // getsid(2)
+++ // pid_t getsid(pid_t pid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getsid (int pid);
+++
+++ // getuid(2)
+++ // uid_t getuid(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern uint getuid ();
+++
+++ // geteuid(2)
+++ // uid_t geteuid(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern uint geteuid ();
+++
+++ // getgid(2)
+++ // gid_t getgid(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern uint getgid ();
+++
+++ // getegid(2)
+++ // gid_t getgid(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern uint getegid ();
+++
+++ // getgroups(2)
+++ // int getgroups(int size, gid_t list[]);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getgroups (int size, uint[] list);
+++
+++ public static int getgroups (uint[] list)
+++ {
+++ return getgroups (list.Length, list);
+++ }
+++
+++ // setuid(2)
+++ // int setuid(uid_t uid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setuid (uint uid);
+++
+++ // setreuid(2)
+++ // int setreuid(uid_t ruid, uid_t euid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setreuid (uint ruid, uint euid);
+++
+++ // setregid(2)
+++ // int setregid(gid_t ruid, gid_t euid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setregid (uint rgid, uint egid);
+++
+++ // seteuid(2)
+++ // int seteuid(uid_t euid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int seteuid (uint euid);
+++
+++ // setegid(2)
+++ // int setegid(gid_t euid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setegid (uint uid);
+++
+++ // setgid(2)
+++ // int setgid(gid_t gid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setgid (uint gid);
+++
+++ // getresuid(2)
+++ // int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getresuid (out uint ruid, out uint euid, out uint suid);
+++
+++ // getresgid(2)
+++ // int getresgid(gid_t *ruid, gid_t *euid, gid_t *suid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getresgid (out uint rgid, out uint egid, out uint sgid);
+++
+++ // setresuid(2)
+++ // int setresuid(uid_t ruid, uid_t euid, uid_t suid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setresuid (uint ruid, uint euid, uint suid);
+++
+++ // setresgid(2)
+++ // int setresgid(gid_t ruid, gid_t euid, gid_t suid);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setresgid (uint rgid, uint egid, uint sgid);
+++
+++ // fork(2)
+++ // pid_t fork(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ [Obsolete ("DO NOT directly call fork(2); it bypasses essential " +
+++ "shutdown code.\nUse System.Diagnostics.Process instead")]
+++ private static extern int fork ();
+++
+++ // vfork(2)
+++ // pid_t vfork(void);
+++ [DllImport (LIBC, SetLastError=true)]
+++ [Obsolete ("DO NOT directly call vfork(2); it bypasses essential " +
+++ "shutdown code.\nUse System.Diagnostics.Process instead")]
+++ private static extern int vfork ();
+++
+++ private static object tty_lock = new object ();
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="ttyname")]
+++ private static extern IntPtr sys_ttyname (int fd);
+++
+++ public static string ttyname (int fd)
+++ {
+++ lock (tty_lock) {
+++ IntPtr r = sys_ttyname (fd);
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++
+++ // ttyname_r(3)
+++ // int ttyname_r(int fd, char *buf, size_t buflen);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_ttyname_r")]
+++ public static extern int ttyname_r (int fd, [Out] StringBuilder buf, ulong buflen);
+++
+++ public static int ttyname_r (int fd, StringBuilder buf)
+++ {
+++ return ttyname_r (fd, buf, (ulong) buf.Capacity);
+++ }
+++
+++ [DllImport (LIBC, EntryPoint="isatty")]
+++ private static extern int sys_isatty (int fd);
+++
+++ public static bool isatty (int fd)
+++ {
+++ return sys_isatty (fd) == 1;
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int link (string oldpath, string newpath);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int symlink (string oldpath, string newpath);
+++
+++ // readlink(2)
+++ // int readlink(const char *path, char *buf, size_t bufsize);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_readlink")]
+++ public static extern int readlink (string path, [Out] StringBuilder buf, ulong bufsiz);
+++
+++ public static int readlink (string path, [Out] StringBuilder buf)
+++ {
+++ return readlink (path, buf, (ulong) buf.Capacity);
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int unlink (string pathname);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int rmdir (string pathname);
+++
+++ // tcgetpgrp(3)
+++ // pid_t tcgetpgrp(int fd);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int tcgetpgrp (int fd);
+++
+++ // tcsetpgrp(3)
+++ // int tcsetpgrp(int fd, pid_t pgrp);
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int tcsetpgrp (int fd, int pgrp);
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="getlogin")]
+++ private static extern IntPtr sys_getlogin ();
+++
+++ public static string getlogin ()
+++ {
+++ lock (getlogin_lock) {
+++ IntPtr r = sys_getlogin ();
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++
+++ // getlogin_r(3)
+++ // int getlogin_r(char *buf, size_t bufsize);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getlogin_r")]
+++ public static extern int getlogin_r ([Out] StringBuilder name, ulong bufsize);
+++
+++ public static int getlogin_r (StringBuilder name)
+++ {
+++ return getlogin_r (name, (ulong) name.Capacity);
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int setlogin (string name);
+++
+++ // gethostname(2)
+++ // int gethostname(char *name, size_t len);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_gethostname")]
+++ public static extern int gethostname ([Out] StringBuilder name, ulong len);
+++
+++ public static int gethostname (StringBuilder name)
+++ {
+++ return gethostname (name, (ulong) name.Capacity);
+++ }
+++
+++ // sethostname(2)
+++ // int gethostname(const char *name, size_t len);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_sethostname")]
+++ public static extern int sethostname (string name, ulong len);
+++
+++ public static int sethostname (string name)
+++ {
+++ return sethostname (name, (ulong) name.Length);
+++ }
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_gethostid")]
+++ public static extern long gethostid ();
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_sethostid")]
+++ public static extern int sethostid (long hostid);
+++
+++ // getdomainname(2)
+++ // int getdomainname(char *name, size_t len);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_getdomainname")]
+++ public static extern int getdomainname ([Out] StringBuilder name, ulong len);
+++
+++ public static int getdomainname (StringBuilder name)
+++ {
+++ return getdomainname (name, (ulong) name.Capacity);
+++ }
+++
+++ // setdomainname(2)
+++ // int setdomainname(const char *name, size_t len);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_setdomainname")]
+++ public static extern int setdomainname (string name, ulong len);
+++
+++ public static int setdomainname (string name)
+++ {
+++ return setdomainname (name, (ulong) name.Length);
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int vhangup ();
+++
+++ // Revoke doesn't appear to be POSIX. Include it?
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int revoke (string file);
+++
+++ // TODO: profil? It's not POSIX.
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int acct (string filename);
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="getusershell")]
+++ private static extern IntPtr sys_getusershell ();
+++
+++ internal static object usershell_lock = new object ();
+++
+++ public static string getusershell ()
+++ {
+++ lock (usershell_lock) {
+++ IntPtr r = sys_getusershell ();
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="setusershell")]
+++ private static extern void sys_setusershell ();
+++
+++ public static void setusershell ()
+++ {
+++ lock (usershell_lock) {
+++ sys_setusershell ();
+++ }
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true, EntryPoint="endusershell")]
+++ private static extern void sys_endusershell ();
+++
+++ public static void endusershell ()
+++ {
+++ lock (usershell_lock) {
+++ sys_endusershell ();
+++ }
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ private static extern int daemon (int nochdir, int noclose);
+++
+++ public static int daemon (bool nochdir, bool noclose)
+++ {
+++ return daemon (nochdir ? 1 : 0, noclose ? 1 : 0);
+++ }
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int chroot (string path);
+++
+++ // skipping getpass(3) as the man page states:
+++ // This function is obsolete. Do not use it.
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int fsync (int fd);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int fdatasync (int fd);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern void sync ();
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ [Obsolete ("Dropped in POSIX 1003.1-2001. " +
+++ "Use Unistd.sysconf (SysConf._SC_PAGESIZE).")]
+++ public static extern int getpagesize ();
+++
+++ // truncate(2)
+++ // int truncate(const char *path, off_t length);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_truncate")]
+++ public static extern int truncate (string path, long length);
+++
+++ // ftruncate(2)
+++ // int ftruncate(int fd, off_t length);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_ftruncate")]
+++ public static extern int ftruncate (int fd, long length);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int getdtablesize ();
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern int brk (IntPtr end_data_segment);
+++
+++ [DllImport (LIBC, SetLastError=true)]
+++ public static extern IntPtr sbrk (IntPtr increment);
+++
+++ // TODO: syscall(2)?
+++ // Probably safer to skip entirely.
+++
+++ // lockf(3)
+++ // int lockf(int fd, int cmd, off_t len);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_lockf")]
+++ public static extern int lockf (int fd, LockfCommand cmd, long len);
+++
+++ internal static object crypt_lock = new object ();
+++
+++ [DllImport (CRYPT, SetLastError=true, EntryPoint="crypt")]
+++ private static extern IntPtr sys_crypt (string key, string salt);
+++
+++ public static string crypt (string key, string salt)
+++ {
+++ lock (crypt_lock) {
+++ IntPtr r = sys_crypt (key, salt);
+++ return UnixMarshal.PtrToString (r);
+++ }
+++ }
+++
+++ internal static object encrypt_lock = new object ();
+++
+++ [DllImport (CRYPT, SetLastError=true, EntryPoint="encrypt")]
+++ private static extern void sys_encrypt ([In, Out] byte[] block, int edflag);
+++
+++ public static void encrypt (byte[] block, bool decode)
+++ {
+++ if (block.Length < 64)
+++ throw new ArgumentOutOfRangeException ("block", "Must refer to at least 64 bytes");
+++ lock (encrypt_lock) {
+++ sys_encrypt (block, decode ? 1 : 0);
+++ }
+++ }
+++
+++ // swab(3)
+++ // void swab(const void *from, void *to, ssize_t n);
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_swab")]
+++ public static extern void swab (IntPtr from, IntPtr to, long n);
+++
+++ public static unsafe void swab (void* from, void* to, long n)
+++ {
+++ swab ((IntPtr) from, (IntPtr) to, n);
+++ }
+++
+++ #endregion
+++
+++ #region <utime.h> Declarations
+++ //
+++ // <utime.h> -- COMPLETE
+++ //
+++
+++ [DllImport (MPH, SetLastError=true,
+++ EntryPoint="Mono_Posix_Syscall_utime")]
+++ private static extern int sys_utime (string filename, ref Utimbuf buf, int use_buf);
+++
+++ public static int utime (string filename, ref Utimbuf buf)
+++ {
+++ return sys_utime (filename, ref buf, 1);
+++ }
+++
+++ public static int utime (string filename)
+++ {
+++ Utimbuf buf = new Utimbuf ();
+++ return sys_utime (filename, ref buf, 0);
+++ }
+++ #endregion
+++ }
+++
+++ #endregion
+++}
+++
+++// vim: noexpandtab
--- /dev/null
--- /dev/null
--- /dev/null
+++//
+++// MakeMap.cs: Builds a C map of constants defined on C# land
+++//
+++// Authors:
+++// Miguel de Icaza (miguel@novell.com)
+++// Jonathan Pryor (jonpryor@vt.edu)
+++//
+++// (C) 2003 Novell, Inc.
+++// (C) 2004 Jonathan Pryor
+++//
+++
+++//
+++// Permission is hereby granted, free of charge, to any person obtaining
+++// a copy of this software and associated documentation files (the
+++// "Software"), to deal in the Software without restriction, including
+++// without limitation the rights to use, copy, modify, merge, publish,
+++// distribute, sublicense, and/or sell copies of the Software, and to
+++// permit persons to whom the Software is furnished to do so, subject to
+++// the following conditions:
+++//
+++// The above copyright notice and this permission notice shall be
+++// included in all copies or substantial portions of the Software.
+++//
+++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+++//
+++using System;
+++using System.Collections;
+++using System.IO;
+++using System.Reflection;
+++using System.Runtime.InteropServices;
+++
+++delegate void CreateFileHandler (string assembly_name, string file_prefix);
+++delegate void AssemblyAttributesHandler (Assembly assembly);
+++delegate void TypeHandler (Type t, string ns, string fn);
+++delegate void CloseFileHandler (string file_prefix);
+++
+++class MakeMap {
+++
+++ public static int Main (string [] args)
+++ {
+++ FileGenerator[] generators = new FileGenerator[]{
+++ new HeaderFileGenerator (),
+++ new SourceFileGenerator (),
+++ new ConvertFileGenerator (),
+++ new MphPrototypeFileGenerator (),
+++ };
+++
+++ MakeMap composite = new MakeMap ();
+++ foreach (FileGenerator g in generators) {
+++ composite.FileCreators += new CreateFileHandler (g.CreateFile);
+++ composite.AssemblyAttributesHandler +=
+++ new AssemblyAttributesHandler (g.WriteAssemblyAttributes);
+++ composite.TypeHandler += new TypeHandler (g.WriteType);
+++ composite.FileClosers += new CloseFileHandler (g.CloseFile);
+++ }
+++
+++ return composite.Run (args);
+++ }
+++
+++ event CreateFileHandler FileCreators;
+++ event AssemblyAttributesHandler AssemblyAttributesHandler;
+++ event TypeHandler TypeHandler;
+++ event CloseFileHandler FileClosers;
+++
+++ int Run (string[] args)
+++ {
+++ if (args.Length != 2){
+++ Console.WriteLine ("Usage is: make-map assembly output");
+++ return 1;
+++ }
+++
+++ string assembly_name = args[0];
+++ string output = args[1];
+++
+++ FileCreators (assembly_name, output);
+++
+++ Assembly assembly = Assembly.LoadFrom (assembly_name);
+++ AssemblyAttributesHandler (assembly);
+++
+++ Type [] exported_types = assembly.GetTypes ();
+++ Array.Sort (exported_types, new TypeFullNameComparer ());
+++
+++ foreach (Type t in exported_types) {
+++ string ns = t.Namespace;
+++ if (ns == null || !ns.StartsWith ("Mono"))
+++ continue;
+++ string fn = GetNativeName (t.FullName);
+++ ns = GetNativeName (ns);
+++
+++ TypeHandler (t, ns, fn);
+++ }
+++ FileClosers (output);
+++
+++ return 0;
+++ }
+++
+++ private class TypeFullNameComparer : IComparer {
+++ public int Compare (object o1, object o2)
+++ {
+++ Type t1 = o1 as Type;
+++ Type t2 = o2 as Type;
+++ if (t1 == t2)
+++ return 0;
+++ if (t1 == null)
+++ return 1;
+++ if (t2 == null)
+++ return -1;
+++ return Comparer.DefaultInvariant.Compare (t1.FullName, t2.FullName);
+++ }
+++ }
+++
+++ private class _MemberNameComparer : IComparer {
+++ public int Compare (object o1, object o2)
+++ {
+++ MemberInfo m1 = o1 as MemberInfo;
+++ MemberInfo m2 = o2 as MemberInfo;
+++ if (m1 == m2)
+++ return 0;
+++ if (m1 == null)
+++ return 1;
+++ if (m2 == null)
+++ return -1;
+++ return Comparer.DefaultInvariant.Compare (m1.Name, m2.Name);
+++ }
+++ }
+++
+++ internal static IComparer MemberNameComparer = new _MemberNameComparer ();
+++
+++ internal static string GetNativeName (string fn)
+++ {
+++ fn = fn.Replace ('.', '_');
+++ if (fn.StartsWith ("Mono_Unix_Native"))
+++ return fn.Replace ("Mono_Unix_Native", "Mono_Posix");
+++ return fn.Replace ("Mono_Unix", "Mono_Posix");
+++ }
+++}
+++
+++abstract class FileGenerator {
+++ public abstract void CreateFile (string assembly_name, string file_prefix);
+++
+++ public virtual void WriteAssemblyAttributes (Assembly assembly)
+++ {
+++ }
+++
+++ public abstract void WriteType (Type t, string ns, string fn);
+++ public abstract void CloseFile (string file_prefix);
+++
+++ protected static void WriteHeader (StreamWriter s, string assembly)
+++ {
+++ WriteHeader (s, assembly, false);
+++ }
+++
+++ protected static void WriteHeader (StreamWriter s, string assembly, bool noConfig)
+++ {
+++ s.WriteLine (
+++ "/*\n" +
+++ " * This file was automatically generated by make-map from {0}.\n" +
+++ " *\n" +
+++ " * DO NOT MODIFY.\n" +
+++ " */",
+++ assembly);
+++ if (!noConfig) {
+++ s.WriteLine ("#include <config.h>");
+++ }
+++ s.WriteLine ();
+++ }
+++
+++ protected static bool CanMapType (Type t, out bool bits)
+++ {
+++ object [] attributes = t.GetCustomAttributes (false);
+++ bool map = false;
+++ bits = false;
+++
+++ foreach (object attr in attributes) {
+++ if (attr.GetType ().Name == "MapAttribute")
+++ map = true;
+++ if (attr.GetType ().Name == "FlagsAttribute")
+++ bits = true;
+++ }
+++ return map;
+++ }
+++
+++ protected static string GetNativeType (Type t)
+++ {
+++ string ut = t.Name;
+++ if (t.IsEnum)
+++ ut = Enum.GetUnderlyingType (t).Name;
+++ Type et = t.GetElementType ();
+++ if (et != null && et.IsEnum)
+++ ut = Enum.GetUnderlyingType (et).Name;
+++
+++ string type = null;
+++
+++ switch (ut) {
+++ case "Boolean": type = "int"; break;
+++ case "Byte": type = "unsigned char"; break;
+++ case "SByte": type = "signed char"; break;
+++ case "Int16": type = "short"; break;
+++ case "UInt16": type = "unsigned short"; break;
+++ case "Int32": type = "int"; break;
+++ case "UInt32": type = "unsigned int"; break;
+++ case "UInt32[]": type = "unsigned int*"; break;
+++ case "Int64": type = "gint64"; break;
+++ case "UInt64": type = "guint64"; break;
+++ case "IntPtr": type = "void*"; break;
+++ case "Byte[]": type = "void*"; break;
+++ case "String": type = "const char*"; break;
+++ case "StringBuilder": type = "char*"; break;
+++ case "Void": type = "void"; break;
+++ case "HandleRef": type = "void*"; break;
+++ }
+++ if (type != null)
+++ return string.Format ("{0}{1}", type,
+++ t.IsByRef ? "*" : "");
+++ return GetTypeName (t);
+++ }
+++
+++ private static string GetTypeName (Type t)
+++ {
+++ if (t.Namespace.StartsWith ("System"))
+++ return "int /* warning: unknown mapping for type: " + t.Name + " */";
+++ string ts = "struct " +
+++ MakeMap.GetNativeName (t.FullName).Replace ("+", "_").Replace ("&", "*");
+++ return ts;
+++ }
+++}
+++
+++class HeaderFileGenerator : FileGenerator {
+++ StreamWriter sh;
+++
+++ public override void CreateFile (string assembly_name, string file_prefix)
+++ {
+++ sh = File.CreateText (file_prefix + ".h");
+++ WriteHeader (sh, assembly_name);
+++ sh.WriteLine ("#ifndef INC_Mono_Posix_" + file_prefix + "_H");
+++ sh.WriteLine ("#define INC_Mono_Posix_" + file_prefix + "_H\n");
+++ sh.WriteLine ("#include <glib/gtypes.h>\n");
+++ sh.WriteLine ("G_BEGIN_DECLS\n");
+++ }
+++
+++ public override void WriteType (Type t, string ns, string fn)
+++ {
+++ bool bits;
+++ if (!CanMapType (t, out bits))
+++ return;
+++ string etype = GetNativeType (t);
+++
+++ WriteLiteralValues (sh, t, fn);
+++ sh.WriteLine ("int {1}_From{2} ({0} x, {0} *r);", etype, ns, t.Name);
+++ sh.WriteLine ("int {1}_To{2} ({0} x, {0} *r);", etype, ns, t.Name);
+++ sh.WriteLine ();
+++ }
+++
+++ static void WriteLiteralValues (StreamWriter sh, Type t, string n)
+++ {
+++ object inst = Activator.CreateInstance (t);
+++ FieldInfo[] fields = t.GetFields ();
+++ Array.Sort (fields, MakeMap.MemberNameComparer);
+++ foreach (FieldInfo fi in fields) {
+++ if (!fi.IsLiteral)
+++ continue;
+++ sh.WriteLine ("#define {0}_{1} 0x{2:x}", n, fi.Name, fi.GetValue (inst));
+++ }
+++ }
+++
+++ public override void CloseFile (string file_prefix)
+++ {
+++ sh.WriteLine ("G_END_DECLS\n");
+++ sh.WriteLine ("#endif /* ndef INC_Mono_Posix_" + file_prefix + "_H */\n");
+++ sh.Close ();
+++ }
+++}
+++
+++class SourceFileGenerator : FileGenerator {
+++ StreamWriter sc;
+++
+++ public override void CreateFile (string assembly_name, string file_prefix)
+++ {
+++ sc = File.CreateText (file_prefix + ".c");
+++ WriteHeader (sc, assembly_name);
+++
+++ if (file_prefix.IndexOf ("/") != -1)
+++ file_prefix = file_prefix.Substring (file_prefix.IndexOf ("/") + 1);
+++ sc.WriteLine ("#include \"{0}.h\"", file_prefix);
+++ sc.WriteLine ();
+++ }
+++
+++ public override void WriteAssemblyAttributes (Assembly assembly)
+++ {
+++ object [] x = assembly.GetCustomAttributes (false);
+++ Console.WriteLine ("Got: " + x.Length);
+++ foreach (object aattr in assembly.GetCustomAttributes (false)) {
+++ Console.WriteLine ("Got: " + aattr.GetType ().Name);
+++ if (aattr.GetType ().Name == "HeaderAttribute"){
+++ WriteDefines (sc, aattr);
+++ WriteIncludes (sc, aattr);
+++ }
+++ }
+++ }
+++
+++ static void WriteDefines (TextWriter writer, object o)
+++ {
+++ PropertyInfo prop = o.GetType ().GetProperty ("Defines");
+++ if (prop == null)
+++ throw new Exception ("Cannot find 'Defines' property");
+++
+++ MethodInfo method = prop.GetGetMethod ();
+++ string [] defines = method.Invoke (o, null).ToString ().Split (',');
+++ foreach (string def in defines) {
+++ writer.WriteLine ("#ifndef {0}", def);
+++ writer.WriteLine ("#define {0}", def);
+++ writer.WriteLine ("#endif /* ndef {0} */", def);
+++ }
+++ }
+++
+++ static void WriteIncludes (TextWriter writer, object o)
+++ {
+++ PropertyInfo prop = o.GetType ().GetProperty ("Includes");
+++ if (prop == null)
+++ throw new Exception ("Cannot find 'Includes' property");
+++
+++ MethodInfo method = prop.GetGetMethod ();
+++ string [] includes = method.Invoke (o, null).ToString ().Split (',');;
+++ foreach (string inc in includes){
+++ if (inc.Length > 3 &&
+++ string.CompareOrdinal (inc, 0, "ah:", 0, 3) == 0) {
+++ string i = inc.Substring (3);
+++ writer.WriteLine ("#ifdef HAVE_" + (i.ToUpper ().Replace ("/", "_").Replace (".", "_")));
+++ writer.WriteLine ("#include <{0}>", i);
+++ writer.WriteLine ("#endif");
+++ } else
+++ writer.WriteLine ("#include <{0}>", inc);
+++ }
+++ writer.WriteLine ();
+++ }
+++
+++ public override void WriteType (Type t, string ns, string fn)
+++ {
+++ bool bits;
+++ if (!CanMapType (t, out bits))
+++ return;
+++ string etype = GetNativeType (t);
+++
+++ WriteFromManagedType (t, ns, fn, etype, bits);
+++ WriteToManagedType (t, ns, fn, etype, bits);
+++ }
+++
+++ private void WriteFromManagedType (Type t, string ns, string fn, string etype, bool bits)
+++ {
+++ sc.WriteLine ("int {1}_From{2} ({0} x, {0} *r)", etype, ns, t.Name);
+++ sc.WriteLine ("{");
+++ sc.WriteLine ("\t*r = 0;");
+++ // For many values, 0 is a valid value, but doesn't have it's own symbol.
+++ // Examples: Error (0 means "no error"), WaitOptions (0 means "no options").
+++ // Make 0 valid for all conversions.
+++ sc.WriteLine ("\tif (x == 0)\n\t\treturn 0;");
+++ FieldInfo[] fields = t.GetFields ();
+++ Array.Sort (fields, MakeMap.MemberNameComparer);
+++ foreach (FieldInfo fi in fields) {
+++ if (!fi.IsLiteral)
+++ continue;
+++ if (Attribute.GetCustomAttribute (fi,
+++ typeof(ObsoleteAttribute), false) != null) {
+++ sc.WriteLine ("\t/* {0}_{1} is obsolete; ignoring */", fn, fi.Name);
+++ continue;
+++ }
+++ if (bits)
+++ // properly handle case where [Flags] enumeration has helper
+++ // synonyms. e.g. DEFFILEMODE and ACCESSPERMS for mode_t.
+++ sc.WriteLine ("\tif ((x & {0}_{1}) == {0}_{1})", fn, fi.Name);
+++ else
+++ sc.WriteLine ("\tif (x == {0}_{1})", fn, fi.Name);
+++ sc.WriteLine ("#ifdef {0}", fi.Name);
+++ if (bits)
+++ sc.WriteLine ("\t\t*r |= {1};", fn, fi.Name);
+++ else
+++ sc.WriteLine ("\t\t{{*r = {1}; return 0;}}", fn, fi.Name);
+++ sc.WriteLine ("#else /* def {0} */\n\t\t{{errno = EINVAL; return -1;}}", fi.Name);
+++ sc.WriteLine ("#endif /* ndef {0} */", fi.Name);
+++ }
+++ if (bits)
+++ sc.WriteLine ("\treturn 0;");
+++ else
+++ sc.WriteLine ("\terrno = EINVAL; return -1;"); // return error if not matched
+++ sc.WriteLine ("}\n");
+++ }
+++
+++ private void WriteToManagedType (Type t, string ns, string fn, string etype, bool bits)
+++ {
+++ sc.WriteLine ("int {1}_To{2} ({0} x, {0} *r)", etype, ns, t.Name);
+++ sc.WriteLine ("{");
+++ sc.WriteLine ("\t*r = 0;", etype);
+++ // For many values, 0 is a valid value, but doesn't have it's own symbol.
+++ // Examples: Error (0 means "no error"), WaitOptions (0 means "no options").
+++ // Make 0 valid for all conversions.
+++ sc.WriteLine ("\tif (x == 0)\n\t\treturn 0;");
+++ FieldInfo[] fields = t.GetFields ();
+++ Array.Sort (fields, MakeMap.MemberNameComparer);
+++ foreach (FieldInfo fi in fields) {
+++ if (!fi.IsLiteral)
+++ continue;
+++ sc.WriteLine ("#ifdef {0}", fi.Name);
+++ if (bits)
+++ // properly handle case where [Flags] enumeration has helper
+++ // synonyms. e.g. DEFFILEMODE and ACCESSPERMS for mode_t.
+++ sc.WriteLine ("\tif ((x & {1}) == {1})\n\t\t*r |= {0}_{1};", fn, fi.Name);
+++ else
+++ sc.WriteLine ("\tif (x == {1})\n\t\t{{*r = {0}_{1}; return 0;}}", fn, fi.Name);
+++ sc.WriteLine ("#endif /* ndef {0} */", fi.Name);
+++ }
+++ if (bits)
+++ sc.WriteLine ("\treturn 0;");
+++ else
+++ sc.WriteLine ("\terrno = EINVAL; return -1;");
+++ sc.WriteLine ("}\n");
+++ }
+++
+++ public override void CloseFile (string file_prefix)
+++ {
+++ sc.Close ();
+++ }
+++}
+++
+++class ConvertFileGenerator : FileGenerator {
+++ StreamWriter scs;
+++
+++ public override void CreateFile (string assembly_name, string file_prefix)
+++ {
+++ scs = File.CreateText (file_prefix + ".cs");
+++ WriteHeader (scs, assembly_name, true);
+++ scs.WriteLine ("using System;");
+++ scs.WriteLine ("using System.Runtime.InteropServices;");
+++ scs.WriteLine ("using Mono.Unix.Native;\n");
+++ scs.WriteLine ("namespace Mono.Unix.Native {\n");
+++ scs.WriteLine ("\t[CLSCompliant (false)]");
+++ scs.WriteLine ("\tpublic sealed /* static */ partial class NativeConvert");
+++ scs.WriteLine ("\t{");
+++ scs.WriteLine ("\t\tprivate NativeConvert () {}\n");
+++ scs.WriteLine ("\t\tprivate const string LIB = \"MonoPosixHelper\";\n");
+++ scs.WriteLine ("\t\tprivate static void ThrowArgumentException (object value)");
+++ scs.WriteLine ("\t\t{");
+++ scs.WriteLine ("\t\t\tthrow new ArgumentOutOfRangeException (\"value\", value,");
+++ scs.WriteLine ("\t\t\t\tLocale.GetText (\"Current platform doesn't support this value.\"));");
+++ scs.WriteLine ("\t\t}\n");
+++ }
+++
+++ public override void WriteType (Type t, string ns, string fn)
+++ {
+++ bool bits;
+++ if (!CanMapType (t, out bits))
+++ return;
+++
+++ string mtype = Enum.GetUnderlyingType(t).Name;
+++ ObsoleteAttribute oa = (ObsoleteAttribute) Attribute.GetCustomAttribute (t,
+++ typeof(ObsoleteAttribute), false);
+++ string obsolete = "";
+++ if (oa != null) {
+++ obsolete = "[Obsolete (\"" + oa.Message + "\")]\n\t\t";
+++ }
+++ scs.WriteLine ("\t\t[DllImport (LIB, " +
+++ "EntryPoint=\"{0}_From{1}\")]\n" +
+++ "\t\tprivate static extern int From{1} ({1} value, out {2} rval);\n",
+++ ns, t.Name, mtype);
+++ scs.WriteLine ("\t\t{3}public static bool TryFrom{1} ({1} value, out {2} rval)\n" +
+++ "\t\t{{\n" +
+++ "\t\t\treturn From{1} (value, out rval) == 0;\n" +
+++ "\t\t}}\n", ns, t.Name, mtype, obsolete);
+++ scs.WriteLine ("\t\t{2}public static {0} From{1} ({1} value)", mtype, t.Name, obsolete);
+++ scs.WriteLine ("\t\t{");
+++ scs.WriteLine ("\t\t\t{0} rval;", mtype);
+++ scs.WriteLine ("\t\t\tif (From{0} (value, out rval) == -1)\n" +
+++ "\t\t\t\tThrowArgumentException (value);", t.Name);
+++ scs.WriteLine ("\t\t\treturn rval;");
+++ scs.WriteLine ("\t\t}\n");
+++ scs.WriteLine ("\t\t[DllImport (LIB, " +
+++ "EntryPoint=\"{0}_To{1}\")]\n" +
+++ "\t\tprivate static extern int To{1} ({2} value, out {1} rval);\n",
+++ ns, t.Name, mtype);
+++ scs.WriteLine ("\t\t{2}public static bool TryTo{1} ({0} value, out {1} rval)\n" +
+++ "\t\t{{\n" +
+++ "\t\t\treturn To{1} (value, out rval) == 0;\n" +
+++ "\t\t}}\n", mtype, t.Name, obsolete);
+++ scs.WriteLine ("\t\t{2}public static {1} To{1} ({0} value)", mtype, t.Name, obsolete);
+++ scs.WriteLine ("\t\t{");
+++ scs.WriteLine ("\t\t\t{0} rval;", t.Name);
+++ scs.WriteLine ("\t\t\tif (To{0} (value, out rval) == -1)\n" +
+++ "\t\t\t\tThrowArgumentException (value);", t.Name);
+++ scs.WriteLine ("\t\t\treturn rval;");
+++ scs.WriteLine ("\t\t}\n");
+++ }
+++
+++ public override void CloseFile (string file_prefix)
+++ {
+++ scs.WriteLine ("\t}");
+++ scs.WriteLine ("}\n");
+++ scs.Close ();
+++ }
+++}
+++
+++class MphPrototypeFileGenerator : FileGenerator {
+++ StreamWriter icall;
+++ Hashtable methods = new Hashtable ();
+++ Hashtable structs = new Hashtable ();
+++
+++ public override void CreateFile (string assembly_name, string file_prefix)
+++ {
+++ icall = File.CreateText (file_prefix + "-icalls.h");
+++ WriteHeader (icall, assembly_name);
+++ icall.WriteLine ("#ifndef INC_Mono_Posix_" + file_prefix + "_ICALLS_H");
+++ icall.WriteLine ("#define INC_Mono_Posix_" + file_prefix + "_ICALLS_H\n");
+++ icall.WriteLine ("#include <glib/gtypes.h>\n");
+++ icall.WriteLine ("G_BEGIN_DECLS\n");
+++
+++ // Kill warning about unused method
+++ DumpTypeInfo (null);
+++ }
+++
+++ public override void WriteType (Type t, string ns, string fn)
+++ {
+++ BindingFlags bf = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
+++ foreach (MethodInfo m in t.GetMethods (bf)) {
+++ if ((m.Attributes & MethodAttributes.PinvokeImpl) == 0)
+++ continue;
+++ DllImportAttribute dia = GetDllImportInfo (m);
+++ if (dia == null) {
+++ Console.WriteLine ("Unable to emit native prototype for P/Invoke " +
+++ "method: {0}", m);
+++ continue;
+++ }
+++ // we shouldn't declare prototypes for POSIX, etc. functions.
+++ if (dia.Value != "MonoPosixHelper" || IsOnExcludeList (dia.EntryPoint))
+++ continue;
+++ methods [dia.EntryPoint] = m;
+++ RecordStructs (m);
+++ }
+++ }
+++
+++ private static DllImportAttribute GetDllImportInfo (MethodInfo method)
+++ {
+++ // .NET 2.0 synthesizes pseudo-attributes such as DllImport
+++ DllImportAttribute dia = (DllImportAttribute) Attribute.GetCustomAttribute (method,
+++ typeof(DllImportAttribute), false);
+++ if (dia != null)
+++ return dia;
+++
+++ // We're not on .NET 2.0; assume we're on Mono and use some internal
+++ // methods...
+++ Type MonoMethod = Type.GetType ("System.Reflection.MonoMethod", false);
+++ if (MonoMethod == null) {
+++ Console.WriteLine ("cannot find MonoMethod");
+++ return null;
+++ }
+++ MethodInfo GetDllImportAttribute =
+++ MonoMethod.GetMethod ("GetDllImportAttribute",
+++ BindingFlags.Static | BindingFlags.NonPublic);
+++ if (GetDllImportAttribute == null) {
+++ Console.WriteLine ("cannot find GetDllImportAttribute");
+++ return null;
+++ }
+++ IntPtr mhandle = method.MethodHandle.Value;
+++ return (DllImportAttribute) GetDllImportAttribute.Invoke (null,
+++ new object[]{mhandle});
+++ }
+++
+++ private static string[] ExcludeList = new string[]{
+++ "Mono_Posix_Stdlib_snprintf",
+++ };
+++
+++ private bool IsOnExcludeList (string method)
+++ {
+++ int idx = Array.BinarySearch (ExcludeList, method);
+++ return (idx >= 0 && idx < ExcludeList.Length) ? true : false;
+++ }
+++
+++ private void RecordStructs (MethodInfo method)
+++ {
+++ ParameterInfo[] parameters = method.GetParameters ();
+++ foreach (ParameterInfo pi in parameters) {
+++ string s = GetNativeType (pi.ParameterType);
+++ if (s.StartsWith ("struct"))
+++ structs [s] = s;
+++ }
+++ }
+++
+++ public override void CloseFile (string file_prefix)
+++ {
+++ icall.WriteLine ("/*\n * Structure Declarations\n */");
+++ foreach (string s in Sort (structs.Keys))
+++ icall.WriteLine ("{0};", s.Replace ("*", ""));
+++
+++ icall.WriteLine ();
+++
+++ icall.WriteLine ("/*\n * Function Declarations\n */");
+++ foreach (string method in Sort (methods.Keys)) {
+++ WriteMethodDeclaration ((MethodInfo) methods [method], method);
+++ }
+++
+++ icall.WriteLine ("\nG_END_DECLS\n");
+++ icall.WriteLine ("#endif /* ndef INC_Mono_Posix_" + file_prefix + "_ICALLS_H */\n");
+++ icall.Close ();
+++ }
+++
+++ private static IEnumerable Sort (ICollection c)
+++ {
+++ ArrayList al = new ArrayList (c);
+++ al.Sort ();
+++ return al;
+++ }
+++
+++ private void WriteMethodDeclaration (MethodInfo method, string entryPoint)
+++ {
+++ icall.Write ("{0} ", GetNativeType (method.ReturnType));
+++ icall.Write ("{0} ", entryPoint);
+++ ParameterInfo[] parameters = method.GetParameters();
+++ if (parameters.Length == 0) {
+++ icall.WriteLine ("(void);");
+++ return;
+++ }
+++ if (parameters.Length > 0) {
+++ icall.Write ("(");
+++ WriteParameterDeclaration (parameters [0]);
+++ }
+++ for (int i = 1; i < parameters.Length; ++i) {
+++ icall.Write (", ");
+++ WriteParameterDeclaration (parameters [i]);
+++ }
+++ icall.WriteLine (");");
+++ }
+++
+++ private void DumpTypeInfo (Type t)
+++ {
+++ if (t == null)
+++ return;
+++
+++ icall.WriteLine ("\t\t/* Type Info for " + t.FullName + ":");
+++ foreach (MemberInfo mi in typeof(Type).GetMembers()) {
+++ icall.WriteLine ("\t\t\t{0}={1}", mi.Name, GetMemberValue (mi, t));
+++ }
+++ icall.WriteLine ("\t\t */");
+++ }
+++
+++ private static string GetMemberValue (MemberInfo mi, Type t)
+++ {
+++ try {
+++ switch (mi.MemberType) {
+++ case MemberTypes.Constructor:
+++ case MemberTypes.Method: {
+++ MethodBase b = (MethodBase) mi;
+++ if (b.GetParameters().Length == 0)
+++ return b.Invoke (t, new object[]{}).ToString();
+++ return "<<cannot invoke>>";
+++ }
+++ case MemberTypes.Field:
+++ return ((FieldInfo) mi).GetValue (t).ToString ();
+++ case MemberTypes.Property: {
+++ PropertyInfo pi = (PropertyInfo) mi;
+++ if (!pi.CanRead)
+++ return "<<cannot read>>";
+++ return pi.GetValue (t, null).ToString ();
+++ }
+++ default:
+++ return "<<unknown value>>";
+++ }
+++ }
+++ catch (Exception e) {
+++ return "<<exception reading member: " + e.Message + ">>";
+++ }
+++ }
+++
+++ private void WriteParameterDeclaration (ParameterInfo pi)
+++ {
+++ // DumpTypeInfo (pi.ParameterType);
+++ icall.Write ("{0} {1}", GetNativeType (pi.ParameterType), pi.Name);
+++ }
+++}
+++
+++// vim: noexpandtab
// on most platforms.
//
// This class is intended to be thread-safe.
+++ [Obsolete ("Use Mono.Unix.Native.CdeclFunction")]
public sealed class CdeclFunction
{
// The readonly fields (1) shouldn't be modified, and (2) should only be
+++2005-09-20 Jonathan Pryor <jonpryor@vt.edu>
+++
+++ * CdeclFunction.cs: [Obsolete]d by Mono.Unix.Native.CdeclFunction.
+++ * make-map.cs: Remove.
+++ * Stdlib.cs: [Obsolete] the types; use the Mono.Unix.Native.* types instead.
+++ * StdioFileStream.cs: Add GC.KeepAlive statements to prevent premature GC's
+++ (FxCop suggestion).
+++ * Syscall.cs: Remove [Map] attribute from all types; [CLSCompliant(false)]
+++ work; [Obsolete] all types and suggest using the Mono.Unix.Native.*
+++ replacements; remove [IncludeAttribute] -- superseded by
+++ Mono.Unix.Native/Syscall.cs's [HeaderAttribte] for CLS compliance.
+++ * UnixConvert.cs: [Obsolete]d by Mono.Unix.Native.NativeConvert.
+++ * UnixDirectory.cs, UnixDriveInfo.cs, UnixEnvironment.cs,
+++ UnixGroup.cs, UnixGroupInfo.cs,
+++ UnixSymbolicLinkInfo.cs, UnixUser.cs, UnixUserInfo.cs:
+++ Add [CLSCompliant(false)] as necessary.
+++ * UnixFile.cs, UnixDirectory.cs, UnixFileInfo.cs, UnixFileSystemInfo.cs:
+++ [CLSCompliant(false)], addition of method overloads for [Obsolete]d types,
+++ warn about changing return types.
+++ * UnixProcess.cs, UnixStream.cs: Add [CLSCompliant(false)] as necessary,
+++ and warn about changing property types.
+++
++2005-09-02 Jonathan Pryor <jonpryor@vt.edu>
++
++ * Stdlib.cs: Cache delegates passed to Stdlib.signal() so that they survive
++ garbage collections. Delegates can be removed by calling Stdlib.signal()
++ again with one of the Stdlib.SIG_* values (or the original return value of
++ Stdlib.signal()).
++ * UnixUser.cs, UnixGroup.cs, UnixEnvironment.cs: Clarify "Id" (int) vs.
++ "Name" (string) differences by always using a Id or Name suffix.
++
2005-07-01 Daniel Drake <dsd@gentoo.org>
* Syscall.cs: The entire extended attribute API now goes through MPH, to
catch (Exception e) {
throw new ArgumentException (Locale.GetText ("Invalid file stream"), "fileStream");
}
+++ GC.KeepAlive (this);
}
private void InitCanReadWrite (FileAccess access)
}
public IntPtr Handle {
--- get {AssertNotDisposed (); return file;}
+++ get {
+++ AssertNotDisposed ();
+++ GC.KeepAlive (this);
+++ return file;
+++ }
}
public override bool CanRead {
r = Stdlib.fseek (file, curPos, SeekFlags.SEEK_SET);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
+++ GC.KeepAlive (this);
return endPos;
}
}
long pos = Stdlib.ftell (file);
if (pos == -1)
UnixMarshal.ThrowExceptionForLastError ();
+++ GC.KeepAlive (this);
return (long) pos;
}
set {
AssertNotDisposed ();
int r = Stdlib.fgetpos (file, pos);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
+++ GC.KeepAlive (this);
}
public void RestoreFilePosition (FilePosition pos)
throw new ArgumentNullException ("value");
int r = Stdlib.fsetpos (file, pos);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
+++ GC.KeepAlive (this);
}
public override void Flush ()
int r = Stdlib.fflush (file);
if (r != 0)
UnixMarshal.ThrowExceptionForLastError ();
+++ GC.KeepAlive (this);
}
public override unsafe int Read ([In, Out] byte[] buffer, int offset, int count)
if (Stdlib.ferror (file) != 0)
throw new IOException ();
}
+++ GC.KeepAlive (this);
return (int) r;
}
{
AssertNotDisposed ();
Stdlib.rewind (file);
+++ GC.KeepAlive (this);
}
public override long Seek (long offset, SeekOrigin origin)
throw new IOException ("Unable to get current file position",
UnixMarshal.CreateExceptionForLastError ());
+++ GC.KeepAlive (this);
return pos;
}
}
if (r != (ulong) count)
UnixMarshal.ThrowExceptionForLastError ();
+++ GC.KeepAlive (this);
}
~StdioFileStream ()
canWrite = false;
GC.SuppressFinalize (this);
+++ GC.KeepAlive (this);
}
private bool canSeek = false;
// Jonathan Pryor (jonpryor@vt.edu)
//
// (C) 2004-2005 Jonathan Pryor
+++//
+++
+++// Deprecated Warning:
+++//
+++// This class is deprecated, and exists only for backward compatibility
+++// with development versions of Mono 1.1.x. It will be removed with
+++// Mono 1.2. Migrate to the Mono.Unix.Native types, or use the Unix*
+++// wrapper classes instead.
+++//
+++// The [Map] attributes have been removed. However, since the type names
+++// are identical to those in Mono.Unix.Native, the MonoPosixHelper methods
+++// will continue to exist and function correctly.
+++//
+++
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
#region Enumerations
+++ [Obsolete ("Use Mono.Unix.Native.Errno")]
[Map]
public enum Error : int {
// errors & their values liberally copied from
#region Classes
+++ [Obsolete ("Use Mono.Unix.Native.FilePosition")]
public sealed class FilePosition : IDisposable {
private static readonly int FilePositionDumpSize =
#if NET_2_0 && UNMANAGED_FN_PTR_SUPPORT_FIXED
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
#endif
+++ [Obsolete ("Use Mono.Unix.Native.SignalHandler")]
public delegate void SignalHandler (int signal);
+ #if !NET_2_0
internal sealed class SignalWrapper {
private IntPtr handler;
// anything from Syscall is non-portable, but restricting yourself to just
// Stdlib is intended to be portable.
//
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.Stdlib")]
public class Stdlib
{
internal const string LIBC = "msvcrt";
// Methods that require tuning are bound as `private sys_NAME' methods
// and then a `NAME' method is exposed.
//
+++// Deprecated Warning:
+++//
+++// This class is deprecated, and exists only for backward compatibility
+++// with development versions of Mono 1.1.x. It will be removed with
+++// Mono 1.2. Migrate to the Mono.Unix.Native types, or use the Unix*
+++// wrapper classes instead.
+++//
+++// The [Map] attributes have been removed. However, since the type names
+++// are identical to those in Mono.Unix.Native, the MonoPosixHelper methods
+++// will continue to exist and function correctly.
+++//
//
// Permission is hereby granted, free of charge, to any person obtaining
using System.Text;
using Mono.Unix;
---[assembly:Mono.Unix.IncludeAttribute (
--- new string [] {
--- "sys/types.h",
--- "sys/stat.h",
--- "ah:sys/poll.h",
--- "ah:sys/wait.h",
--- "ah:sys/statvfs.h",
--- "ah:sys/xattr.h",
--- "unistd.h",
--- "fcntl.h",
--- "signal.h",
--- "ah:poll.h",
--- "ah:grp.h",
--- "errno.h",
--- "ah:syslog.h",
--- },
--- new string [] {
--- "_GNU_SOURCE",
--- "_XOPEN_SOURCE",
--- })]
---
namespace Mono.Unix {
#region Enumerations
--- [Flags][Map]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.SyslogOptions")]
public enum SyslogOptions {
LOG_PID = 0x01, // log the pid with each message
LOG_CONS = 0x02, // log on the console if errors in sending
LOG_PERROR = 0x20 // log to stderr as well
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.SyslogFacility")]
public enum SyslogFacility {
LOG_KERN = 0 << 3,
LOG_USER = 1 << 3,
LOG_LOCAL7 = 23 << 3,
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.SyslogLevel")]
public enum SyslogLevel {
LOG_EMERG = 0, // system is unusable
LOG_ALERT = 1, // action must be taken immediately
LOG_DEBUG = 7 // debug-level messages
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.OpenFlags")]
public enum OpenFlags : int {
//
// One of these
}
// mode_t
--- [Flags][Map]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.FilePermissions")]
public enum FilePermissions : uint {
S_ISUID = 0x0800, // Set user ID on execution
S_ISGID = 0x0400, // Set gorup ID on execution
S_IFSOCK = 0xC000, // Socket
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.FcntlCommand")]
public enum FcntlCommand : int {
// Form /usr/include/bits/fcntl.h
F_DUPFD = 0, // Duplicate file descriptor.
F_NOTIFY = 1026, // Required notifications on a directory
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.LockType")]
public enum LockType : short {
F_RDLCK = 0, // Read lock.
F_WRLCK = 1, // Write lock.
F_UNLCK = 2, // Remove lock.
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.SeekFlags")]
public enum SeekFlags : short {
// values liberally copied from /usr/include/unistd.h
SEEK_SET = 0, // Seek from beginning of file.
L_XTND = SEEK_END, // BSD alias for SEEK_END
}
--- [Map, Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.DirectoryNotifyFlags")]
public enum DirectoryNotifyFlags : int {
// from /usr/include/bits/fcntl.h
DN_ACCESS = 0x00000001, // File accessed.
DN_MULTISHOT = unchecked ((int)0x80000000), // Don't remove notifier
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.PosixFadviseAdvice")]
public enum PosixFadviseAdvice : int {
POSIX_FADV_NORMAL = 0, // No further special treatment.
POSIX_FADV_RANDOM = 1, // Expect random page references.
POSIX_FADV_NOREUSE = 5, // Data will be accessed once.
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.PosixMadviseAdvice")]
public enum PosixMadviseAdvice : int {
POSIX_MADV_NORMAL = 0, // No further special treatment.
POSIX_MADV_RANDOM = 1, // Expect random page references.
POSIX_MADV_DONTNEED = 4, // Don't need these pages.
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.Signum")]
public enum Signum : int {
SIGHUP = 1, // Hangup (POSIX).
SIGINT = 2, // Interrupt (ANSI).
SIGUNUSED = 31
}
--- [Flags][Map]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.WaitOptions")]
public enum WaitOptions : int {
WNOHANG = 1, // Don't block waiting
WUNTRACED = 2, // Report status of stopped children
}
--- [Flags][Map]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.AccessModes")]
public enum AccessMode : int {
R_OK = 1,
W_OK = 2,
F_OK = 8,
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.PathConf")]
public enum PathConf : int {
_PC_LINK_MAX,
_PC_MAX_CANON,
_PC_2_SYMLINKS
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.SysConf")]
public enum SysConf : int {
_SC_ARG_MAX,
_SC_CHILD_MAX,
_SC_LEVEL4_CACHE_LINESIZE
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.ConfStr")]
public enum ConfStr : int {
_CS_PATH, /* The default search path. */
_CS_V6_WIDTH_RESTRICTED_ENVS,
_CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS
}
--- [Map]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.LockfCommand")]
public enum LockfCommand : int {
F_ULOCK = 0, // Unlock a previously locked region.
F_LOCK = 1, // Lock a region for exclusive use.
F_TEST = 3, // Test a region for other process locks.
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.PollEvents")]
public enum PollEvents : short {
POLLIN = 0x0001, // There is data to read
POLLPRI = 0x0002, // There is urgent data to read
POLLWRBAND = 0x0200, // Priority data may be written
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.XattrFlags")]
public enum XattrFlags : int {
XATTR_AUTO = 0,
XATTR_CREATE = 1,
XATTR_REPLACE = 2,
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.MountFlags")]
public enum MountFlags : ulong {
ST_RDONLY = 1, // Mount read-only
ST_NOSUID = 2, // Ignore suid and sgid bits
ST_NODIRATIME = 2048, // Do not update directory access times
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.MmapFlags")]
public enum MmapFlags : int {
MAP_SHARED = 0x01, // Share changes.
MAP_PRIVATE = 0x02, // Changes are private.
MAP_NONBLOCK = 0x10000, // Do not block on IO.
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.MmapProts")]
public enum MmapProt : int {
PROT_READ = 0x1, // Page can be read.
PROT_WRITE = 0x2, // Page can be written.
// growsup vma (mprotect only).
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.MsyncFlags")]
public enum MsyncFlags : int {
MS_ASYNC = 0x1, // Sync memory asynchronously.
MS_SYNC = 0x4, // Synchronous memory sync.
MS_INVALIDATE = 0x2, // Invalidate the caches.
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.MlockallFlags")]
public enum MlockallFlags : int {
MCL_CURRENT = 0x1, // Lock all currently mapped pages.
MCL_FUTURE = 0x2, // Lock all additions to address
}
--- [Map][Flags]
+++ [Flags]
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.MremapFlags")]
public enum MremapFlags : ulong {
MREMAP_MAYMOVE = 0x1,
}
#region Structures
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.Flock")]
public struct Flock {
public LockType l_type; // Type of lock: F_RDLCK, F_WRLCK, F_UNLCK
public SeekFlags l_whence; // How to interpret l_start
public /* pid_t */ int l_pid; // PID of process blocking our lock (F_GETLK only)
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.Pollfd")]
[StructLayout(LayoutKind.Sequential)]
public struct Pollfd {
public int fd;
public PollEvents revents;
}
+++ [Obsolete ("Use Mono.Unix.Native.Stat")]
public struct Stat {
+++ [CLSCompliant (false)]
public /* dev_t */ ulong st_dev; // device
+++ [CLSCompliant (false)]
public /* ino_t */ ulong st_ino; // inode
+++ [CLSCompliant (false)]
public FilePermissions st_mode; // protection
private uint _padding_; // padding for structure alignment
+++ [CLSCompliant (false)]
public /* nlink_t */ ulong st_nlink; // number of hard links
+++ [CLSCompliant (false)]
public /* uid_t */ uint st_uid; // user ID of owner
+++ [CLSCompliant (false)]
public /* gid_t */ uint st_gid; // group ID of owner
+++ [CLSCompliant (false)]
public /* dev_t */ ulong st_rdev; // device type (if inode device)
public /* off_t */ long st_size; // total size, in bytes
public /* blksize_t */ long st_blksize; // blocksize for filesystem I/O
public /* time_t */ long st_ctime; // time of last status change
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.Statvfs")]
public struct Statvfs {
public ulong f_bsize; // file system block size
public ulong f_frsize; // fragment size
public ulong f_namemax; // maximum filename length
}
+++ [Obsolete ("Use Mono.Unix.Native.Timeval")]
public struct Timeval {
public /* time_t */ long tv_sec; // seconds
public /* suseconds_t */ long tv_usec; // microseconds
}
+++ [Obsolete ("Use Mono.Unix.Native.Timezone")]
public struct Timezone {
public int tz_minuteswest; // minutes W of Greenwich
private int tz_dsttime; // type of dst correction (OBSOLETE)
}
+++ [Obsolete ("Use Mono.Unix.Native.Utimbuf")]
public struct Utimbuf {
public /* time_t */ long actime; // access time
public /* time_t */ long modtime; // modification time
#region Classes
+++ [Obsolete ("Use Mono.Unix.Native.Dirent")]
public sealed class Dirent
{
+++ [CLSCompliant (false)]
public /* ino_t */ ulong d_ino;
public /* off_t */ long d_off;
+++ [CLSCompliant (false)]
public ushort d_reclen;
public byte d_type;
public string d_name;
}
}
+++ [Obsolete ("Use Mono.Unix.Native.Fstab")]
public sealed class Fstab
{
public string fs_spec;
}
}
+++ [Obsolete ("Use Mono.Unix.Native.Group")]
public sealed class Group
{
public string gr_name;
public string gr_passwd;
+++ [CLSCompliant (false)]
public /* gid_t */ uint gr_gid;
public string[] gr_mem;
}
}
+++ [Obsolete ("Use Mono.Unix.Native.Passwd")]
public sealed class Passwd
{
public string pw_name;
public string pw_passwd;
+++ [CLSCompliant (false)]
public /* uid_t */ uint pw_uid;
+++ [CLSCompliant (false)]
public /* gid_t */ uint pw_gid;
public string pw_gecos;
public string pw_dir;
// EntryPointNotFoundException. This is also consistent with a missing
// P/Invoke into libc.so.
//
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.Syscall")]
public sealed class Syscall : Stdlib
{
new internal const string LIBC = "libc";
// TODO: times(2)
+++ //
+++ // <sys/utsname.h>
+++ //
+++
+++ // TODO: uname(2)
+++
#region <sys/wait.h> Declarations
//
// <sys/wait.h>
namespace Mono.Unix {
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Mono.Unix.Native.NativeConvert")]
public sealed /* static */ class UnixConvert
{
private UnixConvert () {}
{
private UnixDirectory () {}
+++ [CLSCompliant (false)]
public static UnixDirectoryInfo CreateDirectory (string path, FilePermissions mode)
{
int r = Syscall.mkdir (path, mode);
public override string Name {
get {
string r = UnixPath.GetFileName (FullPath);
--- if (r == null || r == "")
+++ if (r == null || r.Length == 0)
return FullPath;
return r;
}
}
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Create(Mono.Unix.Native.FilePermissions)")]
public void Create (FilePermissions mode)
{
--- int r = Syscall.mkdir (FullPath, mode);
+++ Mono.Unix.Native.FilePermissions _mode =
+++ (Mono.Unix.Native.FilePermissions) mode;
+++ Create (_mode);
+++ }
+++
+++ [CLSCompliant (false)]
+++ public void Create (Mono.Unix.Native.FilePermissions mode)
+++ {
+++ int r = Mono.Unix.Native.Syscall.mkdir (FullPath, mode);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
base.Refresh ();
}
public void Create ()
{
--- FilePermissions mode = FilePermissions.ACCESSPERMS;
+++ Mono.Unix.Native.FilePermissions mode =
+++ Mono.Unix.Native.FilePermissions.ACCESSPERMS;
Create (mode);
}
}
public long AvailableFreeSpace {
--- get {Refresh (); return (long) (stat.f_bavail * stat.f_bsize);}
+++ get {Refresh (); return Convert.ToInt64 (stat.f_bavail * stat.f_bsize);}
}
public string DriveFormat {
// set {}
}
+++ [CLSCompliant(false)]
+++ [Obsolete ("The return type of this property will change in the next release.")]
public ulong MaximumFilenameLength {
get {Refresh (); return stat.f_namemax;}
}
}
}
+++ [CLSCompliant (false)]
public static long GetConfigurationValue (SysConf name)
{
long r = Syscall.sysconf (name);
return r;
}
+++ [CLSCompliant (false)]
public static string GetConfigurationString (ConfStr name)
{
ulong len = Syscall.confstr (name, null, 0);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use UserId")]
public static uint User {
- get {return UnixUser.GetCurrentUser ();}
+ get {return UnixUser.GetCurrentUserId ();}
+ }
+
+++ [CLSCompliant (false)]
+++ public static uint UserId {
+++ get {return UnixUser.GetCurrentUserId ();}
+ + }
+ +
public static string UserName {
get {return UnixUser.GetCurrentUserName();}
}
return Syscall.getpgrp ();
}
+++ [CLSCompliant (false)]
+ [Obsolete ("Use GetSupplementaryGroupIds")]
public static uint[] GetSupplementaryGroups ()
- return GetSupplementaryGroupIds ()
+ {
++ return GetSupplementaryGroupIds ();
+ }
+
+++ [CLSCompliant (false)]
+ public static uint[] GetSupplementaryGroupIds ()
{
int ngroups = Syscall.getgroups (0, new uint[]{});
if (ngroups == -1)
return groups;
}
+++ [CLSCompliant (false)]
+ [Obsolete ("Use SetSupplementaryGroupIds")]
public static void SetSupplementaryGroups (uint[] list)
+ {
+ SetSupplementaryGroupIds (list);
+ }
+
+++ [CLSCompliant (false)]
+ public static void SetSupplementaryGroupIds (uint[] list)
{
int r = Syscall.setgroups (list);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
{
private UnixFile () {}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use CanAccess(string, Mono.Unix.Native.AccessModes)")]
public static bool CanAccess (string path, AccessMode mode)
{
int r = Syscall.access (path, mode);
return r == 0;
}
+++ [CLSCompliant (false)]
+++ public static bool CanAccess (string path, Native.AccessModes mode)
+++ {
+++ int r = Native.Syscall.access (path, mode);
+++ return r == 0;
+++ }
+++
public static void Delete (string path)
{
int r = Syscall.unlink (path);
return false;
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use GetConfigurationValue(string, Mono.Unix.Native.PathConf)")]
public static long GetConfigurationValue (string path, PathConf name)
{
Syscall.SetLastError ((Error) 0);
return r;
}
+++ [CLSCompliant (false)]
+++ public static long GetConfigurationValue (string path, Native.PathConf name)
+++ {
+++ Native.Stdlib.SetLastError ((Native.Errno) 0);
+++ long r = Native.Syscall.pathconf (path, name);
+++ if (r == -1 && Native.Stdlib.GetLastError() != (Native.Errno) 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ return r;
+++ }
+++
public static DateTime GetLastAccessTime (string path)
{
return new UnixFileInfo (path).LastAccessTime;
return new UnixFileInfo (path).LastStatusChangeTime;
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Return Type will change in next release")]
public static FilePermissions GetPermissions (string path)
{
return new UnixFileInfo (path).Permissions;
return sb.ToString (0, r);
}
+++ [CLSCompliant (false)]
+++ [Obsolete("Use SetPermissions(string, Mono.Unix.Native.FilePermissions)")]
public static void SetPermissions (string path, FilePermissions perms)
{
int r = Syscall.chmod (path, perms);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}
+++ [CLSCompliant (false)]
+++ public static void SetPermissions (string path, Native.FilePermissions perms)
+++ {
+++ int r = Native.Syscall.chmod (path, perms);
+++ UnixMarshal.ThrowExceptionForLastErrorIf (r);
+++ }
+++
public static UnixStream Create (string path)
{
FilePermissions mode = // 0644
return Create (path, mode);
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Create(string, Mono.Unix.Native.FilePermissions)")]
public static UnixStream Create (string path, FilePermissions mode)
{
int fd = Syscall.creat (path, mode);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ public static UnixStream Create (string path, Native.FilePermissions mode)
+++ {
+++ int fd = Native.Syscall.creat (path, mode);
+++ if (fd < 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ return new UnixStream (fd);
+++ }
+++
public static UnixPipes CreatePipes ()
{
int reading, writing;
return new UnixPipes (new UnixStream (reading), new UnixStream (writing));
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Open(string, Mono.Unix.Native.OpenFlags)")]
public static UnixStream Open (string path, OpenFlags flags)
{
int fd = Syscall.open (path, flags);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ public static UnixStream Open (string path, Native.OpenFlags flags)
+++ {
+++ int fd = Native.Syscall.open (path, flags);
+++ if (fd < 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ return new UnixStream (fd);
+++ }
+++
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Open(string, Mono.Unix.Native.OpenFlags, Mono.Unix.Native.FilePermissions)")]
public static UnixStream Open (string path, OpenFlags flags, FilePermissions mode)
{
int fd = Syscall.open (path, flags, mode);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ public static UnixStream Open (string path, Native.OpenFlags flags, Native.FilePermissions mode)
+++ {
+++ int fd = Native.Syscall.open (path, flags, mode);
+++ if (fd < 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ return new UnixStream (fd);
+++ }
+++
public static UnixStream Open (string path, FileMode mode)
{
OpenFlags flags = UnixConvert.ToOpenFlags (mode, FileAccess.ReadWrite);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Open(string, FileMode, FileAccess, Mono.Unix.Native.FilePermissions)")]
public static UnixStream Open (string path, FileMode mode, FileAccess access, FilePermissions perms)
{
OpenFlags flags = UnixConvert.ToOpenFlags (mode, access);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ public static UnixStream Open (string path, FileMode mode, FileAccess access, Native.FilePermissions perms)
+++ {
+++ Native.OpenFlags flags = Native.NativeConvert.ToOpenFlags (mode, access);
+++ int fd = Native.Syscall.open (path, flags, perms);
+++ if (fd < 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ return new UnixStream (fd);
+++ }
+++
public static UnixStream OpenRead (string path)
{
return Open (path, FileMode.Open, FileAccess.Read);
return Open (path, FileMode.OpenOrCreate, FileAccess.Write);
}
+++ [CLSCompliant (false)]
public static void SetOwner (string path, uint owner, uint group)
{
int r = Syscall.chown (path, owner, group);
SetOwner (path, uid, gid);
}
+++ [CLSCompliant (false)]
public static void SetLinkOwner (string path, uint owner, uint group)
{
int r = Syscall.lchown (path, owner, group);
return Create (mode);
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Create(Mono.Unix.Native.FilePermissions)")]
public UnixStream Create (FilePermissions mode)
{
int fd = Syscall.creat (FullPath, mode);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ public UnixStream Create (Native.FilePermissions mode)
+++ {
+++ int fd = Native.Syscall.creat (FullPath, mode);
+++ if (fd < 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ base.Refresh ();
+++ return new UnixStream (fd);
+++ }
+++
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Open(Mono.Unix.Native.OpenFlags)")]
public UnixStream Open (OpenFlags flags)
{
int fd = Syscall.open (FullPath, flags);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ public UnixStream Open (Native.OpenFlags flags)
+++ {
+++ int fd = Native.Syscall.open (FullPath, flags);
+++ if (fd < 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ return new UnixStream (fd);
+++ }
+++
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Open(Mono.Unix.Native.OpenFlags,Mono.Unix.Native.FilePermissions)")]
public UnixStream Open (OpenFlags flags, FilePermissions mode)
{
int fd = Syscall.open (FullPath, flags, mode);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ public UnixStream Open (Native.OpenFlags flags, Native.FilePermissions mode)
+++ {
+++ int fd = Native.Syscall.open (FullPath, flags, mode);
+++ if (fd < 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ return new UnixStream (fd);
+++ }
+++
public UnixStream Open (FileMode mode)
{
OpenFlags flags = UnixConvert.ToOpenFlags (mode, FileAccess.ReadWrite);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Open (System.IO.FileMode,System.IO.FileAccess,Mono.Unix.Native.FilePermissions)")]
public UnixStream Open (FileMode mode, FileAccess access, FilePermissions perms)
{
OpenFlags flags = UnixConvert.ToOpenFlags (mode, access);
return new UnixStream (fd);
}
+++ [CLSCompliant (false)]
+++ public UnixStream Open (FileMode mode, FileAccess access, Native.FilePermissions perms)
+++ {
+++ Native.OpenFlags flags = Native.NativeConvert.ToOpenFlags (mode, access);
+++ int fd = Native.Syscall.open (FullPath, flags, perms);
+++ if (fd < 0)
+++ UnixMarshal.ThrowExceptionForLastError ();
+++ return new UnixStream (fd);
+++ }
+++
public UnixStream OpenRead ()
{
return Open (FileMode.Open, FileAccess.Read);
}
}
+++ [CLSCompliant (false)]
public ulong Device {
get {AssertValid (); return stat.st_dev;}
}
+++ [CLSCompliant (false)]
public ulong Inode {
get {AssertValid (); return stat.st_ino;}
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("The type of this property will change in the next release.")]
public FilePermissions Mode {
get {AssertValid (); return stat.st_mode;}
}
+++ [CLSCompliant (false)]
public FilePermissions Permissions {
get {AssertValid (); return stat.st_mode & ~FilePermissions.S_IFMT;}
}
+++ [CLSCompliant (false)]
public FilePermissions FileType {
get {AssertValid (); return stat.st_mode & FilePermissions.S_IFMT;}
}
+++ [CLSCompliant (false)]
public ulong LinkCount {
get {AssertValid (); return (ulong) stat.st_nlink;}
}
+++ [CLSCompliant (false)]
public uint OwnerUser {
get {AssertValid (); return stat.st_uid;}
}
+++ [CLSCompliant (false)]
public uint OwnerGroup {
get {AssertValid (); return stat.st_gid;}
}
+++ [CLSCompliant (false)]
public ulong DeviceType {
get {AssertValid (); return stat.st_rdev;}
}
return (mode & type) == type;
}
+++ internal static bool IsType (Native.FilePermissions mode, Native.FilePermissions type)
+++ {
+++ return (mode & type) == type;
+++ }
+++
+++ [CLSCompliant (false)]
public bool CanAccess (AccessMode mode)
{
int r = Syscall.access (FullPath, mode);
public abstract void Delete ();
+++ [CLSCompliant (false)]
public long GetConfigurationValue (PathConf name)
{
Syscall.SetLastError ((Error) 0);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}
+++ [CLSCompliant (false)]
public void SetPermissions (FilePermissions perms)
{
int r = Syscall.chmod (FullPath, perms);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}
+++ [CLSCompliant (false)]
public virtual void SetOwner (uint owner, uint group)
{
int r = Syscall.chown (FullPath, owner, group);
{
private UnixGroup () {}
+++ [CLSCompliant (false)]
public static uint GetGroupId (string group)
{
return new UnixGroupInfo (group).GroupId;
return new UnixGroupInfo (group).Members;
}
+++ [CLSCompliant (false)]
public static string[] GetMembers (uint group)
{
return new UnixGroupInfo (group).Members;
}
+++ [CLSCompliant (false)]
+ [Obsolete ("Use GetGroupName")]
public static string GetName (uint group)
{
return new UnixGroupInfo (group).GroupName;
}
+++ [CLSCompliant (false)]
+ public static string GetGroupName (uint group)
+ {
+ return new UnixGroupInfo (group).GroupName;
+ }
+
public static string GetPassword (string group)
{
return new UnixGroupInfo (group).Password;
}
+++ [CLSCompliant (false)]
public static string GetPassword (uint group)
{
return new UnixGroupInfo (group).Password;
throw new ArgumentException (Locale.GetText ("invalid group name"), "group");
}
+++ [CLSCompliant (false)]
public UnixGroupInfo (uint group)
{
this.group = new Group ();
get {return group.gr_passwd;}
}
+++ [CLSCompliant (false)]
public uint GroupId {
get {return group.gr_gid;}
}
+++ [Obsolete ("Use GetMembers()")]
public string[] Members {
get {return group.gr_mem;}
}
+++ public string[] GetMembers ()
+++ {
+++ return group.gr_mem;
+++ }
+++
public override int GetHashCode ()
{
return group.GetHashCode ();
}
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("The type of this property will change in the next release.")]
public Signum TerminationSignal {
get {
if (!HasSignaled)
}
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("The type of this property will change in the next release.")]
public Signum StopSignal {
get {
if (!HasStopped)
Signal (Signum.SIGKILL);
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("Use Signal (Mono.Unix.Native.Signum)")]
public void Signal (Signum signal)
{
int r = Syscall.kill (pid, signal);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
}
+++ [CLSCompliant (false)]
+++ public void Signal (Native.Signum signal)
+++ {
+++ int r = Native.Syscall.kill (pid, signal);
+++ UnixMarshal.ThrowExceptionForLastErrorIf (r);
+++ }
+++
public void WaitForExit ()
{
int status;
}
}
+++ [CLSCompliant (false)]
+++ [Obsolete ("The type of this property will change in the next release.")]
public FilePermissions Permissions {
get {
Stat stat;
SendTo (output, (ulong) output.Length);
}
+++ [CLSCompliant (false)]
public void SendTo (UnixStream output, ulong count)
{
SendTo (output.Handle, count);
}
+++ [CLSCompliant (false)]
public void SendTo (int out_fd, ulong count)
{
if (!CanWrite)
UnixMarshal.ThrowExceptionForLastError ();
}
+++ [CLSCompliant (false)]
public void SetOwner (uint user, uint group)
{
AssertNotDisposed ();
SetOwner (uid, gid);
}
+++ [CLSCompliant (false)]
public long GetConfigurationValue (PathConf name)
{
AssertNotDisposed ();
base.Refresh ();
}
+++ [CLSCompliant (false)]
public override void SetOwner (uint owner, uint group)
{
int r = Syscall.lchown (FullPath, owner, group);
{
private UnixUser () {}
+++ [CLSCompliant (false)]
public static uint GetUserId (string user)
{
return new UnixUserInfo (user).UserId;
}
- public static uint GetCurrentUser ()
+++ [CLSCompliant (false)]
+ public static uint GetCurrentUserId ()
{
return Syscall.getuid ();
}
return buf.ToString ();
}
+++ [CLSCompliant (false)]
public static uint GetGroupId (string user)
{
return new UnixUserInfo (user).GroupId;
}
+++ [CLSCompliant (false)]
public static uint GetGroupId (uint user)
{
return new UnixUserInfo (user).GroupId;
return new UnixUserInfo (user).RealName;
}
+++ [CLSCompliant (false)]
public static string GetRealName (uint user)
{
return new UnixUserInfo (user).RealName;
return new UnixUserInfo (user).HomeDirectory;
}
+++ [CLSCompliant (false)]
public static string GetHomeDirectory (uint user)
{
return new UnixUserInfo (user).HomeDirectory;
}
+++ [CLSCompliant (false)]
+ [Obsolete ("Use GetUserName")]
public static string GetName (uint user)
{
return new UnixUserInfo (user).UserName;
}
+++ [CLSCompliant (false)]
+ public static string GetUserName (uint user)
+ {
+ return new UnixUserInfo (user).UserName;
+ }
+
public static string GetPassword (string user)
{
return new UnixUserInfo (user).Password;
}
+++ [CLSCompliant (false)]
public static string GetPassword (uint user)
{
return new UnixUserInfo (user).Password;
return new UnixUserInfo (user).ShellProgram;
}
+++ [CLSCompliant (false)]
public static string GetShellProgram (uint user)
{
return new UnixUserInfo (user).ShellProgram;
throw new ArgumentException (Locale.GetText ("invalid username"), "user");
}
+++ [CLSCompliant (false)]
public UnixUserInfo (uint user)
{
passwd = new Passwd ();
get {return passwd.pw_passwd;}
}
+++ [CLSCompliant (false)]
public uint UserId {
get {return passwd.pw_uid;}
}
+++ [CLSCompliant (false)]
public uint GroupId {
get {return passwd.pw_gid;}
}
+++ /dev/null
---//
---// MakeMap.cs: Builds a C map of constants defined on C# land
---//
---// Authors:
---// Miguel de Icaza (miguel@novell.com)
---// Jonathan Pryor (jonpryor@vt.edu)
---//
---// (C) 2003 Novell, Inc.
---// (C) 2004 Jonathan Pryor
---//
---
---//
---// Permission is hereby granted, free of charge, to any person obtaining
---// a copy of this software and associated documentation files (the
---// "Software"), to deal in the Software without restriction, including
---// without limitation the rights to use, copy, modify, merge, publish,
---// distribute, sublicense, and/or sell copies of the Software, and to
---// permit persons to whom the Software is furnished to do so, subject to
---// the following conditions:
---//
---// The above copyright notice and this permission notice shall be
---// included in all copies or substantial portions of the Software.
---//
---// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
---// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
---// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
---// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
---// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
---// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
---// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---//
---using System;
---using System.Collections;
---using System.IO;
---using System.Reflection;
---using System.Runtime.InteropServices;
---
---delegate void CreateFileHandler (string assembly_name, string file_prefix);
---delegate void AssemblyAttributesHandler (Assembly assembly);
---delegate void TypeHandler (Type t, string ns, string fn);
---delegate void CloseFileHandler (string file_prefix);
---
---class MakeMap {
---
--- public static int Main (string [] args)
--- {
--- FileGenerator[] generators = new FileGenerator[]{
--- new HeaderFileGenerator (),
--- new SourceFileGenerator (),
--- new ConvertFileGenerator (),
--- new MphPrototypeFileGenerator (),
--- };
---
--- MakeMap composite = new MakeMap ();
--- foreach (FileGenerator g in generators) {
--- composite.FileCreators += new CreateFileHandler (g.CreateFile);
--- composite.AssemblyAttributesHandler +=
--- new AssemblyAttributesHandler (g.WriteAssemblyAttributes);
--- composite.TypeHandler += new TypeHandler (g.WriteType);
--- composite.FileClosers += new CloseFileHandler (g.CloseFile);
--- }
---
--- return composite.Run (args);
--- }
---
--- event CreateFileHandler FileCreators;
--- event AssemblyAttributesHandler AssemblyAttributesHandler;
--- event TypeHandler TypeHandler;
--- event CloseFileHandler FileClosers;
---
--- int Run (string[] args)
--- {
--- if (args.Length != 2){
--- Console.WriteLine ("Usage is: make-map assembly output");
--- return 1;
--- }
---
--- string assembly_name = args[0];
--- string output = args[1];
---
--- FileCreators (assembly_name, output);
---
--- Assembly assembly = Assembly.LoadFrom (assembly_name);
--- AssemblyAttributesHandler (assembly);
---
--- Type [] exported_types = assembly.GetTypes ();
---
--- foreach (Type t in exported_types) {
--- string ns = t.Namespace;
--- if (ns == null || !ns.StartsWith ("Mono"))
--- continue;
--- string fn = GetNativeName (t.FullName);
--- ns = GetNativeName (ns);
---
--- TypeHandler (t, ns, fn);
--- }
--- FileClosers (output);
---
--- return 0;
--- }
---
--- internal static string GetNativeName (string fn)
--- {
--- return fn.Replace (".", "_").Replace ("Mono_Unix", "Mono_Posix");
--- }
---}
---
---abstract class FileGenerator {
--- public abstract void CreateFile (string assembly_name, string file_prefix);
---
--- public virtual void WriteAssemblyAttributes (Assembly assembly)
--- {
--- }
---
--- public abstract void WriteType (Type t, string ns, string fn);
--- public abstract void CloseFile (string file_prefix);
---
--- protected static void WriteHeader (StreamWriter s, string assembly)
--- {
--- s.WriteLine (
--- "/*\n" +
--- " * This file was automatically generated by make-map from {0}.\n" +
--- " *\n" +
--- " * DO NOT MODIFY.\n" +
--- " */\n" +
--- "#include <config.h>\n",
--- assembly);
--- }
---
--- protected static bool CanMapType (Type t, out bool bits)
--- {
--- object [] attributes = t.GetCustomAttributes (false);
--- bool map = false;
--- bits = false;
---
--- foreach (object attr in attributes) {
--- if (attr.GetType ().Name == "MapAttribute")
--- map = true;
--- if (attr.GetType ().Name == "FlagsAttribute")
--- bits = true;
--- }
--- return map;
--- }
---
--- protected static string GetNativeType (Type t)
--- {
--- string ut = t.Name;
--- if (t.IsEnum)
--- ut = Enum.GetUnderlyingType (t).Name;
--- Type et = t.GetElementType ();
--- if (et != null && et.IsEnum)
--- ut = Enum.GetUnderlyingType (et).Name;
---
--- string type = null;
---
--- switch (ut) {
--- case "Boolean": type = "int"; break;
--- case "Byte": type = "unsigned char"; break;
--- case "SByte": type = "signed char"; break;
--- case "Int16": type = "short"; break;
--- case "UInt16": type = "unsigned short"; break;
--- case "Int32": type = "int"; break;
--- case "UInt32": type = "unsigned int"; break;
--- case "UInt32[]": type = "unsigned int*"; break;
--- case "Int64": type = "gint64"; break;
--- case "UInt64": type = "guint64"; break;
--- case "IntPtr": type = "void*"; break;
--- case "Byte[]": type = "void*"; break;
--- case "String": type = "const char*"; break;
--- case "StringBuilder": type = "char*"; break;
--- case "Void": type = "void"; break;
--- case "HandleRef": type = "void*"; break;
--- }
--- if (type != null)
--- return string.Format ("{0}{1}", type,
--- t.IsByRef ? "*" : "");
--- return GetTypeName (t);
--- }
---
--- private static string GetTypeName (Type t)
--- {
--- if (t.Namespace.StartsWith ("System"))
--- return "int /* warning: unknown mapping for type: " + t.Name + " */";
--- string ts = "struct " +
--- MakeMap.GetNativeName (t.FullName).Replace ("+", "_").Replace ("&", "*");
--- return ts;
--- }
---}
---
---class HeaderFileGenerator : FileGenerator {
--- StreamWriter sh;
---
--- public override void CreateFile (string assembly_name, string file_prefix)
--- {
--- sh = File.CreateText (file_prefix + ".h");
--- WriteHeader (sh, assembly_name);
--- sh.WriteLine ("#ifndef INC_Mono_Posix_" + file_prefix + "_H");
--- sh.WriteLine ("#define INC_Mono_Posix_" + file_prefix + "_H\n");
--- sh.WriteLine ("#include <glib/gtypes.h>\n");
--- sh.WriteLine ("G_BEGIN_DECLS\n");
--- }
---
--- public override void WriteType (Type t, string ns, string fn)
--- {
--- bool bits;
--- if (!CanMapType (t, out bits))
--- return;
--- string etype = GetNativeType (t);
---
--- WriteLiteralValues (sh, t, fn);
--- sh.WriteLine ("int {1}_From{2} ({0} x, {0} *r);", etype, ns, t.Name);
--- sh.WriteLine ("int {1}_To{2} ({0} x, {0} *r);", etype, ns, t.Name);
--- sh.WriteLine ();
--- }
---
--- static void WriteLiteralValues (StreamWriter sh, Type t, string n)
--- {
--- object inst = Activator.CreateInstance (t);
--- foreach (FieldInfo fi in t.GetFields ()){
--- if (!fi.IsLiteral)
--- continue;
--- sh.WriteLine ("#define {0}_{1} 0x{2:x}", n, fi.Name, fi.GetValue (inst));
--- }
--- }
---
--- public override void CloseFile (string file_prefix)
--- {
--- sh.WriteLine ("G_END_DECLS\n");
--- sh.WriteLine ("#endif /* ndef INC_Mono_Posix_" + file_prefix + "_H */\n");
--- sh.Close ();
--- }
---}
---
---class SourceFileGenerator : FileGenerator {
--- StreamWriter sc;
---
--- public override void CreateFile (string assembly_name, string file_prefix)
--- {
--- sc = File.CreateText (file_prefix + ".c");
--- WriteHeader (sc, assembly_name);
---
--- if (file_prefix.IndexOf ("/") != -1)
--- file_prefix = file_prefix.Substring (file_prefix.IndexOf ("/") + 1);
--- sc.WriteLine ("#include \"{0}.h\"", file_prefix);
--- sc.WriteLine ();
--- }
---
--- public override void WriteAssemblyAttributes (Assembly assembly)
--- {
--- object [] x = assembly.GetCustomAttributes (false);
--- Console.WriteLine ("Got: " + x.Length);
--- foreach (object aattr in assembly.GetCustomAttributes (false)) {
--- Console.WriteLine ("Got: " + aattr.GetType ().Name);
--- if (aattr.GetType ().Name == "IncludeAttribute"){
--- WriteDefines (sc, aattr);
--- WriteIncludes (sc, aattr);
--- }
--- }
--- }
---
--- static void WriteDefines (TextWriter writer, object o)
--- {
--- PropertyInfo prop = o.GetType ().GetProperty ("Defines");
--- if (prop == null)
--- throw new Exception ("Cannot find 'Defines' property");
---
--- MethodInfo method = prop.GetGetMethod ();
--- string [] defines = (string []) method.Invoke (o, null);
--- foreach (string def in defines) {
--- writer.WriteLine ("#ifndef {0}", def);
--- writer.WriteLine ("#define {0}", def);
--- writer.WriteLine ("#endif /* ndef {0} */", def);
--- }
--- }
---
--- static void WriteIncludes (TextWriter writer, object o)
--- {
--- PropertyInfo prop = o.GetType ().GetProperty ("Includes");
--- if (prop == null)
--- throw new Exception ("Cannot find 'Includes' property");
---
--- MethodInfo method = prop.GetGetMethod ();
--- string [] includes = (string []) method.Invoke (o, null);
--- foreach (string inc in includes){
--- if (inc.Length > 3 &&
--- string.CompareOrdinal (inc, 0, "ah:", 0, 3) == 0) {
--- string i = inc.Substring (3);
--- writer.WriteLine ("#ifdef HAVE_" + (i.ToUpper ().Replace ("/", "_").Replace (".", "_")));
--- writer.WriteLine ("#include <{0}>", i);
--- writer.WriteLine ("#endif");
--- } else
--- writer.WriteLine ("#include <{0}>", inc);
--- }
--- writer.WriteLine ();
--- }
---
--- public override void WriteType (Type t, string ns, string fn)
--- {
--- bool bits;
--- if (!CanMapType (t, out bits))
--- return;
--- string etype = GetNativeType (t);
---
--- WriteFromManagedType (t, ns, fn, etype, bits);
--- WriteToManagedType (t, ns, fn, etype, bits);
--- }
---
--- private void WriteFromManagedType (Type t, string ns, string fn, string etype, bool bits)
--- {
--- sc.WriteLine ("int {1}_From{2} ({0} x, {0} *r)", etype, ns, t.Name);
--- sc.WriteLine ("{");
--- sc.WriteLine ("\t*r = 0;");
--- // For many values, 0 is a valid value, but doesn't have it's own symbol.
--- // Examples: Error (0 means "no error"), WaitOptions (0 means "no options").
--- // Make 0 valid for all conversions.
--- sc.WriteLine ("\tif (x == 0)\n\t\treturn 0;");
--- foreach (FieldInfo fi in t.GetFields ()) {
--- if (!fi.IsLiteral)
--- continue;
--- if (Attribute.GetCustomAttribute (fi,
--- typeof(ObsoleteAttribute), false) != null) {
--- sc.WriteLine ("\t/* {0}_{1} is obsolete; ignoring */", fn, fi.Name);
--- continue;
--- }
--- if (bits)
--- // properly handle case where [Flags] enumeration has helper
--- // synonyms. e.g. DEFFILEMODE and ACCESSPERMS for mode_t.
--- sc.WriteLine ("\tif ((x & {0}_{1}) == {0}_{1})", fn, fi.Name);
--- else
--- sc.WriteLine ("\tif (x == {0}_{1})", fn, fi.Name);
--- sc.WriteLine ("#ifdef {0}", fi.Name);
--- if (bits)
--- sc.WriteLine ("\t\t*r |= {1};", fn, fi.Name);
--- else
--- sc.WriteLine ("\t\t{{*r = {1}; return 0;}}", fn, fi.Name);
--- sc.WriteLine ("#else /* def {0} */\n\t\t{{errno = EINVAL; return -1;}}", fi.Name);
--- sc.WriteLine ("#endif /* ndef {0} */", fi.Name);
--- }
--- if (bits)
--- sc.WriteLine ("\treturn 0;");
--- else
--- sc.WriteLine ("\terrno = EINVAL; return -1;"); // return error if not matched
--- sc.WriteLine ("}\n");
--- }
---
--- private void WriteToManagedType (Type t, string ns, string fn, string etype, bool bits)
--- {
--- sc.WriteLine ("int {1}_To{2} ({0} x, {0} *r)", etype, ns, t.Name);
--- sc.WriteLine ("{");
--- sc.WriteLine ("\t*r = 0;", etype);
--- // For many values, 0 is a valid value, but doesn't have it's own symbol.
--- // Examples: Error (0 means "no error"), WaitOptions (0 means "no options").
--- // Make 0 valid for all conversions.
--- sc.WriteLine ("\tif (x == 0)\n\t\treturn 0;");
--- foreach (FieldInfo fi in t.GetFields ()) {
--- if (!fi.IsLiteral)
--- continue;
--- sc.WriteLine ("#ifdef {0}", fi.Name);
--- if (bits)
--- // properly handle case where [Flags] enumeration has helper
--- // synonyms. e.g. DEFFILEMODE and ACCESSPERMS for mode_t.
--- sc.WriteLine ("\tif ((x & {1}) == {1})\n\t\t*r |= {0}_{1};", fn, fi.Name);
--- else
--- sc.WriteLine ("\tif (x == {1})\n\t\t{{*r = {0}_{1}; return 0;}}", fn, fi.Name);
--- sc.WriteLine ("#endif /* ndef {0} */", fi.Name);
--- }
--- if (bits)
--- sc.WriteLine ("\treturn 0;");
--- else
--- sc.WriteLine ("\terrno = EINVAL; return -1;");
--- sc.WriteLine ("}\n");
--- }
---
--- public override void CloseFile (string file_prefix)
--- {
--- sc.Close ();
--- }
---}
---
---class ConvertFileGenerator : FileGenerator {
--- StreamWriter scs;
---
--- public override void CreateFile (string assembly_name, string file_prefix)
--- {
--- scs = File.CreateText (file_prefix + ".cs");
--- WriteHeader (scs, assembly_name);
--- scs.WriteLine ("using System;");
--- scs.WriteLine ("using System.Runtime.InteropServices;");
--- scs.WriteLine ("using Mono.Unix;\n");
--- scs.WriteLine ("namespace Mono.Unix {\n");
--- scs.WriteLine ("\tpublic sealed /* static */ class UnixConvert");
--- scs.WriteLine ("\t{");
--- scs.WriteLine ("\t\tprivate UnixConvert () {}\n");
--- scs.WriteLine ("\t\tprivate const string LIB = \"MonoPosixHelper\";\n");
--- scs.WriteLine ("\t\tprivate static void ThrowArgumentException (object value)");
--- scs.WriteLine ("\t\t{");
--- scs.WriteLine ("\t\t\tthrow new ArgumentOutOfRangeException (\"value\", value,");
--- scs.WriteLine ("\t\t\t\tLocale.GetText (\"Current platform doesn't support this value.\"));");
--- scs.WriteLine ("\t\t}\n");
--- }
---
--- public override void WriteType (Type t, string ns, string fn)
--- {
--- bool bits;
--- if (!CanMapType (t, out bits))
--- return;
---
--- string mtype = Enum.GetUnderlyingType(t).Name;
--- ObsoleteAttribute oa = (ObsoleteAttribute) Attribute.GetCustomAttribute (t,
--- typeof(ObsoleteAttribute), false);
--- string obsolete = "";
--- if (oa != null) {
--- obsolete = "[Obsolete (\"" + oa.Message + "\")]\n\t\t";
--- }
--- scs.WriteLine ("\t\t[DllImport (LIB, " +
--- "EntryPoint=\"{0}_From{1}\")]\n" +
--- "\t\tprivate static extern int From{1} ({1} value, out {2} rval);\n",
--- ns, t.Name, mtype);
--- scs.WriteLine ("\t\t{3}public static bool TryFrom{1} ({1} value, out {2} rval)\n" +
--- "\t\t{{\n" +
--- "\t\t\treturn From{1} (value, out rval) == 0;\n" +
--- "\t\t}}\n", ns, t.Name, mtype, obsolete);
--- scs.WriteLine ("\t\t{2}public static {0} From{1} ({1} value)", mtype, t.Name, obsolete);
--- scs.WriteLine ("\t\t{");
--- scs.WriteLine ("\t\t\t{0} rval;", mtype);
--- scs.WriteLine ("\t\t\tif (From{0} (value, out rval) == -1)\n" +
--- "\t\t\t\tThrowArgumentException (value);", t.Name);
--- scs.WriteLine ("\t\t\treturn rval;");
--- scs.WriteLine ("\t\t}\n");
--- scs.WriteLine ("\t\t[DllImport (LIB, " +
--- "EntryPoint=\"{0}_To{1}\")]\n" +
--- "\t\tprivate static extern int To{1} ({2} value, out {1} rval);\n",
--- ns, t.Name, mtype);
--- scs.WriteLine ("\t\t{2}public static bool TryTo{1} ({0} value, out {1} rval)\n" +
--- "\t\t{{\n" +
--- "\t\t\treturn To{1} (value, out rval) == 0;\n" +
--- "\t\t}}\n", mtype, t.Name, obsolete);
--- scs.WriteLine ("\t\t{2}public static {1} To{1} ({0} value)", mtype, t.Name, obsolete);
--- scs.WriteLine ("\t\t{");
--- scs.WriteLine ("\t\t\t{0} rval;", t.Name);
--- scs.WriteLine ("\t\t\tif (To{0} (value, out rval) == -1)\n" +
--- "\t\t\t\tThrowArgumentException (value);", t.Name);
--- scs.WriteLine ("\t\t\treturn rval;");
--- scs.WriteLine ("\t\t}\n");
--- }
---
--- public override void CloseFile (string file_prefix)
--- {
--- scs.WriteLine ("\t}");
--- scs.WriteLine ("}\n");
--- scs.Close ();
--- }
---}
---
---class MphPrototypeFileGenerator : FileGenerator {
--- StreamWriter icall;
--- Hashtable methods = new Hashtable ();
--- Hashtable structs = new Hashtable ();
---
--- public override void CreateFile (string assembly_name, string file_prefix)
--- {
--- icall = File.CreateText (file_prefix + "-icalls.h");
--- WriteHeader (icall, assembly_name);
--- icall.WriteLine ("#ifndef INC_Mono_Posix_" + file_prefix + "_ICALLS_H");
--- icall.WriteLine ("#define INC_Mono_Posix_" + file_prefix + "_ICALLS_H\n");
--- icall.WriteLine ("#include <glib/gtypes.h>\n");
--- icall.WriteLine ("G_BEGIN_DECLS\n");
---
--- // Kill warning about unused method
--- DumpTypeInfo (null);
--- }
---
--- public override void WriteType (Type t, string ns, string fn)
--- {
--- BindingFlags bf = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
--- foreach (MethodInfo m in t.GetMethods (bf)) {
--- if ((m.Attributes & MethodAttributes.PinvokeImpl) == 0)
--- continue;
--- DllImportAttribute dia = GetDllImportInfo (m);
--- if (dia == null) {
--- Console.WriteLine ("Unable to emit native prototype for P/Invoke " +
--- "method: {0}", m);
--- continue;
--- }
--- // we shouldn't declare prototypes for POSIX, etc. functions.
--- if (dia.Value != "MonoPosixHelper" || IsOnExcludeList (dia.EntryPoint))
--- continue;
--- methods [dia.EntryPoint] = m;
--- RecordStructs (m);
--- }
--- }
---
--- private static DllImportAttribute GetDllImportInfo (MethodInfo method)
--- {
--- // .NET 2.0 synthesizes pseudo-attributes such as DllImport
--- DllImportAttribute dia = (DllImportAttribute) Attribute.GetCustomAttribute (method,
--- typeof(DllImportAttribute), false);
--- if (dia != null)
--- return dia;
---
--- // We're not on .NET 2.0; assume we're on Mono and use some internal
--- // methods...
--- Type MonoMethod = Type.GetType ("System.Reflection.MonoMethod", false);
--- if (MonoMethod == null) {
--- Console.WriteLine ("cannot find MonoMethod");
--- return null;
--- }
--- MethodInfo GetDllImportAttribute =
--- MonoMethod.GetMethod ("GetDllImportAttribute",
--- BindingFlags.Static | BindingFlags.NonPublic);
--- if (GetDllImportAttribute == null) {
--- Console.WriteLine ("cannot find GetDllImportAttribute");
--- return null;
--- }
--- IntPtr mhandle = method.MethodHandle.Value;
--- return (DllImportAttribute) GetDllImportAttribute.Invoke (null,
--- new object[]{mhandle});
--- }
---
--- private static string[] ExcludeList = new string[]{
--- "Mono_Posix_Stdlib_snprintf",
--- };
---
--- private bool IsOnExcludeList (string method)
--- {
--- int idx = Array.BinarySearch (ExcludeList, method);
--- return (idx >= 0 && idx < ExcludeList.Length) ? true : false;
--- }
---
--- private void RecordStructs (MethodInfo method)
--- {
--- ParameterInfo[] parameters = method.GetParameters ();
--- foreach (ParameterInfo pi in parameters) {
--- string s = GetNativeType (pi.ParameterType);
--- if (s.StartsWith ("struct"))
--- structs [s] = s;
--- }
--- }
---
--- public override void CloseFile (string file_prefix)
--- {
--- icall.WriteLine ("/*\n * Structure Declarations\n */");
--- foreach (string s in Sort (structs.Keys))
--- icall.WriteLine ("{0};", s.Replace ("*", ""));
---
--- icall.WriteLine ();
---
--- icall.WriteLine ("/*\n * Function Declarations\n */");
--- foreach (string method in Sort (methods.Keys)) {
--- WriteMethodDeclaration ((MethodInfo) methods [method], method);
--- }
---
--- icall.WriteLine ("\nG_END_DECLS\n");
--- icall.WriteLine ("#endif /* ndef INC_Mono_Posix_" + file_prefix + "_ICALLS_H */\n");
--- icall.Close ();
--- }
---
--- private static IEnumerable Sort (ICollection c)
--- {
--- ArrayList al = new ArrayList (c);
--- al.Sort ();
--- return al;
--- }
---
--- private void WriteMethodDeclaration (MethodInfo method, string entryPoint)
--- {
--- icall.Write ("{0} ", GetNativeType (method.ReturnType));
--- icall.Write ("{0} ", entryPoint);
--- ParameterInfo[] parameters = method.GetParameters();
--- if (parameters.Length == 0) {
--- icall.WriteLine ("(void);");
--- return;
--- }
--- if (parameters.Length > 0) {
--- icall.Write ("(");
--- WriteParameterDeclaration (parameters [0]);
--- }
--- for (int i = 1; i < parameters.Length; ++i) {
--- icall.Write (", ");
--- WriteParameterDeclaration (parameters [i]);
--- }
--- icall.WriteLine (");");
--- }
---
--- private void DumpTypeInfo (Type t)
--- {
--- if (t == null)
--- return;
---
--- icall.WriteLine ("\t\t/* Type Info for " + t.FullName + ":");
--- foreach (MemberInfo mi in typeof(Type).GetMembers()) {
--- icall.WriteLine ("\t\t\t{0}={1}", mi.Name, GetMemberValue (mi, t));
--- }
--- icall.WriteLine ("\t\t */");
--- }
---
--- private static string GetMemberValue (MemberInfo mi, Type t)
--- {
--- try {
--- switch (mi.MemberType) {
--- case MemberTypes.Constructor:
--- case MemberTypes.Method: {
--- MethodBase b = (MethodBase) mi;
--- if (b.GetParameters().Length == 0)
--- return b.Invoke (t, new object[]{}).ToString();
--- return "<<cannot invoke>>";
--- }
--- case MemberTypes.Field:
--- return ((FieldInfo) mi).GetValue (t).ToString ();
--- case MemberTypes.Property: {
--- PropertyInfo pi = (PropertyInfo) mi;
--- if (!pi.CanRead)
--- return "<<cannot read>>";
--- return pi.GetValue (t, null).ToString ();
--- }
--- default:
--- return "<<unknown value>>";
--- }
--- }
--- catch (Exception e) {
--- return "<<exception reading member: " + e.Message + ">>";
--- }
--- }
---
--- private void WriteParameterDeclaration (ParameterInfo pi)
--- {
--- // DumpTypeInfo (pi.ParameterType);
--- icall.Write ("{0} {1}", GetNativeType (pi.ParameterType), pi.Name);
--- }
---}
---
---// vim: noexpandtab