aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-12-13 11:26:12 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-12-13 11:26:12 +0000
commit814b41ea4b9a164160af761e33b09e8f7efaafa3 (patch)
treef83b1c37fb9c42a7434dc48d93e1ec0cba8a9b05
parent6ca7be8f333b28c465a7b7d961bddcb31d59d72f (diff)
downloadmandoc-814b41ea4b9a164160af761e33b09e8f7efaafa3.tar.gz
mandoc-814b41ea4b9a164160af761e33b09e8f7efaafa3.tar.zst
mandoc-814b41ea4b9a164160af761e33b09e8f7efaafa3.zip
Compatibility support fgetln() on Linux. This uses the BSD-licensed
implementation from NetBSD tnftpd, Christos Zoulas (copyright message retained in the compat_fgetln.c file). Patch verified by schwarze@. He notes that you'll need -pthread for -static binaries (due to libdb), so I've noted that -static should really only be used for BSD UNIX. While here, add some forgotten goop to the Makefile, building and cleaning extra manpages.
-rw-r--r--Makefile27
-rw-r--r--compat_fgetln.c89
-rw-r--r--config.h.post3
-rw-r--r--config.h.pre2
-rw-r--r--test-fgetln.c11
5 files changed, 129 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 589333e1..a8a92a68 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,9 @@ CFLAGS += -DUSE_WCHAR
# variable.
#CFLAGS += -DUSE_MANPATH
-# If your system supports static binaries only, uncomment this.
+# If your system supports static binaries only, uncomment this. This
+# appears only to be BSD UNIX systems (Mac OS X has no support and Linux
+# requires -pthreads for static libdb).
STATIC = -static
CFLAGS += -g -DHAVE_CONFIG_H -DVERSION="\"$(VERSION)\""
@@ -76,6 +78,7 @@ SRCS = Makefile \
cgi.c \
chars.c \
chars.in \
+ compat_fgetln.c \
compat_getsubopt.c \
compat_strlcat.c \
compat_strlcpy.c \
@@ -156,6 +159,7 @@ SRCS = Makefile \
term.h \
term_ascii.c \
term_ps.c \
+ test-fgetln.c \
test-getsubopt.c \
test-mmap.c \
test-strlcat.c \
@@ -224,10 +228,12 @@ LIBMANDOC_LNS = $(LIBMAN_LNS) \
msec.ln \
read.ln
-COMPAT_OBJS = compat_getsubopt.o \
+COMPAT_OBJS = compat_fgetln.o \
+ compat_getsubopt.o \
compat_strlcat.o \
compat_strlcpy.o
-COMPAT_LNS = compat_getsubopt.ln \
+COMPAT_LNS = compat_fgetln.ln \
+ compat_getsubopt.ln \
compat_strlcat.ln \
compat_strlcpy.ln
@@ -343,6 +349,11 @@ INDEX_MANS = apropos.1.html \
apropos.1.ps \
apropos.1.pdf \
apropos.1.txt \
+ catman.8.html \
+ catman.8.xhtml \
+ catman.8.ps \
+ catman.8.pdf \
+ catman.8.txt \
demandoc.1.html \
demandoc.1.xhtml \
demandoc.1.ps \
@@ -373,6 +384,11 @@ INDEX_MANS = apropos.1.html \
man.7.ps \
man.7.pdf \
man.7.txt \
+ man.cgi.7.html \
+ man.cgi.7.xhtml \
+ man.cgi.7.ps \
+ man.cgi.7.pdf \
+ man.cgi.7.txt \
mandoc_char.7.html \
mandoc_char.7.xhtml \
mandoc_char.7.ps \
@@ -437,6 +453,7 @@ clean:
rm -f config.h config.log $(COMPAT_OBJS) $(COMPAT_LNS)
rm -f mdocml.tar.gz mdocml-win32.zip mdocml-win64.zip mdocml-macosx.zip
rm -f index.html $(INDEX_OBJS)
+ rm -rf test-fgetln.DSYM
rm -rf test-strlcpy.DSYM
rm -rf test-strlcat.DSYM
rm -rf test-strptime.DSYM
@@ -575,6 +592,10 @@ config.h: config.h.pre config.h.post
rm -f config.log
( cat config.h.pre; \
echo; \
+ if $(CC) $(CFLAGS) -Werror -o test-fgetln test-fgetln.c >> config.log 2>&1; then \
+ echo '#define HAVE_FGETLN'; \
+ rm test-fgetln; \
+ fi; \
if $(CC) $(CFLAGS) -Werror -o test-strptime test-strptime.c >> config.log 2>&1; then \
echo '#define HAVE_STRPTIME'; \
rm test-strptime; \
diff --git a/compat_fgetln.c b/compat_fgetln.c
new file mode 100644
index 00000000..236e3830
--- /dev/null
+++ b/compat_fgetln.c
@@ -0,0 +1,89 @@
+#ifdef HAVE_FGETLN
+
+int dummy;
+
+#else
+
+/* $NetBSD: fgetln.c,v 1.3 2006/09/25 07:18:17 lukem Exp $ */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+fgetln(fp, len)
+ FILE *fp;
+ size_t *len;
+{
+ static char *buf = NULL;
+ static size_t bufsiz = 0;
+ char *ptr;
+
+
+ if (buf == NULL) {
+ bufsiz = BUFSIZ;
+ if ((buf = malloc(bufsiz)) == NULL)
+ return NULL;
+ }
+
+ if (fgets(buf, bufsiz, fp) == NULL)
+ return NULL;
+
+ *len = 0;
+ while ((ptr = strchr(&buf[*len], '\n')) == NULL) {
+ size_t nbufsiz = bufsiz + BUFSIZ;
+ char *nbuf = realloc(buf, nbufsiz);
+
+ if (nbuf == NULL) {
+ int oerrno = errno;
+ free(buf);
+ errno = oerrno;
+ buf = NULL;
+ return NULL;
+ } else
+ buf = nbuf;
+
+ *len = bufsiz;
+ if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL)
+ return buf;
+
+ bufsiz = nbufsiz;
+ }
+
+ *len = (ptr - buf) + 1;
+ return buf;
+}
+
+#endif
diff --git a/config.h.post b/config.h.post
index 62ce4ea6..39da2b2f 100644
--- a/config.h.post
+++ b/config.h.post
@@ -35,5 +35,8 @@ extern size_t strlcpy(char *, const char *, size_t);
extern int getsubopt(char **, char * const *, char **);
extern char *suboptarg;
#endif
+#ifndef HAVE_FGETLN
+extern char *fgetln(FILE *, size_t *);
+#endif
#endif /* MANDOC_CONFIG_H */
diff --git a/config.h.pre b/config.h.pre
index a309ed95..bc594784 100644
--- a/config.h.pre
+++ b/config.h.pre
@@ -4,3 +4,5 @@
#if defined(__linux__) || defined(__MINT__)
# define _GNU_SOURCE /* strptime(), getsubopt() */
#endif
+
+#include <stdio.h>
diff --git a/test-fgetln.c b/test-fgetln.c
new file mode 100644
index 00000000..90869cd8
--- /dev/null
+++ b/test-fgetln.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(void)
+{
+ char *cp;
+ size_t sz;
+ cp = fgetln(stdin, &sz);
+ return 0;
+}