aboutsummaryrefslogtreecommitdiff
path: root/text.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2018-05-22 16:25:23 +0200
committerMarc André Tanner <mat@brain-dump.org>2018-05-30 16:27:45 +0200
commitd9b8f7bda83e746617ce1001972ba255ffdebed7 (patch)
treea900fb814bdba7b3932e77a814856ca78978541c /text.c
parentcbe37e6133109e2459df44a09f9d7006b5c1a60d (diff)
downloadvis-d9b8f7bda83e746617ce1001972ba255ffdebed7.tar.gz
vis-d9b8f7bda83e746617ce1001972ba255ffdebed7.tar.xz
text: allow to specify how the file content should be loaded
Diffstat (limited to 'text.c')
-rw-r--r--text.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/text.c b/text.c
index 5d5f814..548805b 100644
--- a/text.c
+++ b/text.c
@@ -1120,9 +1120,11 @@ ssize_t text_write_range(Text *txt, Filerange *range, int fd) {
return size - rem;
}
-/* load the given file as starting point for further editing operations.
- * to start with an empty document, pass NULL as filename. */
Text *text_load(const char *filename) {
+ return text_load_method(filename, TEXT_LOAD_AUTO);
+}
+
+Text *text_load_method(const char *filename, enum TextLoadMethod method) {
int fd = -1;
size_t size = 0;
Text *txt = calloc(1, sizeof *txt);
@@ -1144,7 +1146,7 @@ Text *text_load(const char *filename) {
// XXX: use lseek(fd, 0, SEEK_END); instead?
size = txt->info.st_size;
if (size > 0) {
- if (size < BLOCK_MMAP_SIZE)
+ if (method == TEXT_LOAD_READ || (method == TEXT_LOAD_AUTO && size < BLOCK_MMAP_SIZE))
txt->block = block_read(txt, size, fd);
else
txt->block = block_mmap(txt, size, fd, 0);