From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id pBDBQD2W003188 for ; Tue, 13 Dec 2011 06:26:13 -0500 (EST) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.5/8.14.3/Submit) id pBDBQDje017087; Tue, 13 Dec 2011 06:26:13 -0500 (EST) Date: Tue, 13 Dec 2011 06:26:13 -0500 (EST) Message-Id: <201112131126.pBDBQDje017087@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Compatibility support fgetln() on Linux. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- 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. Modified Files: -------------- mdocml: Makefile config.h.post config.h.pre Added Files: ----------- mdocml: compat_fgetln.c test-fgetln.c Revision Data ------------- Index: config.h.pre =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/config.h.pre,v retrieving revision 1.1 retrieving revision 1.2 diff -Lconfig.h.pre -Lconfig.h.pre -u -p -r1.1 -r1.2 --- config.h.pre +++ config.h.pre @@ -4,3 +4,5 @@ #if defined(__linux__) || defined(__MINT__) # define _GNU_SOURCE /* strptime(), getsubopt() */ #endif + +#include --- /dev/null +++ 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 +#include +#include +#include + +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 Index: Makefile =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v retrieving revision 1.389 retrieving revision 1.390 diff -LMakefile -LMakefile -u -p -r1.389 -r1.390 --- Makefile +++ 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; \ Index: config.h.post =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/config.h.post,v retrieving revision 1.3 retrieving revision 1.4 diff -Lconfig.h.post -Lconfig.h.post -u -p -r1.3 -r1.4 --- config.h.post +++ config.h.post @@ -35,5 +35,8 @@ extern size_t strlcpy(char *, const ch 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 */ --- /dev/null +++ test-fgetln.c @@ -0,0 +1,11 @@ +#include +#include + +int +main(void) +{ + char *cp; + size_t sz; + cp = fgetln(stdin, &sz); + return 0; +} -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv