]> git.ipfire.org Git - thirdparty/git.git/blob - compat/mmap.c
Add to documentation of git-update-index arguments and usage.
[thirdparty/git.git] / compat / mmap.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <errno.h>
5 #include "../cache.h"
6
7 void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
8 {
9 int n = 0;
10
11 if (start != NULL || !(flags & MAP_PRIVATE))
12 die("Invalid usage of gitfakemmap.");
13
14 if (lseek(fd, offset, SEEK_SET) < 0) {
15 errno = EINVAL;
16 return MAP_FAILED;
17 }
18
19 start = xmalloc(length);
20 if (start == NULL) {
21 errno = ENOMEM;
22 return MAP_FAILED;
23 }
24
25 while (n < length) {
26 int count = read(fd, start+n, length-n);
27
28 if (count == 0) {
29 memset(start+n, 0, length-n);
30 break;
31 }
32
33 if (count < 0) {
34 free(start);
35 errno = EACCES;
36 return MAP_FAILED;
37 }
38
39 n += count;
40 }
41
42 return start;
43 }
44
45 int gitfakemunmap(void *start, size_t length)
46 {
47 free(start);
48 return 0;
49 }
50