Getline touchups.
authorEric Blake <ebb9@byu.net>
Thu, 23 Aug 2007 02:00:18 +0000 (02:00 +0000)
committerEric Blake <ebb9@byu.net>
Thu, 23 Aug 2007 02:00:18 +0000 (02:00 +0000)
* 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
doc/functions/getdelim.texi [new file with mode: 0644]
doc/functions/getline.texi [new file with mode: 0644]
doc/gnulib.texi
lib/getdelim.c
lib/stdio_.h
m4/getdelim.m4
m4/getline.m4

index 668d4a3..da49d88 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2007-08-22  Eric Blake  <ebb9@byu.net>
+
+       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  <ludo@gnu.org>
 
        * users.txt: Add Guile.
diff --git a/doc/functions/getdelim.texi b/doc/functions/getdelim.texi
new file mode 100644 (file)
index 0000000..77336c1
--- /dev/null
@@ -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 (file)
index 0000000..daaa766
--- /dev/null
@@ -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
index 3cc7342..4abf6ed 100644 (file)
@@ -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
index 352b597..ded1d9c 100644 (file)
@@ -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;
 }
index 03d85e3..76d9856 100644 (file)
@@ -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
index 21be20c..7f6e3b4 100644 (file)
@@ -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 <stdio.h> 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
 ])
index 4217105..11949b7 100644 (file)
@@ -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 <stdio.h> 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