Пример #1
0
        /// <summary>Invoke <see cref="Interop.Sys.SysConf"/>, throwing if it fails.</summary>
        private static int CheckedSysConf(Interop.Sys.SysConfName name)
        {
            long result = Interop.Sys.SysConf(name);

            if (result == -1)
            {
                Interop.ErrorInfo errno = Interop.Sys.GetLastErrorInfo();
                throw errno.Error == Interop.Error.EINVAL ?
                      new ArgumentOutOfRangeException(nameof(name), name, errno.GetErrorMessage()) :
                      Interop.GetIOException(errno);
            }
            return((int)result);
        }
Пример #2
0
        private static unsafe void Write(SafeFileHandle fd, byte *bufPtr, int count)
        {
            while (count > 0)
            {
                int bytesWritten = Interop.Sys.Write(fd, bufPtr, count);
                if (bytesWritten < 0)
                {
                    Interop.ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo();
                    if (errorInfo.Error == Interop.Error.EPIPE)
                    {
                        return;
                    }
                    else
                    {
                        throw Interop.GetIOException(errorInfo);
                    }
                }

                count  -= bytesWritten;
                bufPtr += bytesWritten;
            }
        }