Subject: [PATCH] make fakemmap standalone to fix linking error because of gitfakemmap referencing die living in usage.c, and git.c not linking in the file. Instead of hardcoding usage.o in git.c prerequisites, I separated mmap. Signed-off-by: Alex Riesen --- cache.h | 18 +++--------------- compat/mmap.c | 11 +++++++---- compat/mmap.h | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 compat/mmap.h e1e24d29b684d468a7be5d097ba3e1679170e7db diff --git a/cache.h b/cache.h index f9b367f..c70a467 100644 --- a/cache.h +++ b/cache.h @@ -11,7 +11,9 @@ #include #include #include -#ifndef NO_MMAP +#ifdef NO_MMAP +#include "compat/mmap.h" +#else #include #endif #include @@ -373,20 +375,6 @@ extern void packed_object_info_detail(st /* Dumb servers support */ extern int update_server_info(int); -#ifdef NO_MMAP - -#ifndef PROT_READ -#define PROT_READ 1 -#define PROT_WRITE 2 -#define MAP_PRIVATE 1 -#define MAP_FAILED ((void*)-1) -#endif - -extern void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset); -extern int gitfakemunmap(void *start, size_t length); - -#endif - typedef int (*config_fn_t)(const char *, const char *); extern int git_default_config(const char *, const char *); extern int git_config_from_file(config_fn_t fn, const char *); diff --git a/compat/mmap.c b/compat/mmap.c index a051c47..98cf3cb 100644 --- a/compat/mmap.c +++ b/compat/mmap.c @@ -2,21 +2,24 @@ #include #include #include -#include "../cache.h" +#include +#include "mmap.h" void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset) { int n = 0; - if (start != NULL || !(flags & MAP_PRIVATE)) - die("Invalid usage of gitfakemmap."); + if (!start || !(flags & MAP_PRIVATE)) { + fprintf(stderr, "Invalid usage of gitfakemmap.\n"); + exit(128); /* see die() in ../usage.c */ + } if (lseek(fd, offset, SEEK_SET) < 0) { errno = EINVAL; return MAP_FAILED; } - start = xmalloc(length); + start = malloc(length); if (start == NULL) { errno = ENOMEM; return MAP_FAILED; diff --git a/compat/mmap.h b/compat/mmap.h new file mode 100644 index 0000000..08d7f99 --- /dev/null +++ b/compat/mmap.h @@ -0,0 +1,15 @@ +#ifndef MMAP_H +#define MMAP_H + +#ifndef PROT_READ +#define PROT_READ 1 +#define PROT_WRITE 2 +#define MAP_PRIVATE 1 +#define MAP_FAILED ((void*)-1) +#endif + +extern void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset); +extern int gitfakemunmap(void *start, size_t length); + +#endif + -- 0.99.9.GIT