source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: At least in theory, this patch lets us compile on Windows (which
@ 2011-05-26 20:36 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2011-05-26 20:36 UTC (permalink / raw)
  To: source

Log Message:
-----------
At least in theory, this patch lets us compile on Windows (which does
not have mmap(), from what I can tell).

Modified Files:
--------------
    mdocml:
        Makefile
        read.c

Added Files:
-----------
    mdocml:
        test-mmap.c

Revision Data
-------------
--- /dev/null
+++ 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;
+}
Index: Makefile
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v
retrieving revision 1.346
retrieving revision 1.347
diff -LMakefile -LMakefile -u -p -r1.346 -r1.347
--- Makefile
+++ 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 \
@@ -381,6 +382,10 @@ config.h: config.h.pre config.h.post
 	  if $(CC) $(CFLAGS) -Werror -o test-strlcat test-strlcat.c >> config.log 2>&1; then \
 		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'; \
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -Lread.c -Lread.c -u -p -r1.14 -r1.15
--- read.c
+++ read.c
@@ -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 *f
 
 	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
 		if (fb->buf != MAP_FAILED)
 			return(1);
 	}
+#endif
 
 	/*
 	 * If this isn't a regular file (like, say, stdin), then we must
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-26 20:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-26 20:36 mdocml: At least in theory, this patch lets us compile on Windows (which kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).