Beispiel #1
0
        /// <summary>
        /// Invokes the 'read' syscall, retrying on <see cref="Errno.EINTR"/>.
        /// </summary>
        /// <param name="handle">File descriptor</param>
        /// <param name="bytes">Buffer to which to read</param>
        /// <param name="offset">Index in <paramref name="bytes"/> at which to save read bytes</param>
        /// <param name="length">Max number of bytes to read</param>
        /// <returns>
        /// 0 on EOF, -1 on error, or number of bytes read otherwise.
        /// Returning a positive number that is less than <paramref name="length"/> does not indicate error.
        /// </returns>
        public unsafe static int Read(SafeFileHandle handle, byte[] bytes, int offset, int length)
        {
            Contract.Requires(bytes.Length >= offset + length);

            fixed(byte *buf = &bytes[offset])
            {
                int result;

                do
                {
                    result = Impl_Common.read(ToInt(handle), buf, length);
                }while (result < 0 && Marshal.GetLastWin32Error() == (int)Errno.EINTR);
                return(result);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new hardlink for file / directory specified by <paramref name="link"/> at <paramref name="hardlinkFilePath"/>.
 /// Returns 0 upon successful completion, and -1 otherwise.
 /// </summary>
 public static int link(string link, string hardlinkFilePath)
 => Impl_Common.link(link, hardlinkFilePath);
Beispiel #3
0
 /// <summary>
 /// Creates a symbolic link at <paramref name="symlinkFilePath"/> pointing to <paramref name="target"/>.
 /// Returns 0 upon successful completion, and -1 otherwise.
 /// </summary>
 public static int symlink(string target, string symlinkFilePath)
 => Impl_Common.symlink(target, symlinkFilePath);
Beispiel #4
0
 /// <summary>
 /// Creates a FIFO special file (a.k.a. named pipe).
 /// </summary>
 /// <returns>0 on success, -1 on error</returns>
 public static int MkFifo(string pathname, FilePermissions permission)
 => Impl_Common.mkfifo(pathname, permission);
Beispiel #5
0
 /// <remarks>
 /// Implemented by sending SIGKILL to a process with id <paramref name="pid"/>.
 /// The return value indicates whether the KILL signal was sent successfully.
 /// </remarks>
 public static bool ForceQuit(int pid) => Impl_Common.kill(pid, 9) == 0;
Beispiel #6
0
 /// <remarks>
 /// Implemented by calling "kill -0".
 /// This should be much cheaper than calling Process.GetProcessById().
 /// </remarks>
 public static bool IsAlive(int pid) => Impl_Common.kill(pid, 0) == 0;