System.IO.FileStream.ReadNative C# (CSharp) Method

ReadNative() private method

private ReadNative ( byte buffer, int offset, int count ) : int
buffer byte
offset int
count int
return int
        private unsafe int ReadNative(byte[] buffer, int offset, int count)
        {
            AssertCanRead(buffer, offset, count);

            if (_useAsyncIO)
                return ReadNativeAsync(buffer, offset, count, 0, CancellationToken.None).GetAwaiter().GetResult();

            // Make sure we are reading from the right spot
            VerifyOSHandlePosition();

            int errorCode = 0;
            int r = ReadFileNative(_fileHandle, buffer, offset, count, null, out errorCode);

            if (r == -1)
            {
                // For pipes, ERROR_BROKEN_PIPE is the normal end of the pipe.
                if (errorCode == ERROR_BROKEN_PIPE)
                {
                    r = 0;
                }
                else
                {
                    if (errorCode == ERROR_INVALID_PARAMETER)
                        throw new ArgumentException(SR.Arg_HandleNotSync, "_fileHandle");

                    throw Win32Marshal.GetExceptionForWin32Error(errorCode);
                }
            }
            Debug.Assert(r >= 0, "FileStream's ReadNative is likely broken.");
            _filePosition += r;

            return r;
        }