about summary refs log tree commit diff
path: root/seq.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-10-05 14:44:36 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-10-05 14:44:36 +0200
commitb4a8090f75c90ec26133344b00a085025da212aa (patch)
tree9cc00368c48542853cf22621450009582b76ec51 /seq.c
parent0b2e4880f5c80a97a8c4577591210185669ddb4a (diff)
downloadmblaze-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.c16
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;