diff options
| author | Patrick Steinhardt <ps@pks.im> | 2026-04-02 09:31:18 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-04-02 10:45:44 -0700 |
| commit | 87e4eee3f94ec261a92a76d06261b227b00de461 (patch) | |
| tree | 4e2baee0836ac16f4813ba107630a785683b3d55 /reftable/system.c | |
| parent | cb0882de1979522b2fc3dc4c3064b0ad21d50b06 (diff) | |
| download | git-87e4eee3f94ec261a92a76d06261b227b00de461.tar.xz | |
reftable/system: add abstraction to mmap files
In our codebase we have a couple of wrappers around mmap(3p) that allow
us to reimplement the syscall on platforms that don't have it natively,
like for example Windows. Other projects that embed the reftable library
may have a different infra though to hook up mmap wrappers, but these
are currently hard to integrate.
Provide the infrastructure to let projects easily define the mmap
interface with a custom struct and custom functions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/system.c')
| -rw-r--r-- | reftable/system.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/reftable/system.c b/reftable/system.c index cd76e56be8..9063641f30 100644 --- a/reftable/system.c +++ b/reftable/system.c @@ -143,3 +143,23 @@ uint64_t reftable_time_ms(void) { return getnanotime() / 1000000; } + +int reftable_mmap(struct reftable_mmap *out, int fd, size_t len) +{ + void *data = xmmap_gently(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); + if (data == MAP_FAILED) + return REFTABLE_IO_ERROR; + + out->data = data; + out->size = len; + + return 0; +} + +int reftable_munmap(struct reftable_mmap *mmap) +{ + if (munmap(mmap->data, mmap->size) < 0) + return REFTABLE_IO_ERROR; + memset(mmap, 0, sizeof(*mmap)); + return 0; +} |
