Beispiel #1
0
        public static string GetConfigurationString(ConfstrName name)
        {
            ulong num = Syscall.confstr(name, null, (ulong)0);

            if (num == (long)-1)
            {
                UnixMarshal.ThrowExceptionForLastError();
            }
            if (num == 0)
            {
                return(string.Empty);
            }
            StringBuilder stringBuilder = new StringBuilder((int)num + 1);

            num = Syscall.confstr(name, stringBuilder, num);
            if (num == (long)-1)
            {
                UnixMarshal.ThrowExceptionForLastError();
            }
            return(stringBuilder.ToString());
        }
        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());
        }
Beispiel #3
0
 public override void Close()
 {
     if (this.file == StdioFileStream.InvalidFileStream)
     {
         return;
     }
     if (!this.owner)
     {
         this.Flush();
     }
     else if (Stdlib.fclose(this.file) != 0)
     {
         UnixMarshal.ThrowExceptionForLastError();
     }
     this.file     = StdioFileStream.InvalidFileStream;
     this.canRead  = false;
     this.canSeek  = false;
     this.canWrite = false;
     GC.SuppressFinalize(this);
     GC.KeepAlive(this);
 }
        public static UnixGroupInfo[] GetLocalGroups()
        {
            ArrayList arrayLists = new ArrayList();
            object    grpLock    = Syscall.grp_lock;

            Monitor.Enter(grpLock);
            try
            {
                if (Syscall.setgrent() != 0)
                {
                    UnixMarshal.ThrowExceptionForLastError();
                }
                try
                {
                    while (true)
                    {
                        Group group  = Syscall.getgrent();
                        Group group1 = group;
                        if (group == null)
                        {
                            break;
                        }
                        arrayLists.Add(new UnixGroupInfo(group1));
                    }
                    if ((int)Stdlib.GetLastError() != 0)
                    {
                        UnixMarshal.ThrowExceptionForLastError();
                    }
                }
                finally
                {
                    Syscall.endgrent();
                }
            }
            finally
            {
                Monitor.Exit(grpLock);
            }
            return((UnixGroupInfo[])arrayLists.ToArray(typeof(UnixGroupInfo)));
        }
        public static UnixUserInfo[] GetLocalUsers()
        {
            ArrayList arrayLists = new ArrayList();
            object    pwdLock    = Syscall.pwd_lock;

            Monitor.Enter(pwdLock);
            try
            {
                if (Syscall.setpwent() != 0)
                {
                    UnixMarshal.ThrowExceptionForLastError();
                }
                try
                {
                    while (true)
                    {
                        Passwd passwd  = Syscall.getpwent();
                        Passwd passwd1 = passwd;
                        if (passwd == null)
                        {
                            break;
                        }
                        arrayLists.Add(new UnixUserInfo(passwd1));
                    }
                    if ((int)Stdlib.GetLastError() != 0)
                    {
                        UnixMarshal.ThrowExceptionForLastError();
                    }
                }
                finally
                {
                    Syscall.endpwent();
                }
            }
            finally
            {
                Monitor.Exit(pwdLock);
            }
            return((UnixUserInfo[])arrayLists.ToArray(typeof(UnixUserInfo)));
        }
        private static Dirent[] GetEntries(IntPtr dirp, Regex regex)
        {
            int       num;
            IntPtr    intPtr;
            ArrayList arrayLists = new ArrayList();

            do
            {
                Dirent dirent = new Dirent();
                num = Syscall.readdir_r(dirp, dirent, out intPtr);
                if (num != 0 || !(intPtr != IntPtr.Zero) || !regex.Match(dirent.d_name).Success || !(dirent.d_name != ".") || !(dirent.d_name != ".."))
                {
                    continue;
                }
                arrayLists.Add(dirent);
            }while (num == 0 && intPtr != IntPtr.Zero);
            if (num != 0)
            {
                UnixMarshal.ThrowExceptionForLastError();
            }
            return((Dirent[])arrayLists.ToArray(typeof(Dirent)));
        }
Beispiel #7
0
        public override unsafe void Write(byte[] buffer, int offset, int count)
        {
            AssertNotDisposed();
            AssertValidBuffer(buffer, offset, count);
            if (!CanWrite)
            {
                throw new NotSupportedException("File Stream does not support writing");
            }

            ulong r = 0;

            fixed(byte *buf = &buffer[offset])
            {
                r = Native.Stdlib.fwrite(buf, (ulong)1, (ulong)count, file);
            }

            if (r != (ulong)count)
            {
                UnixMarshal.ThrowExceptionForLastError();
            }
            GC.KeepAlive(this);
        }
        public static string[] GetUserShells()
        {
            ArrayList shells = new ArrayList();

            lock (Native.Syscall.usershell_lock) {
                try {
                    if (Native.Syscall.setusershell() != 0)
                    {
                        UnixMarshal.ThrowExceptionForLastError();
                    }
                    string shell;
                    while ((shell = Native.Syscall.getusershell()) != null)
                    {
                        shells.Add(shell);
                    }
                }
                finally {
                    Native.Syscall.endusershell();
                }
            }

            return((string[])shells.ToArray(typeof(string)));
        }
Beispiel #9
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            unsafe
            {
                this.AssertNotDisposed();
                this.AssertValidBuffer(buffer, offset, count);
                if (!this.CanWrite)
                {
                    throw new NotSupportedException("File Stream does not support writing");
                }
                ulong num = (ulong)0;
                fixed(byte *numPointer = &buffer[offset])
                {
                    num = Stdlib.fwrite(numPointer, (ulong)1, (ulong)count, this.file);
                }

                if (num != (long)count)
                {
                    UnixMarshal.ThrowExceptionForLastError();
                }
                GC.KeepAlive(this);
            }
        }
Beispiel #10
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            this.AssertNotDisposed();
            if (!this.CanSeek)
            {
                throw new NotSupportedException("The File Descriptor does not support seeking");
            }
            SeekFlags seekFlag = SeekFlags.SEEK_CUR;

            switch (origin)
            {
            case SeekOrigin.Begin:
            {
                seekFlag = SeekFlags.SEEK_SET;
                break;
            }

            case SeekOrigin.Current:
            {
                seekFlag = SeekFlags.SEEK_CUR;
                break;
            }

            case SeekOrigin.End:
            {
                seekFlag = SeekFlags.SEEK_END;
                break;
            }
            }
            long num = Syscall.lseek(this.fileDescriptor, offset, seekFlag);

            if (num == (long)-1)
            {
                UnixMarshal.ThrowExceptionForLastError();
            }
            return(num);
        }
Beispiel #11
0
        public static string[] GetUserShells()
        {
            ArrayList arrayLists    = new ArrayList();
            object    usershellLock = Syscall.usershell_lock;

            Monitor.Enter(usershellLock);
            try
            {
                try
                {
                    if (Syscall.setusershell() != 0)
                    {
                        UnixMarshal.ThrowExceptionForLastError();
                    }
                    while (true)
                    {
                        string str  = Syscall.getusershell();
                        string str1 = str;
                        if (str == null)
                        {
                            break;
                        }
                        arrayLists.Add(str1);
                    }
                }
                finally
                {
                    Syscall.endusershell();
                }
            }
            finally
            {
                Monitor.Exit(usershellLock);
            }
            return((string[])arrayLists.ToArray(typeof(string)));
        }