diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-12-27 19:48:52 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-12-27 19:48:52 -0800 |
| commit | 7d4bc36949cec8e5c791c352a264cd1dea4f8a1e (patch) | |
| tree | f2a873d8628beae17af524c2334c75b97a50beb0 /file_loader.c | |
| parent | 177bc55cfc405a7df0f666aa2dce29e428b9592c (diff) | |
Added in-place filtering/replacements
Diffstat (limited to 'file_loader.c')
| -rw-r--r-- | file_loader.c | 18 |
1 files changed, 18 insertions, 0 deletions
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) { |
