1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <errno.h>
5 #include "../git-compat-util.h"
7 void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
8 {
9 int n = 0;
11 if (start != NULL || !(flags & MAP_PRIVATE))
12 die("Invalid usage of gitfakemmap.");
14 if (lseek(fd, offset, SEEK_SET) < 0) {
15 errno = EINVAL;
16 return MAP_FAILED;
17 }
19 start = xmalloc(length);
20 if (start == NULL) {
21 errno = ENOMEM;
22 return MAP_FAILED;
23 }
25 while (n < length) {
26 int count = read(fd, start+n, length-n);
28 if (count == 0) {
29 memset(start+n, 0, length-n);
30 break;
31 }
33 if (count < 0) {
34 free(start);
35 errno = EACCES;
36 return MAP_FAILED;
37 }
39 n += count;
40 }
42 return start;
43 }
45 int gitfakemunmap(void *start, size_t length)
46 {
47 free(start);
48 return 0;
49 }