mirror of
https://github.com/git/git.git
synced 2024-11-06 17:23:00 +01:00
85023577a8
This is a mechanical clean-up of the way *.c files include system header files. (1) sources under compat/, platform sha-1 implementations, and xdelta code are exempt from the following rules; (2) the first #include must be "git-compat-util.h" or one of our own header file that includes it first (e.g. config.h, builtin.h, pkt-line.h); (3) system headers that are included in "git-compat-util.h" need not be included in individual C source files. (4) "git-compat-util.h" does not have to include subsystem specific header files (e.g. expat.h). Signed-off-by: Junio C Hamano <junkio@cox.net>
52 lines
879 B
C
52 lines
879 B
C
#include "../git-compat-util.h"
|
|
|
|
void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
|
|
{
|
|
int n = 0;
|
|
off_t current_offset = lseek(fd, 0, SEEK_CUR);
|
|
|
|
if (start != NULL || !(flags & MAP_PRIVATE))
|
|
die("Invalid usage of gitfakemmap.");
|
|
|
|
if (lseek(fd, offset, SEEK_SET) < 0) {
|
|
errno = EINVAL;
|
|
return MAP_FAILED;
|
|
}
|
|
|
|
start = xmalloc(length);
|
|
if (start == NULL) {
|
|
errno = ENOMEM;
|
|
return MAP_FAILED;
|
|
}
|
|
|
|
while (n < length) {
|
|
int count = read(fd, start+n, length-n);
|
|
|
|
if (count == 0) {
|
|
memset(start+n, 0, length-n);
|
|
break;
|
|
}
|
|
|
|
if (count < 0) {
|
|
free(start);
|
|
errno = EACCES;
|
|
return MAP_FAILED;
|
|
}
|
|
|
|
n += count;
|
|
}
|
|
|
|
if (current_offset != lseek(fd, current_offset, SEEK_SET)) {
|
|
errno = EINVAL;
|
|
return MAP_FAILED;
|
|
}
|
|
|
|
return start;
|
|
}
|
|
|
|
int gitfakemunmap(void *start, size_t length)
|
|
{
|
|
free(start);
|
|
return 0;
|
|
}
|
|
|