* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Mono.Posix / Mono.Unix / UnixEnvironment.cs
index 11806d111b8609e58cc41601cbbd89ea8daf9563..4144c13317fc17f674cb6876df0e763866f75923 100644 (file)
@@ -39,10 +39,10 @@ namespace Mono.Unix {
 
                public static string CurrentDirectory {
                        get {
-                               return UnixDirectory.GetCurrentDirectory ();
+                               return UnixDirectoryInfo.GetCurrentDirectory ();
                        }
                        set {
-                               UnixDirectory.SetCurrentDirectory (value);
+                               UnixDirectoryInfo.SetCurrentDirectory (value);
                        }
                }
 
@@ -50,35 +50,24 @@ namespace Mono.Unix {
                        get {
                                StringBuilder buf = new StringBuilder (8);
                                int r = 0;
-                               Error e = (Error) 0;
+                               Native.Errno e = (Native.Errno) 0;
                                do {
                                        buf.Capacity *= 2;
-                                       r = Syscall.gethostname (buf);
-                               } while (r == (-1) && ((e = Syscall.GetLastError()) == Error.EINVAL) || 
-                                               (e == Error.ENAMETOOLONG));
+                                       r = Native.Syscall.gethostname (buf);
+                               } while (r == (-1) && ((e = Native.Stdlib.GetLastError()) == Native.Errno.EINVAL) || 
+                                               (e == Native.Errno.ENAMETOOLONG));
                                if (r == (-1))
                                        UnixMarshal.ThrowExceptionForLastError ();
                                return buf.ToString ();
                        }
                        set {
-                               Syscall.sethostname (value);
+                               int r = Native.Syscall.sethostname (value);
+                               UnixMarshal.ThrowExceptionForLastErrorIf (r);
                        }
                }
 
