aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-05-26 20:36:21 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-05-26 20:36:21 +0000
commitf241326688a1194c7487ac998177f9f7aa5ac406 (patch)
treebad4851b5e833543f26aa0d0004b3d5a62d135e6
parentdbf801977e01cd4d9bad6df7cfeacb641d962157 (diff)
downloadmandoc-f241326688a1194c7487ac998177f9f7aa5ac406.tar.gz
mandoc-f241326688a1194c7487ac998177f9f7aa5ac406.tar.zst
mandoc-f241326688a1194c7487ac998177f9f7aa5ac406.zip
At least in theory, this patch lets us compile on Windows (which does
not have mmap(), from what I can tell).
-rw-r--r--Makefile5
-rw-r--r--read.c14
-rw-r--r--test-mmap.c9
3 files changed, 24 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index e0b5203d..d9c824e1 100644
--- a/Makefile
+++ b/Makefile
@@ -108,6 +108,7 @@ SRCS = Makefile \
term.h \
term_ascii.c \
term_ps.c \
+ test-mmap.c \
test-strlcat.c \
test-strlcpy.c \
tree.c \
@@ -382,6 +383,10 @@ config.h: config.h.pre config.h.post
echo '#define HAVE_STRLCAT'; \
rm test-strlcat; \
fi; \
+ if $(CC) $(CFLAGS) -Werror -o test-mmap test-mmap.c >> config.log 2>&1; then \
+ echo '#define HAVE_MMAP'; \
+ rm test-mmap; \
+ fi; \
if $(CC) $(CFLAGS) -Werror -o test-strlcpy test-strlcpy.c >> config.log 2>&1; then \
echo '#define HAVE_STRLCPY'; \
rm test-strlcpy; \
diff --git a/read.c b/read.c
index 9a1d9f37..da273ae1 100644
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.14 2011/04/30 10:18:24 kristaps Exp $ */
+/* $Id: read.c,v 1.15 2011/05/26 20:36:21 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -19,8 +19,10 @@
#include "config.h"
#endif
-#include <sys/stat.h>
-#include <sys/mman.h>
+#ifdef HAVE_MMAP
+# include <sys/stat.h>
+# include <sys/mman.h>
+#endif
#include <assert.h>
#include <ctype.h>
@@ -529,19 +531,22 @@ pdesc(struct mparse *curp, const char *file, int fd)
mparse_buf_r(curp, blk, 1);
+#ifdef HAVE_MMAP
if (with_mmap)
munmap(blk.buf, blk.sz);
else
+#endif
free(blk.buf);
}
static int
read_whole_file(const char *file, int fd, struct buf *fb, int *with_mmap)
{
- struct stat st;
size_t off;
ssize_t ssz;
+#ifdef HAVE_MMAP
+ struct stat st;
if (-1 == fstat(fd, &st)) {
perror(file);
return(0);
@@ -566,6 +571,7 @@ read_whole_file(const char *file, int fd, struct buf *fb, int *with_mmap)
if (fb->buf != MAP_FAILED)
return(1);
}
+#endif
/*
* If this isn't a regular file (like, say, stdin), then we must
diff --git a/test-mmap.c b/test-mmap.c
new file mode 100644
index 00000000..87596e3f
--- /dev/null
+++ b/test-mmap.c
@@ -0,0 +1,9 @@
+#include <sys/mman.h>
+
+int
+main(int argc, char **argv)
+{
+
+ mmap(0, 0, PROT_READ, MAP_FILE|MAP_SHARED, -1, 0);
+ return 0;
+}