From 0b4d810b066318b221f809c925ff625334452a7b Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Fri, 31 Aug 2007 11:37:40 +0200 Subject: [PATCH] Update gnulib files. --- gl/Makefile.am | 9 +++++++-- gl/getdelim.c | 15 +++++++++++---- gl/getdelim.h | 28 --------------------------- gl/getline.c | 5 ++--- gl/getline.h | 28 --------------------------- gl/getpass.c | 2 -- {lib/gl => gl}/m4/getdelim.m4 | 15 ++++++++++----- gl/m4/getline.m4 | 24 ++++++++++++----------- gl/m4/gnulib-comp.m4 | 4 ++-- gl/m4/stdio_h.m4 | 5 +++++ gl/readline.c | 3 +-- gl/stdio_.h | 45 +++++++++++++++++++++++++++++++++++++++++-- lib/gl/Makefile.am | 9 +++++++-- lib/gl/getdelim.c | 15 +++++++++++---- lib/gl/getdelim.h | 28 --------------------------- lib/gl/getline.c | 5 ++--- lib/gl/getline.h | 28 --------------------------- lib/gl/m4/getdelim.m4 | 15 ++++++++++----- lib/gl/m4/getline.m4 | 24 ++++++++++++----------- lib/gl/m4/gnulib-comp.m4 | 4 ++-- lib/gl/m4/stdio_h.m4 | 5 +++++ lib/gl/stdio_.h | 45 +++++++++++++++++++++++++++++++++++++++++-- 22 files changed, 187 insertions(+), 174 deletions(-) delete mode 100644 gl/getdelim.h delete mode 100644 gl/getline.h copy {lib/gl => gl}/m4/getdelim.m4 (63%) delete mode 100644 lib/gl/getdelim.h delete mode 100644 lib/gl/getline.h diff --git a/gl/Makefile.am b/gl/Makefile.am index 93b55bc..06de184 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -157,7 +157,7 @@ EXTRA_libgl_la_SOURCES += gai_strerror.c getaddrinfo.c ## begin gnulib module getdelim -EXTRA_DIST += getdelim.c getdelim.h +EXTRA_DIST += getdelim.c EXTRA_libgl_la_SOURCES += getdelim.c @@ -166,7 +166,7 @@ EXTRA_libgl_la_SOURCES += getdelim.c ## begin gnulib module getline -EXTRA_DIST += getline.c getline.h +EXTRA_DIST += getline.c EXTRA_libgl_la_SOURCES += getline.c @@ -440,6 +440,8 @@ stdio.h: stdio_.h -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \ -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \ -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \ + -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \ + -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \ -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \ -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \ -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \ @@ -457,6 +459,9 @@ stdio.h: stdio_.h -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \ -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \ -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \ + -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \ + -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \ + -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/stdio_.h; \ } > $@-t diff --git a/gl/getdelim.c b/gl/getdelim.c index e0b8a70..0547c7f 100644 --- a/gl/getdelim.c +++ b/gl/getdelim.c @@ -1,5 +1,5 @@ /* getdelim.c --- Implementation of replacement getdelim function. - Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006 Free + Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or @@ -21,7 +21,7 @@ #include -#include "getdelim.h" +#include #include #include @@ -42,6 +42,11 @@ # define funlockfile(x) ((void) 0) #endif +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and NUL-terminate it). *LINEPTR is a pointer returned from malloc (or NULL), pointing to *N characters of space. It is realloc'ed as @@ -65,7 +70,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) if (*lineptr == NULL || *n == 0) { *n = 120; - *lineptr = (char *) malloc (*n); + *lineptr = (char *) realloc (*lineptr, *n); if (*lineptr == NULL) { result = -1; @@ -97,6 +102,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) if (cur_len + 1 >= needed) { result = -1; + errno = EOVERFLOW; goto unlock_return; } @@ -121,6 +127,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) result = cur_len ? cur_len : result; unlock_return: - funlockfile (fp); + funlockfile (fp); /* doesn't set errno */ + return result; } diff --git a/gl/getdelim.h b/gl/getdelim.h deleted file mode 100644 index 8bc6130..0000000 --- a/gl/getdelim.h +++ /dev/null @@ -1,28 +0,0 @@ -/* getdelim.h --- Prototype for replacement getdelim function. - Copyright (C) 2005 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ - -/* Written by Simon Josefsson. */ - -/* Get size_t, FILE, ssize_t. And getdelim, if available. */ -# include -# include -# include - -#if !HAVE_DECL_GETDELIM -ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream); -#endif /* !HAVE_GETDELIM */ diff --git a/gl/getline.c b/gl/getline.c index c8c9244..817c281 100644 --- a/gl/getline.c +++ b/gl/getline.c @@ -1,5 +1,5 @@ /* getline.c --- Implementation of replacement getline function. - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -20,8 +20,7 @@ #include -#include "getdelim.h" -#include "getline.h" +#include ssize_t getline (char **lineptr, size_t *n, FILE *stream) diff --git a/gl/getline.h b/gl/getline.h deleted file mode 100644 index f0f61c4..0000000 --- a/gl/getline.h +++ /dev/null @@ -1,28 +0,0 @@ -/* getline.h --- Prototype for replacement getline function. - Copyright (C) 2005 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ - -/* Written by Simon Josefsson. */ - -/* Get size_t, FILE, ssize_t. And getline, if available. */ -# include -# include -# include - -#if !HAVE_DECL_GETLINE -ssize_t getline (char **lineptr, size_t *n, FILE *stream); -#endif /* !HAVE_GETLINE */ diff --git a/gl/getpass.c b/gl/getpass.c index 4ae2333..17d5137 100644 --- a/gl/getpass.c +++ b/gl/getpass.c @@ -41,8 +41,6 @@ # include #endif -#include "getline.h" - #if USE_UNLOCKED_IO # include "unlocked-io.h" #else diff --git a/lib/gl/m4/getdelim.m4 b/gl/m4/getdelim.m4 similarity index 63% copy from lib/gl/m4/getdelim.m4 copy to gl/m4/getdelim.m4 index 2a738f6..7f6e3b4 100644 --- a/lib/gl/m4/getdelim.m4 +++ b/gl/m4/getdelim.m4 @@ -1,25 +1,30 @@ -# getdelim.m4 serial 2 +# getdelim.m4 serial 3 -dnl Copyright (C) 2005, 2006 Free Software dnl Foundation, Inc. +dnl Copyright (C) 2005, 2006, 2007 Free Software dnl Foundation, Inc. dnl dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. -AC_PREREQ(2.52) +AC_PREREQ([2.60]) AC_DEFUN([gl_FUNC_GETDELIM], [ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) dnl Persuade glibc to declare getdelim(). AC_REQUIRE([AC_GNU_SOURCE]) - AC_REPLACE_FUNCS(getdelim) - AC_CHECK_DECLS_ONCE(getdelim) + AC_REPLACE_FUNCS([getdelim]) + AC_CHECK_DECLS_ONCE([getdelim]) if test $ac_cv_func_getdelim = no; then gl_PREREQ_GETDELIM fi + + if test $ac_cv_have_decl_getdelim = no; then + HAVE_DECL_GETDELIM=0 + fi ]) # Prerequisites of lib/getdelim.c. diff --git a/gl/m4/getline.m4 b/gl/m4/getline.m4 index 5b55c30..11949b7 100644 --- a/gl/m4/getline.m4 +++ b/gl/m4/getline.m4 @@ -1,13 +1,13 @@ -# getline.m4 serial 15 +# getline.m4 serial 16 -dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006 Free Software -dnl Foundation, Inc. +dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007 Free +dnl Software Foundation, Inc. dnl dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. -AC_PREREQ(2.52) +AC_PREREQ([2.60]) dnl See if there's a working, system-supplied version of the getline function. dnl We can't just do AC_REPLACE_FUNCS(getline) because some systems @@ -15,10 +15,12 @@ dnl have a function by that name in -linet that doesn't have anything dnl to do with the function we need. AC_DEFUN([gl_FUNC_GETLINE], [ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + dnl Persuade glibc to declare getline(). AC_REQUIRE([AC_GNU_SOURCE]) - AC_CHECK_DECLS([getline]) + AC_CHECK_DECLS_ONCE([getline]) gl_getline_needs_run_time_check=no AC_CHECK_FUNC(getline, @@ -60,13 +62,13 @@ AC_DEFUN([gl_FUNC_GETLINE], )]) fi + if test $ac_cv_have_decl_getline = no; then + HAVE_DECL_GETLINE=0 + fi + if test $am_cv_func_working_getline = no; then - dnl We must choose a different name for our function, since on ELF systems - dnl a broken getline() in libc.so would override our getline() in - dnl libgettextlib.so. - AC_DEFINE([getline], [gnu_getline], - [Define to a replacement function name for getline().]) - AC_LIBOBJ(getline) + REPLACE_GETLINE=1 + AC_LIBOBJ([getline]) gl_PREREQ_GETLINE fi diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index 4c1e8ad..9c24224 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -50,7 +50,9 @@ AC_DEFUN([gl_INIT], gl_STDIO_MODULE_INDICATOR([fseeko]) gl_GETADDRINFO gl_FUNC_GETDELIM + gl_STDIO_MODULE_INDICATOR([getdelim]) gl_FUNC_GETLINE + gl_STDIO_MODULE_INDICATOR([getline]) gl_GETOPT gl_FUNC_GETPASS AC_SUBST([LIBINTL]) @@ -156,9 +158,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/getaddrinfo.c lib/getaddrinfo.h lib/getdelim.c - lib/getdelim.h lib/getline.c - lib/getline.h lib/getopt.c lib/getopt1.c lib/getopt_.h diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4 index 721c826..b9a6998 100644 --- a/gl/m4/stdio_h.m4 +++ b/gl/m4/stdio_h.m4 @@ -33,6 +33,8 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL]) GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO]) GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH]) + GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM]) + GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE]) dnl Assume proper GNU behavior unless another module says otherwise. REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF]) REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF]) @@ -53,6 +55,9 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO]) REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL]) REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH]) + HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM]) + HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE]) + REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE]) ]) dnl Code shared by fseeko and ftello. Determine if large files are supported, diff --git a/gl/readline.c b/gl/readline.c index f93a115..1eadabd 100644 --- a/gl/readline.c +++ b/gl/readline.c @@ -1,5 +1,5 @@ /* readline.c --- Simple implementation of readline. - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. Written by Simon Josefsson This program is free software; you can redistribute it and/or modify @@ -32,7 +32,6 @@ #include #include -#include char * readline (const char *prompt) diff --git a/gl/stdio_.h b/gl/stdio_.h index 7d77c5e..76d9856 100644 --- a/gl/stdio_.h +++ b/gl/stdio_.h @@ -35,8 +35,11 @@ #include #include -#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) -/* Get off_t. */ +#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \ + || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \ + || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \ + || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@)) +/* Get off_t and ssize_t. */ # include #endif @@ -303,6 +306,44 @@ extern long rpl_ftell (FILE *fp); fflush (f)) #endif +#if @GNULIB_GETDELIM@ +# if !@HAVE_DECL_GETDELIM@ + /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and + NUL-terminate it). *LINEPTR is a pointer returned from malloc (or + NULL), pointing to *N characters of space. It is realloc'ed as + necessary. Returns the number of characters read (not including + the null terminator), or -1 on error or EOF. */ + extern ssize_t getdelim (char **, size_t *, int delim, FILE *); +# endif +#elif defined GNULIB_POSIXCHECK +# undef getdelim +# define getdelim(l, s, d, f) \ + (GL_LINK_WARNING ("getdelim is unportable - " \ + "use gnulib module getdelim for portability"), \ + getdelim (l, s, d, f)) +#endif + +#if @GNULIB_GETLINE@ +# if @REPLACE_GETLINE@ +# undef getline +# define getline rpl_getline +# endif +# if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@ + /* Read up to (and including) a newline from FP into *LINEPTR (and + NUL-terminate it). *LINEPTR is a pointer returned from malloc (or + NULL), pointing to *N characters of space. It is realloc'ed as + necessary. Returns the number of characters read (not including + the null terminator), or -1 on error or EOF. */ + extern ssize_t getline (char **, size_t *, FILE *); +# endif +#elif defined GNULIB_POSIXCHECK +# undef getline +# define getline(l, s, f) \ + (GL_LINK_WARNING ("getline is unportable - " \ + "use gnulib module getline for portability"), \ + getline (l, s, f)) +#endif + #ifdef __cplusplus } #endif diff --git a/lib/gl/Makefile.am b/lib/gl/Makefile.am index e21608f..a140474 100644 --- a/lib/gl/Makefile.am +++ b/lib/gl/Makefile.am @@ -112,7 +112,7 @@ EXTRA_DIST += float_.h ## begin gnulib module getdelim -EXTRA_DIST += getdelim.c getdelim.h +EXTRA_DIST += getdelim.c EXTRA_libgl_la_SOURCES += getdelim.c @@ -121,7 +121,7 @@ EXTRA_libgl_la_SOURCES += getdelim.c ## begin gnulib module getline -EXTRA_DIST += getline.c getline.h +EXTRA_DIST += getline.c EXTRA_libgl_la_SOURCES += getline.c @@ -259,6 +259,8 @@ stdio.h: stdio_.h -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \ -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \ -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \ + -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \ + -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \ -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \ -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \ -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \ @@ -276,6 +278,9 @@ stdio.h: stdio_.h -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \ -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \ -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \ + -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \ + -e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \ + -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/stdio_.h; \ } > $@-t diff --git a/lib/gl/getdelim.c b/lib/gl/getdelim.c index f20d0a1..f903dfc 100644 --- a/lib/gl/getdelim.c +++ b/lib/gl/getdelim.c @@ -1,5 +1,5 @@ /* getdelim.c --- Implementation of replacement getdelim function. - Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006 Free + Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or @@ -21,7 +21,7 @@ #include -#include "getdelim.h" +#include #include #include @@ -42,6 +42,11 @@ # define funlockfile(x) ((void) 0) #endif +/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ +#ifndef EOVERFLOW +# define EOVERFLOW E2BIG +#endif + /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and NUL-terminate it). *LINEPTR is a pointer returned from malloc (or NULL), pointing to *N characters of space. It is realloc'ed as @@ -65,7 +70,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) if (*lineptr == NULL || *n == 0) { *n = 120; - *lineptr = (char *) malloc (*n); + *lineptr = (char *) realloc (*lineptr, *n); if (*lineptr == NULL) { result = -1; @@ -97,6 +102,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) if (cur_len + 1 >= needed) { result = -1; + errno = EOVERFLOW; goto unlock_return; } @@ -121,6 +127,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) result = cur_len ? cur_len : result; unlock_return: - funlockfile (fp); + funlockfile (fp); /* doesn't set errno */ + return result; } diff --git a/lib/gl/getdelim.h b/lib/gl/getdelim.h deleted file mode 100644 index 9e6c931..0000000 --- a/lib/gl/getdelim.h +++ /dev/null @@ -1,28 +0,0 @@ -/* getdelim.h --- Prototype for replacement getdelim function. - Copyright (C) 2005 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1, or (at - your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ - -/* Written by Simon Josefsson. */ - -/* Get size_t, FILE, ssize_t. And getdelim, if available. */ -# include -# include -# include - -#if !HAVE_DECL_GETDELIM -ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream); -#endif /* !HAVE_GETDELIM */ diff --git a/lib/gl/getline.c b/lib/gl/getline.c index 2185e96..2be81c0 100644 --- a/lib/gl/getline.c +++ b/lib/gl/getline.c @@ -1,5 +1,5 @@ /* getline.c --- Implementation of replacement getline function. - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -20,8 +20,7 @@ #include -#include "getdelim.h" -#include "getline.h" +#include ssize_t getline (char **lineptr, size_t *n, FILE *stream) diff --git a/lib/gl/getline.h b/lib/gl/getline.h deleted file mode 100644 index d58df19..0000000 --- a/lib/gl/getline.h +++ /dev/null @@ -1,28 +0,0 @@ -/* getline.h --- Prototype for replacement getline function. - Copyright (C) 2005 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1, or (at - your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ - -/* Written by Simon Josefsson. */ - -/* Get size_t, FILE, ssize_t. And getline, if available. */ -# include -# include -# include - -#if !HAVE_DECL_GETLINE -ssize_t getline (char **lineptr, size_t *n, FILE *stream); -#endif /* !HAVE_GETLINE */ diff --git a/lib/gl/m4/getdelim.m4 b/lib/gl/m4/getdelim.m4 index 2a738f6..7f6e3b4 100644 --- a/lib/gl/m4/getdelim.m4 +++ b/lib/gl/m4/getdelim.m4 @@ -1,25 +1,30 @@ -# getdelim.m4 serial 2 +# getdelim.m4 serial 3 -dnl Copyright (C) 2005, 2006 Free Software dnl Foundation, Inc. +dnl Copyright (C) 2005, 2006, 2007 Free Software dnl Foundation, Inc. dnl dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. -AC_PREREQ(2.52) +AC_PREREQ([2.60]) AC_DEFUN([gl_FUNC_GETDELIM], [ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) dnl Persuade glibc to declare getdelim(). AC_REQUIRE([AC_GNU_SOURCE]) - AC_REPLACE_FUNCS(getdelim) - AC_CHECK_DECLS_ONCE(getdelim) + AC_REPLACE_FUNCS([getdelim]) + AC_CHECK_DECLS_ONCE([getdelim]) if test $ac_cv_func_getdelim = no; then gl_PREREQ_GETDELIM fi + + if test $ac_cv_have_decl_getdelim = no; then + HAVE_DECL_GETDELIM=0 + fi ]) # Prerequisites of lib/getdelim.c. diff --git a/lib/gl/m4/getline.m4 b/lib/gl/m4/getline.m4 index 5b55c30..11949b7 100644 --- a/lib/gl/m4/getline.m4 +++ b/lib/gl/m4/getline.m4 @@ -1,13 +1,13 @@ -# getline.m4 serial 15 +# getline.m4 serial 16 -dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006 Free Software -dnl Foundation, Inc. +dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007 Free +dnl Software Foundation, Inc. dnl dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. -AC_PREREQ(2.52) +AC_PREREQ([2.60]) dnl See if there's a working, system-supplied version of the getline function. dnl We can't just do AC_REPLACE_FUNCS(getline) because some systems @@ -15,10 +15,12 @@ dnl have a function by that name in -linet that doesn't have anything dnl to do with the function we need. AC_DEFUN([gl_FUNC_GETLINE], [ + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) + dnl Persuade glibc to declare getline(). AC_REQUIRE([AC_GNU_SOURCE]) - AC_CHECK_DECLS([getline]) + AC_CHECK_DECLS_ONCE([getline]) gl_getline_needs_run_time_check=no AC_CHECK_FUNC(getline, @@ -60,13 +62,13 @@ AC_DEFUN([gl_FUNC_GETLINE], )]) fi + if test $ac_cv_have_decl_getline = no; then + HAVE_DECL_GETLINE=0 + fi + if test $am_cv_func_working_getline = no; then - dnl We must choose a different name for our function, since on ELF systems - dnl a broken getline() in libc.so would override our getline() in - dnl libgettextlib.so. - AC_DEFINE([getline], [gnu_getline], - [Define to a replacement function name for getline().]) - AC_LIBOBJ(getline) + REPLACE_GETLINE=1 + AC_LIBOBJ([getline]) gl_PREREQ_GETLINE fi diff --git a/lib/gl/m4/gnulib-comp.m4 b/lib/gl/m4/gnulib-comp.m4 index d0faff7..4119060 100644 --- a/lib/gl/m4/gnulib-comp.m4 +++ b/lib/gl/m4/gnulib-comp.m4 @@ -54,7 +54,9 @@ AC_DEFUN([gl_INIT], gl_MODULE_INDICATOR([gc-random]) gl_FLOAT_H gl_FUNC_GETDELIM + gl_STDIO_MODULE_INDICATOR([getdelim]) gl_FUNC_GETLINE + gl_STDIO_MODULE_INDICATOR([getline]) dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. AM_GNU_GETTEXT_VERSION([0.16.1]) AC_SUBST([LIBINTL]) @@ -124,9 +126,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/gc-libgcrypt.c lib/gc.h lib/getdelim.c - lib/getdelim.h lib/getline.c - lib/getline.h lib/gettext.h lib/hmac-md5.c lib/hmac.h diff --git a/lib/gl/m4/stdio_h.m4 b/lib/gl/m4/stdio_h.m4 index 721c826..b9a6998 100644 --- a/lib/gl/m4/stdio_h.m4 +++ b/lib/gl/m4/stdio_h.m4 @@ -33,6 +33,8 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL]) GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO]) GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH]) + GNULIB_GETDELIM=0; AC_SUBST([GNULIB_GETDELIM]) + GNULIB_GETLINE=0; AC_SUBST([GNULIB_GETLINE]) dnl Assume proper GNU behavior unless another module says otherwise. REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF]) REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF]) @@ -53,6 +55,9 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO]) REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL]) REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH]) + HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM]) + HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE]) + REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE]) ]) dnl Code shared by fseeko and ftello. Determine if large files are supported, diff --git a/lib/gl/stdio_.h b/lib/gl/stdio_.h index 01a6496..42bac02 100644 --- a/lib/gl/stdio_.h +++ b/lib/gl/stdio_.h @@ -35,8 +35,11 @@ #include #include -#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) -/* Get off_t. */ +#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \ + || (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \ + || (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \ + || (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@)) +/* Get off_t and ssize_t. */ # include #endif @@ -303,6 +306,44 @@ extern long rpl_ftell (FILE *fp); fflush (f)) #endif +#if @GNULIB_GETDELIM@ +# if !@HAVE_DECL_GETDELIM@ + /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and + NUL-terminate it). *LINEPTR is a pointer returned from malloc (or + NULL), pointing to *N characters of space. It is realloc'ed as + necessary. Returns the number of characters read (not including + the null terminator), or -1 on error or EOF. */ + extern ssize_t getdelim (char **, size_t *, int delim, FILE *); +# endif +#elif defined GNULIB_POSIXCHECK +# undef getdelim +# define getdelim(l, s, d, f) \ + (GL_LINK_WARNING ("getdelim is unportable - " \ + "use gnulib module getdelim for portability"), \ + getdelim (l, s, d, f)) +#endif + +#if @GNULIB_GETLINE@ +# if @REPLACE_GETLINE@ +# undef getline +# define getline rpl_getline +# endif +# if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@ + /* Read up to (and including) a newline from FP into *LINEPTR (and + NUL-terminate it). *LINEPTR is a pointer returned from malloc (or + NULL), pointing to *N characters of space. It is realloc'ed as + necessary. Returns the number of characters read (not including + the null terminator), or -1 on error or EOF. */ + extern ssize_t getline (char **, size_t *, FILE *); +# endif +#elif defined GNULIB_POSIXCHECK +# undef getline +# define getline(l, s, f) \ + (GL_LINK_WARNING ("getline is unportable - " \ + "use gnulib module getline for portability"), \ + getline (l, s, f)) +#endif + #ifdef __cplusplus } #endif -- 2.11.4.GIT