Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ReadFileNative()

static unsafe int System.ConsolePal.WindowsConsoleStream.ReadFileNative ( IntPtr hFile,
Span< byte > buffer,
bool isPipe,
out int bytesRead,
bool useFileAPIs )
inlinestaticprivate

Definition at line 74 of file ConsolePal.cs.

75 {
76 if (buffer.IsEmpty)
77 {
78 bytesRead = 0;
79 return 0;
80 }
81 bool flag;
82 fixed (byte* ptr = buffer)
83 {
84 if (useFileAPIs)
85 {
86 flag = global::Interop.Kernel32.ReadFile(hFile, ptr, buffer.Length, out bytesRead, IntPtr.Zero) != 0;
87 }
88 else
89 {
90 flag = global::Interop.Kernel32.ReadConsole(hFile, ptr, buffer.Length / 2, out var lpNumberOfCharsRead, IntPtr.Zero);
91 bytesRead = lpNumberOfCharsRead * 2;
92 }
93 }
94 if (flag)
95 {
96 return 0;
97 }
98 int lastPInvokeError = Marshal.GetLastPInvokeError();
99 if (lastPInvokeError == 232 || lastPInvokeError == 109)
100 {
101 return 0;
102 }
103 return lastPInvokeError;
104 }

References System.buffer, System.Runtime.InteropServices.Marshal.GetLastPInvokeError(), and System.IntPtr.Zero.

Referenced by System.ConsolePal.WindowsConsoleStream.Read().