From b4a8090f75c90ec26133344b00a085025da212aa Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Wed, 5 Oct 2016 14:44:36 +0200 Subject: seq: slurp the file instead of mmap mmap is not robust when there are writes possible. --- seq.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'seq.c') diff --git a/seq.c b/seq.c index 3cbf131..7b0b9ea 100644 --- a/seq.c +++ b/seq.c @@ -1,4 +1,3 @@ -#include #include #include @@ -50,23 +49,14 @@ blaze822_home_file(char *basename) char * blaze822_seq_open(char *file) { - int fd; - struct stat st; - - // env $SEQ or something if (!file) file = getenv("MAILSEQ"); if (!file) file = blaze822_home_file("seq"); - fd = open(file, O_RDONLY); - if (!fd) - return 0; - - fstat(fd, &st); - char *map = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - close(fd); - if (map == MAP_FAILED) + char *map; + off_t len; + if (slurp(file, &map, &len) != 0) return 0; return map; -- cgit 1.4.1