Use mmap_data more widely

This commit is contained in:
topjohnwu
2021-11-30 01:50:55 -08:00
parent 2d82ad93dd
commit 1443a5b175
19 changed files with 168 additions and 276 deletions
+6 -12
View File
@@ -151,12 +151,9 @@ void cpio::dump(FILE *out) {
}
void cpio::load_cpio(const char *file) {
char *buf;
size_t sz;
mmap_ro(file, buf, sz);
fprintf(stderr, "Loading cpio: [%s]\n", file);
load_cpio(buf, sz);
munmap(buf, sz);
auto m = mmap_data(file);
load_cpio(reinterpret_cast<char *>(m.buf), m.sz);
}
void cpio::insert(string_view name, cpio_entry *e) {
@@ -169,14 +166,11 @@ void cpio::insert(string_view name, cpio_entry *e) {
}
void cpio::add(mode_t mode, const char *name, const char *file) {
void *buf;
size_t sz;
mmap_ro(file, buf, sz);
auto m = mmap_data(file);
auto e = new cpio_entry(S_IFREG | mode);
e->filesize = sz;
e->data = xmalloc(sz);
memcpy(e->data, buf, sz);
munmap(buf, sz);
e->filesize = m.sz;
e->data = xmalloc(m.sz);
memcpy(e->data, m.buf, m.sz);
insert(name, e);
fprintf(stderr, "Add entry [%s] (%04o)\n", name, mode);
}