From 33c8286ea93bec94c46d777a77d471babd3698e0 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 23 Aug 2007 02:00:18 +0000 Subject: [PATCH] Getline touchups. * lib/getdelim.c (getdelim): Revert regression that required *n to be 0 when *lineptr is NULL. Preserve errno across funlockfile. * m4/getdelim.m4 (gl_FUNC_GETDELIM): Check for declaration of getdelim, rather than whether implementation is missing. * m4/getline.m4 (gl_FUNC_GETLINE): Likewise for getline. * lib/stdio_.h (getline): Also declare if replacement is required. * doc/functions/getdelim.texi: New file. * doc/functions/getline.texi: Likewise. * doc/gnulib.texi (Function Substitutes): Add new files. Reported by Bruno Haible. --- ChangeLog | 15 +++++++++++++++ doc/functions/getdelim.texi | 23 +++++++++++++++++++++++ doc/functions/getline.texi | 27 +++++++++++++++++++++++++++ doc/gnulib.texi | 8 ++++++-- lib/getdelim.c | 12 +++++++++--- lib/stdio_.h | 2 +- m4/getdelim.m4 | 9 ++++++--- m4/getline.m4 | 8 ++++---- 8 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 doc/functions/getdelim.texi create mode 100644 doc/functions/getline.texi diff --git a/ChangeLog b/ChangeLog index 668d4a3d5..da49d88c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-08-22 Eric Blake + + Getline touchups. + * lib/getdelim.c (getdelim): Revert regression that required *n to + be 0 when *lineptr is NULL. Preserve errno across funlockfile. + * m4/getdelim.m4 (gl_FUNC_GETDELIM): Check for declaration of + getdelim, rather than whether implementation is missing. + * m4/getline.m4 (gl_FUNC_GETLINE): Likewise for getline. + * lib/stdio_.h (getline): Also declare if replacement is + required. + * doc/functions/getdelim.texi: New file. + * doc/functions/getline.texi: Likewise. + * doc/gnulib.texi (Function Substitutes): Add new files. + Reported by Bruno Haible. + 2007-08-22 Ludovic Courtès * users.txt: Add Guile. diff --git a/doc/functions/getdelim.texi b/doc/functions/getdelim.texi new file mode 100644 index 000000000..77336c174 --- /dev/null +++ b/doc/functions/getdelim.texi @@ -0,0 +1,23 @@ +@node getdelim +@section @code{getdelim} +@findex getdelim + +POSIX specification: Draft 3 of 200x; free membership at +@url{http://www.opengroup.org/austin/} is required + +Gnulib module: getdelim + +Portability problems fixed by Gnulib: +@itemize +@item +This function is missing on some platforms: +mingw + +@item +This function is missing a declaration on some platforms: +BeOS +@end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize diff --git a/doc/functions/getline.texi b/doc/functions/getline.texi new file mode 100644 index 000000000..daaa766fe --- /dev/null +++ b/doc/functions/getline.texi @@ -0,0 +1,27 @@ +@node getline +@section @code{getline} +@findex getline + +POSIX specification: Draft 3 of 200x; free membership at +@url{http://www.opengroup.org/austin/} is required + +Gnulib module: getline + +Portability problems fixed by Gnulib: +@itemize +@item +This function is missing on some platforms: +mingw + +@item +This function is missing a declaration on some platforms: +BeOS + +@item +Some platforms provide a function by this name but with the wrong +signature, for example in -linet. +@end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize diff --git a/doc/gnulib.texi b/doc/gnulib.texi index 3cc7342c3..4abf6ed52 100644 --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -1,5 +1,5 @@ \input texinfo @c -*-texinfo-*- -@comment $Id: gnulib.texi,v 1.42 2007-07-15 14:05:43 karl Exp $ +@comment $Id: gnulib.texi,v 1.43 2007-08-23 02:00:19 ericb Exp $ @comment %**start of header @setfilename gnulib.info @settitle GNU Gnulib @@ -7,7 +7,7 @@ @syncodeindex pg cp @comment %**end of header -@set UPDATED $Date: 2007-07-15 14:05:43 $ +@set UPDATED $Date: 2007-08-23 02:00:19 $ @copying This manual is for GNU Gnulib (updated @value{UPDATED}), @@ -929,6 +929,7 @@ by Gnulib. * getcontext:: * getcwd:: * getdate:: +* getdelim:: * getegid:: * getenv:: * geteuid:: @@ -945,6 +946,7 @@ by Gnulib. * gethostid:: * gethostname:: * getitimer:: +* getline:: * getlogin:: * getlogin_r:: * getmsg:: @@ -2047,6 +2049,7 @@ by Gnulib. @include functions/getcontext.texi @include functions/getcwd.texi @include functions/getdate.texi +@include functions/getdelim.texi @include functions/getegid.texi @include functions/getenv.texi @include functions/geteuid.texi @@ -2063,6 +2066,7 @@ by Gnulib. @include functions/gethostid.texi @include functions/gethostname.texi @include functions/getitimer.texi +@include functions/getline.texi @include functions/getlogin.texi @include functions/getlogin_r.texi @include functions/getmsg.texi diff --git a/lib/getdelim.c b/lib/getdelim.c index 352b5974b..ded1d9cf5 100644 --- a/lib/getdelim.c +++ b/lib/getdelim.c @@ -58,6 +58,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) { ssize_t result; size_t cur_len = 0; + int e; /* Preserve errno across funlockfile. */ if (lineptr == NULL || n == NULL || fp == NULL) { @@ -67,13 +68,14 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) flockfile (fp); - if (*n == 0) + if (*lineptr == NULL || *n == 0) { *n = 120; - *lineptr = (char *) realloc (*lineptr, 120); + *lineptr = (char *) realloc (*lineptr, *n); if (*lineptr == NULL) { result = -1; + e = ENOMEM; goto unlock_return; } } @@ -86,6 +88,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) if (i == EOF) { result = -1; + e = errno; break; } @@ -102,7 +105,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) if (cur_len + 1 >= needed) { result = -1; - errno = EOVERFLOW; + e = EOVERFLOW; goto unlock_return; } @@ -110,6 +113,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) if (new_lineptr == NULL) { result = -1; + e = ENOMEM; goto unlock_return; } @@ -128,5 +132,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) unlock_return: funlockfile (fp); + if (result == -1) + errno = e; return result; } diff --git a/lib/stdio_.h b/lib/stdio_.h index 03d85e3d6..76d985637 100644 --- a/lib/stdio_.h +++ b/lib/stdio_.h @@ -328,7 +328,7 @@ extern long rpl_ftell (FILE *fp); # undef getline # define getline rpl_getline # endif -# if !@HAVE_DECL_GETLINE@ +# 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 diff --git a/m4/getdelim.m4 b/m4/getdelim.m4 index 21be20c3a..7f6e3b41f 100644 --- a/m4/getdelim.m4 +++ b/m4/getdelim.m4 @@ -6,7 +6,7 @@ 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], [ @@ -15,11 +15,14 @@ AC_DEFUN([gl_FUNC_GETDELIM], 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 ]) diff --git a/m4/getline.m4 b/m4/getline.m4 index 421710595..11949b71c 100644 --- a/m4/getline.m4 +++ b/m4/getline.m4 @@ -7,7 +7,7 @@ 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 @@ -20,7 +20,7 @@ AC_DEFUN([gl_FUNC_GETLINE], 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, @@ -62,13 +62,13 @@ AC_DEFUN([gl_FUNC_GETLINE], )]) fi - if test $ac_cv_func_getline = no; then + if test $ac_cv_have_decl_getline = no; then HAVE_DECL_GETLINE=0 fi if test $am_cv_func_working_getline = no; then REPLACE_GETLINE=1 - AC_LIBOBJ(getline) + AC_LIBOBJ([getline]) gl_PREREQ_GETLINE fi -- 2.11.0