From dcc0647eb662e3634c24ff549c27f0a1ef410a30 Mon Sep 17 00:00:00 2001 From: George Vinokhodov Date: Mon, 20 May 2024 16:59:55 +0300 Subject: [PATCH] Update mappedfile.c: fix large files support on Windows changed GetFileSize call to GetFileSizeEx to support files larger then 4 GB (2^32 bytes) --- mappedfile.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mappedfile.c b/mappedfile.c index 757b2ab..2a2a947 100644 --- a/mappedfile.c +++ b/mappedfile.c @@ -56,11 +56,14 @@ char *map_file(const char *path, size_t *length) if (hFile == INVALID_HANDLE_VALUE) return NULL; - size = GetFileSize(hFile, NULL); - if (size == INVALID_FILE_SIZE || size == 0) + if (!GetFileSizeEx(hFile, &size)) goto fail; - hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, size, NULL); + if (size == 0) + goto fail; + + hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, (DWORD) (size >> 32), (DWORD) size, NULL); + if (!hMap) goto fail;