mirror of
https://github.com/NoelFB/blah.git
synced 2024-12-01 17:38:57 +08:00
fixing win32 file operations for 64 bit integers
This commit is contained in:
parent
3b4f721b64
commit
1376ef874b
|
@ -69,7 +69,7 @@ bool PlatformBackend::init(const Config* config)
|
||||||
wc.lpszClassName = "BLAH WINDOW";
|
wc.lpszClassName = "BLAH WINDOW";
|
||||||
wc.hInstance = hInstance;
|
wc.hInstance = hInstance;
|
||||||
wc.lpfnWndProc = blah_window_procedure;
|
wc.lpfnWndProc = blah_window_procedure;
|
||||||
wc.hCursor = NULL;
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||||
wc.hIcon = NULL;
|
wc.hIcon = NULL;
|
||||||
wc.lpszMenuName = NULL;
|
wc.lpszMenuName = NULL;
|
||||||
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
|
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
|
||||||
|
@ -523,31 +523,74 @@ i64 PlatformBackend::file_length(PlatformBackend::FileHandle handle)
|
||||||
|
|
||||||
i64 PlatformBackend::file_position(PlatformBackend::FileHandle handle)
|
i64 PlatformBackend::file_position(PlatformBackend::FileHandle handle)
|
||||||
{
|
{
|
||||||
// Todo: handle 64-bit values properly
|
LARGE_INTEGER move;
|
||||||
// Todo: cache this value? not sure how performant it is
|
LARGE_INTEGER result;
|
||||||
return SetFilePointer(handle, 0, NULL, FILE_CURRENT);
|
|
||||||
|
move.QuadPart = 0;
|
||||||
|
result.QuadPart = 0;
|
||||||
|
|
||||||
|
SetFilePointerEx(handle, move, &result, FILE_CURRENT);
|
||||||
|
|
||||||
|
return result.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 PlatformBackend::file_seek(PlatformBackend::FileHandle handle, i64 seek_to)
|
i64 PlatformBackend::file_seek(PlatformBackend::FileHandle handle, i64 seek_to)
|
||||||
{
|
{
|
||||||
// Todo: handle 64-bit values properly
|
LARGE_INTEGER move;
|
||||||
return SetFilePointer(handle, seek_to, NULL, FILE_BEGIN);
|
LARGE_INTEGER result;
|
||||||
|
|
||||||
|
move.QuadPart = seek_to;
|
||||||
|
result.QuadPart = 0;
|
||||||
|
|
||||||
|
SetFilePointerEx(handle, move, &result, FILE_BEGIN);
|
||||||
|
|
||||||
|
return result.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 PlatformBackend::file_read(PlatformBackend::FileHandle handle, void* ptr, i64 length)
|
i64 PlatformBackend::file_read(PlatformBackend::FileHandle handle, void* ptr, i64 length)
|
||||||
{
|
{
|
||||||
DWORD read = 0;
|
static const DWORD read_step = 65536;
|
||||||
if (ReadFile(handle, ptr, length, &read, NULL))
|
|
||||||
|
i64 read = 0;
|
||||||
|
|
||||||
|
while (read < length)
|
||||||
|
{
|
||||||
|
DWORD to_read = read_step;
|
||||||
|
if (to_read > length - read)
|
||||||
|
to_read = (DWORD)(length - read);
|
||||||
|
|
||||||
|
DWORD moved = 0;
|
||||||
|
if (ReadFile(handle, (unsigned char*)ptr + read, to_read, &moved, NULL))
|
||||||
|
read += moved;
|
||||||
|
|
||||||
|
if (moved < to_read)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return read;
|
return read;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 PlatformBackend::file_write(PlatformBackend::FileHandle handle, const void* ptr, i64 length)
|
i64 PlatformBackend::file_write(PlatformBackend::FileHandle handle, const void* ptr, i64 length)
|
||||||
{
|
{
|
||||||
DWORD written = 0;
|
static const DWORD write_step = 65536;
|
||||||
if (WriteFile(handle, ptr, length, &written, NULL))
|
|
||||||
|
i64 written = 0;
|
||||||
|
|
||||||
|
while (written < length)
|
||||||
|
{
|
||||||
|
DWORD to_write = write_step;
|
||||||
|
if (to_write > length - written)
|
||||||
|
to_write = (DWORD)(length - written);
|
||||||
|
|
||||||
|
DWORD moved = 0;
|
||||||
|
if (WriteFile(handle, (unsigned char*)ptr + written, to_write, &moved, NULL))
|
||||||
|
written += moved;
|
||||||
|
|
||||||
|
if (moved < to_write)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return written;
|
return written;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformBackend::file_close(PlatformBackend::FileHandle handle)
|
void PlatformBackend::file_close(PlatformBackend::FileHandle handle)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user