tree-walk: replace hard-coded constants with the_hash_algo
[git.git] / compat / mmap.c
blob7f662fef7bcb408045eb1536afed058a607ae97b
1 #include "../git-compat-util.h"
3 void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
5 size_t n = 0;
7 if (start != NULL || !(flags & MAP_PRIVATE))
8 die("Invalid usage of mmap when built with NO_MMAP");
10 start = xmalloc(length);
11 if (start == NULL) {
12 errno = ENOMEM;
13 return MAP_FAILED;
16 while (n < length) {
17 ssize_t count = xpread(fd, (char *)start + n, length - n, offset + n);
19 if (count == 0) {
20 memset((char *)start+n, 0, length-n);
21 break;
24 if (count < 0) {
25 free(start);
26 errno = EACCES;
27 return MAP_FAILED;
30 n += count;
33 return start;
36 int git_munmap(void *start, size_t length)
38 free(start);
39 return 0;