]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file: move `xmmap()` into "wrapper.c"
authorPatrick Steinhardt <ps@pks.im>
Tue, 15 Apr 2025 09:38:17 +0000 (11:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Apr 2025 15:24:35 +0000 (08:24 -0700)
The `xmmap()` function is provided by "object-file.c" even though its
functionality has nothing to do with the object file subsystem. Move it
into "wrapper.c", whose header already declares those functions.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
wrapper.c

index c3e20417f3f71eeef8394f76728becf413818009..a7868201d09a85a2123a29ea21901e534b760352 100644 (file)
@@ -718,54 +718,6 @@ int has_loose_object(const struct object_id *oid)
        return check_and_freshen(oid, 0);
 }
 
-static void mmap_limit_check(size_t length)
-{
-       static size_t limit = 0;
-       if (!limit) {
-               limit = git_env_ulong("GIT_MMAP_LIMIT", 0);
-               if (!limit)
-                       limit = SIZE_MAX;
-       }
-       if (length > limit)
-               die(_("attempting to mmap %"PRIuMAX" over limit %"PRIuMAX),
-                   (uintmax_t)length, (uintmax_t)limit);
-}
-
-void *xmmap_gently(void *start, size_t length,
-                 int prot, int flags, int fd, off_t offset)
-{
-       void *ret;
-
-       mmap_limit_check(length);
-       ret = mmap(start, length, prot, flags, fd, offset);
-       if (ret == MAP_FAILED && !length)
-               ret = NULL;
-       return ret;
-}
-
-const char *mmap_os_err(void)
-{
-       static const char blank[] = "";
-#if defined(__linux__)
-       if (errno == ENOMEM) {
-               /* this continues an existing error message: */
-               static const char enomem[] =
-", check sys.vm.max_map_count and/or RLIMIT_DATA";
-               return enomem;
-       }
-#endif /* OS-specific bits */
-       return blank;
-}
-
-void *xmmap(void *start, size_t length,
-       int prot, int flags, int fd, off_t offset)
-{
-       void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
-       if (ret == MAP_FAILED)
-               die_errno(_("mmap failed%s"), mmap_os_err());
-       return ret;
-}
-
 static int format_object_header_literally(char *str, size_t size,
                                          const char *type, size_t objsize)
 {
index 8b985931490d62acb2030c147b8728b34917df8a..3c79778055eb9d5f7f30bd6ebcdca55069854899 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -829,3 +829,51 @@ uint32_t git_rand(unsigned flags)
 
        return result;
 }
+
+static void mmap_limit_check(size_t length)
+{
+       static size_t limit = 0;
+       if (!limit) {
+               limit = git_env_ulong("GIT_MMAP_LIMIT", 0);
+               if (!limit)
+                       limit = SIZE_MAX;
+       }
+       if (length > limit)
+               die(_("attempting to mmap %"PRIuMAX" over limit %"PRIuMAX),
+                   (uintmax_t)length, (uintmax_t)limit);
+}
+
+void *xmmap_gently(void *start, size_t length,
+                 int prot, int flags, int fd, off_t offset)
+{
+       void *ret;
+
+       mmap_limit_check(length);
+       ret = mmap(start, length, prot, flags, fd, offset);
+       if (ret == MAP_FAILED && !length)
+               ret = NULL;
+       return ret;
+}
+
+const char *mmap_os_err(void)
+{
+       static const char blank[] = "";
+#if defined(__linux__)
+       if (errno == ENOMEM) {
+               /* this continues an existing error message: */
+               static const char enomem[] =
+", check sys.vm.max_map_count and/or RLIMIT_DATA";
+               return enomem;
+       }
+#endif /* OS-specific bits */
+       return blank;
+}
+
+void *xmmap(void *start, size_t length,
+       int prot, int flags, int fd, off_t offset)
+{
+       void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
+       if (ret == MAP_FAILED)
+               die_errno(_("mmap failed%s"), mmap_os_err());
+       return ret;
+}