private static int ReadFileNative(SafeFileHandle hFile, byte[] bytes, int offset, int count, out int bytesRead) { if (bytes.Length - offset < count) { throw new IndexOutOfRangeException("IORaceCondition"); } // You can't use the fixed statement on an array of length 0. if (bytes.Length == 0) { bytesRead = 0; return(ERROR_SUCCESS); } bool readSuccess; bytesRead = hFile.ReadFile(bytes, offset, count); readSuccess = (0 != bytesRead); if (readSuccess) { return(ERROR_SUCCESS); } int errorCode = -1; return(errorCode); }
// __ConsoleStream also uses this code. private int ReadFileNative(SafeFileHandle handle, byte[] bytes, int offset, int count, out int hr) { // Don't corrupt memory when multiple threads are erroneously writing // to this stream simultaneously. if (bytes.Length - offset < count) { throw new IndexOutOfRangeException("IORaceCondition"); } // You can't use the fixed statement on an array of length 0. if (bytes.Length == 0) { hr = 0; return(0); } int r = 0; int numBytesRead = 0; hr = 0; numBytesRead = handle.ReadFile(bytes, offset, count); return(numBytesRead); }
private static int ReadFileNative(SafeFileHandle hFile, byte[] bytes, int offset, int count, out int bytesRead) { if (bytes.Length - offset < count) throw new IndexOutOfRangeException("IORaceCondition"); // You can't use the fixed statement on an array of length 0. if (bytes.Length == 0) { bytesRead = 0; return ERROR_SUCCESS; } bool readSuccess; bytesRead = hFile.ReadFile(bytes, offset, count); readSuccess = (0 != bytesRead); if (readSuccess) return ERROR_SUCCESS; int errorCode = -1; return errorCode; }