Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/compat/mmap.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / compat / mmap.c` 45 lines ยท 773 bytes Raw Blame History 1 #include "../git-compat-util.h" 2 3 void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) 4 { 5 size_t n = 0; 6 7 if (start != NULL || flags != MAP_PRIVATE || prot != PROT_READ) 8 die("Invalid usage of mmap when built with NO_MMAP"); 9 10 if (length == 0) { 11 errno = EINVAL; 12 return MAP_FAILED; 13 } 14 15 start = malloc(length); 16 if (!start) { 17 errno = ENOMEM; 18 return MAP_FAILED; 19 } 20 21 while (n < length) { 22 ssize_t count = xpread(fd, (char *)start + n, length - n, offset + n); 23 24 if (count == 0) { 25 memset((char *)start+n, 0, length-n); 26 break; 27 } 28 29 if (count < 0) { 30 free(start); 31 errno = EACCES; 32 return MAP_FAILED; 33 } 34 35 n += count; 36 } 37 38 return start; 39 } 40 41 int git_munmap(void *start, size_t length UNUSED) 42 { 43 free(start); 44 return 0; 45 }