Merge branch 'main' into wip/net-n-btree

This commit is contained in:
Kae 2024-09-12 23:06:24 +10:00
commit 79d8ca62d3
2 changed files with 13 additions and 4 deletions

View File

@ -377,7 +377,12 @@ size_t File::pread(void* f, char* data, size_t len, StreamOffset position) {
HANDLE file = (HANDLE)f; HANDLE file = (HANDLE)f;
DWORD numRead = 0; DWORD numRead = 0;
OVERLAPPED overlapped = makeOverlapped(position); OVERLAPPED overlapped = makeOverlapped(position);
StreamOffset pos = ftell(f);
if (pos != 0) fseek(f, 0, IOSeek::Absolute);
int ret = ReadFile(file, data, len, &numRead, &overlapped); int ret = ReadFile(file, data, len, &numRead, &overlapped);
if (pos != 0) fseek(f, pos, IOSeek::Absolute);
if (ret == 0) { if (ret == 0) {
auto err = GetLastError(); auto err = GetLastError();
if (err != ERROR_IO_PENDING) if (err != ERROR_IO_PENDING)
@ -391,7 +396,12 @@ size_t File::pwrite(void* f, char const* data, size_t len, StreamOffset position
HANDLE file = (HANDLE)f; HANDLE file = (HANDLE)f;
DWORD numWritten = 0; DWORD numWritten = 0;
OVERLAPPED overlapped = makeOverlapped(position); OVERLAPPED overlapped = makeOverlapped(position);
StreamOffset pos = ftell(f);
if (pos != 0) fseek(f, 0, IOSeek::Absolute);
int ret = WriteFile(file, data, len, &numWritten, &overlapped); int ret = WriteFile(file, data, len, &numWritten, &overlapped);
if (pos != 0) fseek(f, pos, IOSeek::Absolute);
if (ret == 0) { if (ret == 0) {
auto err = GetLastError(); auto err = GetLastError();
if (err != ERROR_IO_PENDING) if (err != ERROR_IO_PENDING)

View File

@ -18,13 +18,12 @@ void readPngData(png_structp pngPtr, png_bytep data, png_size_t length) {
}; };
bool Image::isPng(IODevicePtr device) { bool Image::isPng(IODevicePtr device) {
png_byte header[8]; png_byte header[8]{};
device->readAbsolute(0, (char*)header, sizeof(header)); return !png_sig_cmp(header, 0, device->readAbsolute(0, (char*)header, sizeof(header)));
return !png_sig_cmp(header, 0, sizeof(header));
} }
Image Image::readPng(IODevicePtr device) { Image Image::readPng(IODevicePtr device) {
png_byte header[8]; png_byte header[8]{};
device->readFull((char*)header, sizeof(header)); device->readFull((char*)header, sizeof(header));
if (png_sig_cmp(header, 0, sizeof(header))) if (png_sig_cmp(header, 0, sizeof(header)))