Seek back to current filepos when mmap()ing with NO_MMAP
"git-index-pack --fix-thin" relies on mmap() not changing the current file position (otherwise the pack will be corrupted when writing the final SHA1). Meet that expectation. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Nov 15, 2006 at 17:27 UTC
0a3881d4cfee5c4ee3991a1b14a10333355958f1
1 file changed
+6
compat/mmap.c
+6
@@ -7,6 +7,7 @@
7
void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
8
{
9
int n = 0;
10
+ off_t current_offset = lseek(fd, 0, SEEK_CUR);
11
12
if (start != NULL || !(flags & MAP_PRIVATE))
13
die("Invalid usage of gitfakemmap.");
@@ -39,6 +40,11 @@ void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_
40
n += count;
41
}
42
43
+ if (current_offset != lseek(fd, current_offset, SEEK_SET)) {
44
+ errno = EINVAL;
45
+ return MAP_FAILED;
46
+ }
47
+
48
return start;
49
}
50