Skip to content

Commit 95069b3

Browse files
committed
win32mmap: set errno appropriately
It is not really helpful when a `git fetch` fails with the message: fatal: mmap failed: No error In the particular instance encountered by a colleague of yours truly, the Win32 error code was ERROR_COMMITMENT_LIMIT which means that the page file is not big enough. Let's make the message fatal: mmap failed: File too large instead, which is only marginally better, but which can be associated with the appropriate work-around: setting `core.packedGitWindowSize` to a relatively small value. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 1f524e1 commit 95069b3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compat/win32mmap.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
2424
hmap = CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL,
2525
PAGE_WRITECOPY, 0, 0, NULL);
2626

27-
if (!hmap)
27+
if (!hmap) {
28+
errno = EINVAL;
2829
return MAP_FAILED;
30+
}
2931

3032
temp = MapViewOfFileEx(hmap, FILE_MAP_COPY, h, l, length, start);
3133

3234
if (!CloseHandle(hmap))
3335
warning("unable to close file mapping handle");
3436

35-
return temp ? temp : MAP_FAILED;
37+
if (temp)
38+
return temp;
39+
40+
errno = GetLastError() == ERROR_COMMITMENT_LIMIT ? EFBIG : EINVAL;
41+
return MAP_FAILED;
3642
}
3743

3844
int git_munmap(void *start, size_t length)

0 commit comments

Comments
 (0)