gitweb: Fix thinko in git_tags and git_heads
[git/gitweb.git] / compat / mmap.c
blob55cb120764da5520da7dbd91193a285551eae8bb
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)
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;
19 start = xmalloc(length);
20 if (start == NULL) {
21 errno = ENOMEM;
22 return MAP_FAILED;
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;
33 if (count < 0) {
34 free(start);
35 errno = EACCES;
36 return MAP_FAILED;
39 n += count;
42 return start;
45 int gitfakemunmap(void *start, size_t length)
47 free(start);
48 return 0;