aboutsummaryrefslogtreecommitdiff
path: root/reftable/blocksource.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-04-08 10:19:17 -0700
committerJunio C Hamano <gitster@pobox.com>2026-04-08 10:19:17 -0700
commit4fee6ff3b23321b55073ca2d13c4e2aa6adaea65 (patch)
tree097114e50b0fea8c224986e29d070b99a7904370 /reftable/blocksource.c
parent0c0cbd8ab7c8e1884d6f0bdf1f36f5f9d4732553 (diff)
parent87e4eee3f94ec261a92a76d06261b227b00de461 (diff)
downloadgit-4fee6ff3b23321b55073ca2d13c4e2aa6adaea65.tar.xz
Merge branch 'ps/reftable-portability'
Update reftable library part with what is used in libgit2 to improve portability to different target codebases and platforms. * ps/reftable-portability: reftable/system: add abstraction to mmap files reftable/system: add abstraction to retrieve time in milliseconds reftable/fsck: use REFTABLE_UNUSED instead of UNUSED reftable/stack: provide fsync(3p) via system header reftable: introduce "reftable-system.h" header
Diffstat (limited to 'reftable/blocksource.c')
-rw-r--r--reftable/blocksource.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/reftable/blocksource.c b/reftable/blocksource.c
index 573c81287f..7f7441f751 100644
--- a/reftable/blocksource.c
+++ b/reftable/blocksource.c
@@ -93,13 +93,12 @@ void block_source_from_buf(struct reftable_block_source *bs,
}
struct file_block_source {
- uint64_t size;
- unsigned char *data;
+ struct reftable_mmap mmap;
};
static uint64_t file_size(void *b)
{
- return ((struct file_block_source *)b)->size;
+ return ((struct file_block_source *)b)->mmap.size;
}
static void file_release_data(void *b REFTABLE_UNUSED, struct reftable_block_data *dest REFTABLE_UNUSED)
@@ -109,7 +108,7 @@ static void file_release_data(void *b REFTABLE_UNUSED, struct reftable_block_dat
static void file_close(void *v)
{
struct file_block_source *b = v;
- munmap(b->data, b->size);
+ reftable_munmap(&b->mmap);
reftable_free(b);
}
@@ -117,8 +116,8 @@ static ssize_t file_read_data(void *v, struct reftable_block_data *dest, uint64_
uint32_t size)
{
struct file_block_source *b = v;
- assert(off + size <= b->size);
- dest->data = b->data + off;
+ assert(off + size <= b->mmap.size);
+ dest->data = (unsigned char *) b->mmap.data + off;
dest->len = size;
return size;
}
@@ -156,13 +155,9 @@ int reftable_block_source_from_file(struct reftable_block_source *bs,
goto out;
}
- p->size = st.st_size;
- p->data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (p->data == MAP_FAILED) {
- err = REFTABLE_IO_ERROR;
- p->data = NULL;
+ err = reftable_mmap(&p->mmap, fd, st.st_size);
+ if (err < 0)
goto out;
- }
assert(!bs->ops);
bs->ops = &file_vtable;