示例#1
0
文件: IO.cs 项目: microsoft/BuildXL
        /// <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);
            }
        }
示例#2
0
文件: IO.cs 项目: microsoft/BuildXL
 /// <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);
示例#3
0
文件: IO.cs 项目: microsoft/BuildXL
 /// <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);
示例#4
0
文件: IO.cs 项目: microsoft/BuildXL
 /// <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);
示例#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;
示例#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;