-               [CLSCompliant (false)]
-               [Obsolete ("Use RealUserId")]
-               public static uint User {
-                       get {return UnixUser.GetCurrentUserId ();}
-               }
-
-               [CLSCompliant (false)]
-               [Obsolete ("Use RealUserId")]
-               public static uint UserId {
-                       get {return UnixUser.GetCurrentUserId ();}
-               }
-
                public static string UserName {
-                       get {return UnixUser.GetCurrentUserName();}
+                       get {return UnixUserInfo.GetRealUser ().UserName;}
                }
 
                public static UnixGroupInfo RealGroup {
@@ -122,106 +111,94 @@ namespace Mono.Unix {
                }
 
                public static string Login {
-                       get {return UnixUser.GetLogin ();}
-               }
-
-               [CLSCompliant (false)]
-               [Obsolete ("Use GetConfigurationValue (Mono.Unix.Native.SysconfName)")]
-               public static long GetConfigurationValue (SysConf name)
-               {
-                       long r = Syscall.sysconf (name);
-                       if (r == -1 && Syscall.GetLastError() == Error.EINVAL)
-                               UnixMarshal.ThrowExceptionForLastError ();
-                       return r;
+                       get {return UnixUserInfo.GetRealUser ().UserName;}
                }
 
                [CLSCompliant (false)]
                public static long GetConfigurationValue (Native.SysconfName name)
                {
                        long r = Native.Syscall.sysconf (name);
-                       if (r == -1 && Native.Stdlib.GetLastError() == Native.Errno.EINVAL)
+                       if (r == -1 && Native.Stdlib.GetLastError() != (Native.Errno) 0)
                                UnixMarshal.ThrowExceptionForLastError ();
                        return r;
                }
 
-               [CLSCompliant (false)]
-               [Obsolete ("Use GetConfigurationString (Mono.Unix.Native.ConfstrName)")]
-               public static string GetConfigurationString (ConfStr name)
-               {
-                       ulong len = Syscall.confstr (name, null, 0);
-                       if (len == 0)
-                               return "";
-                       StringBuilder buf = new StringBuilder ((int) len+1);
-                       len = Syscall.confstr (name, buf, len);
-                       return buf.ToString ();
-               }
-
                [CLSCompliant (false)]
                public static string GetConfigurationString (Native.ConfstrName name)
                {
                        ulong len = Native.Syscall.confstr (name, null, 0);
+                       if (len == unchecked ((ulong) (-1)))
+                               UnixMarshal.ThrowExceptionForLastError ();
                        if (len == 0)
                                return "";
                        StringBuilder buf = new StringBuilder ((int) len+1);
                        len = Native.Syscall.confstr (name, buf, len);
+                       if (len == unchecked ((ulong) (-1)))
+                               UnixMarshal.ThrowExceptionForLastError ();
                        return buf.ToString ();
                }
 
                public static void SetNiceValue (int inc)
                {
-                       int r = Syscall.nice (inc);
+                       int r = Native.Syscall.nice (inc);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
 
                public static int CreateSession ()
                {
-                       return Syscall.setsid ();
+                       int s = Native.Syscall.setsid ();
+                       UnixMarshal.ThrowExceptionForLastErrorIf (s);
+                       return s;
                }
 
                public static void SetProcessGroup ()
                {
-                       int r = Syscall.setpgrp ();
+                       int r = Native.Syscall.setpgrp ();
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
 
                public static int GetProcessGroup ()
                {
-                       return Syscall.getpgrp ();
+                       return Native.Syscall.getpgrp ();
                }
 
-               [CLSCompliant (false)]
-               [Obsolete ("Use GetSupplementaryGroupIds")]
-               public static uint[] GetSupplementaryGroups ()
+               public static UnixGroupInfo[] GetSupplementaryGroups ()
                {
-                       return GetSupplementaryGroupIds ();
+                       uint[] ids = _GetSupplementaryGroupIds ();
+                       UnixGroupInfo[] groups = new UnixGroupInfo [ids.Length];
+                       for (int i = 0; i < groups.Length; ++i)
+                               groups [i] = new UnixGroupInfo (ids [i]);
+                       return groups;
                }
 
-               [CLSCompliant (false)]
-               [Obsolete ("The return type of this method will change in the next release")]
-               public static uint[] GetSupplementaryGroupIds ()
+               private static uint[] _GetSupplementaryGroupIds ()
                {
-                       int ngroups = Syscall.getgroups (0, new uint[]{});
+                       int ngroups = Native.Syscall.getgroups (0, new uint[]{});
                        if (ngroups == -1)
                                UnixMarshal.ThrowExceptionForLastError ();
                        uint[] groups = new uint[ngroups];
-                       int r = Syscall.getgroups (groups);
+                       int r = Native.Syscall.getgroups (groups);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                        return groups;
                }
 
-               [CLSCompliant (false)]
-               [Obsolete ("Use SetSupplementaryGroupIds(long[])")]
-               public static void SetSupplementaryGroups (uint[] list)
+               public static void SetSupplementaryGroups (UnixGroupInfo[] groups)
                {
-                       SetSupplementaryGroupIds (list);
+                       uint[] list = new uint [groups.Length];
+                       for (int i = 0; i < list.Length; ++i) {
+                               list [i] = Convert.ToUInt32 (groups [i].GroupId);
+                       }
+                       int r = Native.Syscall.setgroups (list);
+                       UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
 
-               [CLSCompliant (false)]
-               [Obsolete ("Use SetSupplementaryGroupIds(long[])")]
-               public static void SetSupplementaryGroupIds (uint[] list)
+               public static long[] GetSupplementaryGroupIds ()
                {
-                       int r = Syscall.setgroups (list);
-                       UnixMarshal.ThrowExceptionForLastErrorIf (r);
+                       uint[] _groups = _GetSupplementaryGroupIds ();
+                       long[] groups = new long [_groups.Length];
+                       for (int i = 0; i < groups.Length; ++i)
+                               groups [i] = _groups [i];
+                       return groups;
                }
 
                public static void SetSupplementaryGroupIds (long[] list)
@@ -229,13 +206,13 @@ namespace Mono.Unix {
                        uint[] _list = new uint [list.Length];
                        for (int i = 0; i < _list.Length; ++i)
                                _list [i] = Convert.ToUInt32 (list [i]);
-                       int r = Syscall.setgroups (_list);
+                       int r = Native.Syscall.setgroups (_list);
                        UnixMarshal.ThrowExceptionForLastErrorIf (r);
                }
 
                public static int GetParentProcessId ()
                {
-                       return Syscall.getppid ();
+                       return Native.Syscall.getppid ();
                }
                
                public static UnixProcess GetParentProcess ()
@@ -247,7 +224,7 @@ namespace Mono.Unix {
                {
                        ArrayList shells = new ArrayList ();
 
-                       lock (Syscall.usershell_lock) {
+                       lock (Native.Syscall.usershell_lock) {
                                try {
                                        if (Native.Syscall.setusershell () != 0)
                                                UnixMarshal.ThrowExceptionForLastError ();