mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 12:00:17 +02:00
Utils/File: add PRead(), PWrite() and Size()
Because PRead/PWrite don't have the same side effects on the file cursor between Linux and Windows (:/), make them all-or-nothing.
This commit is contained in:
1 parent
c1e9d19809
commit
efc5eaf9c7
2 files changed
+107
-7
No files matched your search
@@ -111,10 +111,16 @@ DLLEXPORT_FUNC(HANDLE, CreateFileW,
|
||||
DLLEXPORT_FUNC(WINBOOL, WriteFile,
|
||||
(HANDLE hFile, const void* lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)) {
|
||||
IO_STATUS_BLOCK IOSB;
|
||||
LARGE_INTEGER ByteOffset;
|
||||
PLARGE_INTEGER ByteOffsetPtr = nullptr;
|
||||
if (lpOverlapped) {
|
||||
UNIMPLEMENTED();
|
||||
if (lpOverlapped->hEvent) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
ByteOffset.QuadPart = (static_cast<LONGLONG>(lpOverlapped->OffsetHigh) << 32) | lpOverlapped->Offset;
|
||||
ByteOffsetPtr = &ByteOffset;
|
||||
}
|
||||
NTSTATUS Status = NtWriteFile(hFile, nullptr, nullptr, nullptr, &IOSB, lpBuffer, nNumberOfBytesToWrite, nullptr, nullptr);
|
||||
NTSTATUS Status = NtWriteFile(hFile, nullptr, nullptr, nullptr, &IOSB, lpBuffer, nNumberOfBytesToWrite, ByteOffsetPtr, nullptr);
|
||||
if (lpNumberOfBytesWritten) {
|
||||
*lpNumberOfBytesWritten = static_cast<DWORD>(IOSB.Information);
|
||||
}
|
||||
@@ -135,6 +141,18 @@ DLLEXPORT_FUNC(WINBOOL, WriteConsoleW,
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
DLLEXPORT_FUNC(WINBOOL, GetFileSizeEx, (HANDLE hFile, PLARGE_INTEGER lpFileSize)) {
|
||||
IO_STATUS_BLOCK IOSB;
|
||||
FILE_STANDARD_INFORMATION StandardInfo;
|
||||
if (NTSTATUS Status = NtQueryInformationFile(hFile, &IOSB, &StandardInfo, sizeof(StandardInfo), FileStandardInformation); Status) {
|
||||
return WinAPIReturn(Status);
|
||||
}
|
||||
if (lpFileSize) {
|
||||
*lpFileSize = StandardInfo.EndOfFile;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DLLEXPORT_FUNC(WINBOOL, SetFilePointerEx, (HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)) {
|
||||
IO_STATUS_BLOCK IOSB;
|
||||
FILE_POSITION_INFORMATION PositionInfo;
|
||||
@@ -173,10 +191,17 @@ DLLEXPORT_FUNC(WINBOOL, SetFilePointerEx, (HANDLE hFile, LARGE_INTEGER liDistanc
|
||||
DLLEXPORT_FUNC(WINBOOL, ReadFile,
|
||||
(HANDLE hFile, void* lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)) {
|
||||
IO_STATUS_BLOCK IOSB;
|
||||
LARGE_INTEGER ByteOffset;
|
||||
PLARGE_INTEGER ByteOffsetPtr = nullptr;
|
||||
if (lpOverlapped) {
|
||||
UNIMPLEMENTED();
|
||||
if (lpOverlapped->hEvent) {
|
||||
// no actual async-overlapped, just enough for PRead
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
ByteOffset.QuadPart = (static_cast<LONGLONG>(lpOverlapped->OffsetHigh) << 32) | lpOverlapped->Offset;
|
||||
ByteOffsetPtr = &ByteOffset;
|
||||
}
|
||||
NTSTATUS Status = NtReadFile(hFile, nullptr, nullptr, nullptr, &IOSB, lpBuffer, nNumberOfBytesToRead, nullptr, nullptr);
|
||||
NTSTATUS Status = NtReadFile(hFile, nullptr, nullptr, nullptr, &IOSB, lpBuffer, nNumberOfBytesToRead, ByteOffsetPtr, nullptr);
|
||||
if (lpNumberOfBytesRead) {
|
||||
*lpNumberOfBytesRead = static_cast<DWORD>(IOSB.Information);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user