git/list[1] front-page[2] threads[3] people[4] search[5] about
 

make gitfakemmap standalone to fix linking error in git.c

From
Alex Riesen <raa.lkml@gmail.com>
Date
Dec 5, 2005, 13:19 UTC
Message-ID
<81b0412b0512050519k5ed80035x9eb4907f569e0a4b@mail.gmail.com>

The patch is 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 from the main sources.

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 <fork0@gmail.com>
---
 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 <string.h>
 #include <errno.h>
 #include <limits.h>
-#ifndef NO_MMAP
+#ifdef NO_MMAP
+#include "compat/mmap.h"
+#else
 #include <sys/mman.h>
 #endif
 #include <sys/param.h>
@@ -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 <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
-#include "../cache.h"
+#include <string.h>
+#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
Next: Alex Riesen
Message 1 of 23 in “make gitfakemmap standalone to fix linking error in git.c”
  1. Alex RiesenDec 5, 2005
  2. Alex RiesenDec 5, 2005
  3. Petr BaudisDec 5, 2005
  4. Alex RiesenDec 5, 2005
  5. Junio C HamanoDec 5, 2005
  6. Clean up compatibility definitions.Junio C Hamano, Dec 5, 2005
  7. Johannes SchindelinDec 5, 2005
  8. Junio C HamanoDec 5, 2005
  9. Alex RiesenDec 5, 2005
  10. Alex RiesenDec 6, 2005
  11. Junio C HamanoDec 6, 2005
  12. Alex RiesenDec 5, 2005
  13. Junio C HamanoDec 5, 2005
  14. Alex RiesenDec 6, 2005
  15. Junio C HamanoDec 6, 2005
  16. Alex RiesenDec 6, 2005
  17. Junio C HamanoDec 6, 2005
  18. Petr BaudisDec 5, 2005
  19. Junio C HamanoDec 6, 2005
  20. Petr BaudisDec 6, 2005
  21. Alex RiesenDec 5, 2005
  22. Junio C HamanoDec 5, 2005
  23. Alex RiesenDec 6, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.