From 7d4bc36949cec8e5c791c352a264cd1dea4f8a1e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 27 Dec 2020 19:48:52 -0800 Subject: Added in-place filtering/replacements --- file_loader.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'file_loader.c') diff --git a/file_loader.c b/file_loader.c index 72cea72..1f61953 100644 --- a/file_loader.c +++ b/file_loader.c @@ -89,6 +89,24 @@ file_t *spoof_file(const char *filename, char *text) return f; } +/* + * Ensure that the file's contents are held in memory, rather than being memory + * mapped IO. + */ +void intern_file(file_t *f) +{ + if (!f->mmapped) return; + size_t size = (size_t)(f->end - f->contents); + char *buf = xcalloc(sizeof(char), size + 1); + memcpy(buf, f->contents, size); + munmap(f->contents, size); + f->contents = buf; + f->end = buf + size; + f->mmapped = 0; + free(f->lines); + populate_lines(f); +} + void destroy_file(file_t **f) { if ((*f)->filename) { -- cgit v1.2.3