diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2016-10-05 14:44:36 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2016-10-05 14:44:36 +0200 |
commit | b4a8090f75c90ec26133344b00a085025da212aa (patch) | |
tree | 9cc00368c48542853cf22621450009582b76ec51 /seq.c | |
parent | 0b2e4880f5c80a97a8c4577591210185669ddb4a (diff) | |
download | mblaze-b4a8090f75c90ec26133344b00a085025da212aa.tar.gz mblaze-b4a8090f75c90ec26133344b00a085025da212aa.tar.xz mblaze-b4a8090f75c90ec26133344b00a085025da212aa.zip |
seq: slurp the file instead of mmap
mmap is not robust when there are writes possible.
Diffstat (limited to 'seq.c')
-rw-r--r-- | seq.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/seq.c b/seq.c index 3cbf131..7b0b9ea 100644 --- a/seq.c +++ b/seq.c @@ -1,4 +1,3 @@ -#include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> @@ -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; |