Skip to content

Commit 5f3ccd6

Browse files
pks-tgitster
authored andcommitted
object-file: move xmmap() into "wrapper.c"
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e21581e commit 5f3ccd6

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

object-file.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -719,54 +719,6 @@ int has_loose_object(const struct object_id *oid)
719719
return check_and_freshen(oid, 0);
720720
}
721721

722-
static void mmap_limit_check(size_t length)
723-
{
724-
static size_t limit = 0;
725-
if (!limit) {
726-
limit = git_env_ulong("GIT_MMAP_LIMIT", 0);
727-
if (!limit)
728-
limit = SIZE_MAX;
729-
}
730-
if (length > limit)
731-
die(_("attempting to mmap %"PRIuMAX" over limit %"PRIuMAX),
732-
(uintmax_t)length, (uintmax_t)limit);
733-
}
734-
735-
void *xmmap_gently(void *start, size_t length,
736-
int prot, int flags, int fd, off_t offset)
737-
{
738-
void *ret;
739-
740-
mmap_limit_check(length);
741-
ret = mmap(start, length, prot, flags, fd, offset);
742-
if (ret == MAP_FAILED && !length)
743-
ret = NULL;
744-
return ret;
745-
}
746-
747-
const char *mmap_os_err(void)
748-
{
749-
static const char blank[] = "";
750-
#if defined(__linux__)
751-
if (errno == ENOMEM) {
752-
/* this continues an existing error message: */
753-
static const char enomem[] =
754-
", check sys.vm.max_map_count and/or RLIMIT_DATA";
755-
return enomem;
756-
}
757-
#endif /* OS-specific bits */
758-
return blank;
759-
}
760-
761-
void *xmmap(void *start, size_t length,
762-
int prot, int flags, int fd, off_t offset)
763-
{
764-
void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
765-
if (ret == MAP_FAILED)
766-
die_errno(_("mmap failed%s"), mmap_os_err());
767-
return ret;
768-
}
769-
770722
static int format_object_header_literally(char *str, size_t size,
771723
const char *type, size_t objsize)
772724
{

wrapper.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,3 +829,51 @@ uint32_t git_rand(unsigned flags)
829829

830830
return result;
831831
}
832+
833+
static void mmap_limit_check(size_t length)
834+
{
835+
static size_t limit = 0;
836+
if (!limit) {
837+
limit = git_env_ulong("GIT_MMAP_LIMIT", 0);
838+
if (!limit)
839+
limit = SIZE_MAX;
840+
}
841+
if (length > limit)
842+
die(_("attempting to mmap %"PRIuMAX" over limit %"PRIuMAX),
843+
(uintmax_t)length, (uintmax_t)limit);
844+
}
845+
846+
void *xmmap_gently(void *start, size_t length,
847+
int prot, int flags, int fd, off_t offset)
848+
{
849+
void *ret;
850+
851+
mmap_limit_check(length);
852+
ret = mmap(start, length, prot, flags, fd, offset);
853+
if (ret == MAP_FAILED && !length)
854+
ret = NULL;
855+
return ret;
856+
}
857+
858+
const char *mmap_os_err(void)
859+
{
860+
static const char blank[] = "";
861+
#if defined(__linux__)
862+
if (errno == ENOMEM) {
863+
/* this continues an existing error message: */
864+
static const char enomem[] =
865+
", check sys.vm.max_map_count and/or RLIMIT_DATA";
866+
return enomem;
867+
}
868+
#endif /* OS-specific bits */
869+
return blank;
870+
}
871+
872+
void *xmmap(void *start, size_t length,
873+
int prot, int flags, int fd, off_t offset)
874+
{
875+
void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
876+
if (ret == MAP_FAILED)
877+
die_errno(_("mmap failed%s"), mmap_os_err());
878+
return ret;
879+
}

0 commit comments

Comments
 (0)