Esempio n. 1
0
 public static void ThrowExceptionForErrorIf(int retval, Errno errno)
 {
     if (retval == -1)
     {
         UnixMarshal.ThrowExceptionForError(errno);
     }
 }
Esempio n. 2
0
        // Read the specified symbolic link.  If the file isn't a symbolic link,
        // return null; otherwise, return the contents of the symbolic link.
        //
        // readlink(2) is horribly evil, as there is no way to query how big the
        // symlink contents are.  Consequently, it's trial and error...
        internal static string ReadSymbolicLink(string path)
        {
            StringBuilder buf = new StringBuilder(256);

            do
            {
                int r = Native.Syscall.readlink(path, buf);
                if (r < 0)
                {
                    Native.Errno e;
                    switch (e = Native.Stdlib.GetLastError())
                    {
                    case Native.Errno.EINVAL:
                        // path isn't a symbolic link
                        return(null);

                    default:
                        UnixMarshal.ThrowExceptionForError(e);
                        break;
                    }
                }
                else if (r == buf.Capacity)
                {
                    buf.Capacity *= 2;
                }
                else
                {
                    return(buf.ToString(0, r));
                }
            } while (true);
        }
Esempio n. 3
0
        internal static string ReadSymbolicLink(string path)
        {
            int           num;
            StringBuilder stringBuilder = new StringBuilder(256);

            while (true)
            {
                num = Syscall.readlink(path, stringBuilder);
                if (num >= 0)
                {
                    if (num != stringBuilder.Capacity)
                    {
                        break;
                    }
                    StringBuilder capacity = stringBuilder;
                    capacity.Capacity = capacity.Capacity * 2;
                }
                else
                {
                    Errno lastError = Stdlib.GetLastError();
                    Errno errno     = lastError;
                    if (lastError == Errno.EINVAL)
                    {
                        return(null);
                    }
                    UnixMarshal.ThrowExceptionForError(errno);
                }
            }
            return(stringBuilder.ToString(0, num));
        }
Esempio n. 4
0
 public static string ReadLink(string path)
 {
     Native.Errno errno;
     path = ReadSymbolicLink(path, out errno);
     if (errno != 0)
     {
         UnixMarshal.ThrowExceptionForError(errno);
     }
     return(path);
 }
Esempio n. 5
0
        // Read the specified symbolic link.  If the file isn't a symbolic link,
        // return null; otherwise, return the contents of the symbolic link.
        internal static string ReadSymbolicLink(string path)
        {
            string target = TryReadLink(path);

            if (target == null)
            {
                Native.Errno errno = Native.Stdlib.GetLastError();
                if (errno != Native.Errno.EINVAL)
                {
                    UnixMarshal.ThrowExceptionForError(errno);
                }
            }
            return(target);
        }