bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getline.h


From: Eric Blake
Subject: Re: getline.h
Date: Wed, 22 Aug 2007 19:59:31 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 8/22/2007 6:04 PM:
> According to Bruno Haible on 8/22/2007 3:02 PM:
>> Hi Eric,
> 
>> Thanks for working on this, and for the unit tests. The patch - excluding
>> the one of getdelim.c - is nearly perfect. But I see three problems:
> 
> Thanks for catching the nits.  Please feel free to apply patches if you
> come up with them before me.

Here's what I'm committing; I think it addresses all your points.

2007-08-22  Eric Blake  <address@hidden>

        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.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFGzOoD84KuGfSFAYARAl+dAJ9XrkZHtoiOQwJUpxWbqc3JTl+KowCWOSv6
wSAwvtfYANnM796ICFivDg==
=c4j1
-----END PGP SIGNATURE-----
Index: lib/getdelim.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/getdelim.c,v
retrieving revision 1.8
diff -u -p -r1.8 getdelim.c
--- lib/getdelim.c      22 Aug 2007 12:54:22 -0000      1.8
+++ lib/getdelim.c      23 Aug 2007 01:58:57 -0000
@@ -58,6 +58,7 @@ getdelim (char **lineptr, size_t *n, int
 {
   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
 
   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
       if (i == EOF)
        {
          result = -1;
+         e = errno;
          break;
        }
 
@@ -102,7 +105,7 @@ getdelim (char **lineptr, size_t *n, int
          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
          if (new_lineptr == NULL)
            {
              result = -1;
+             e = ENOMEM;
              goto unlock_return;
            }
 
@@ -128,5 +132,7 @@ getdelim (char **lineptr, size_t *n, int
 
  unlock_return:
   funlockfile (fp);
+  if (result == -1)
+    errno = e;
   return result;
 }
Index: lib/stdio_.h
===================================================================
RCS file: /sources/gnulib/gnulib/lib/stdio_.h,v
retrieving revision 1.33
diff -u -p -r1.33 stdio_.h
--- lib/stdio_.h        22 Aug 2007 12:54:22 -0000      1.33
+++ lib/stdio_.h        23 Aug 2007 01:58:57 -0000
@@ -328,7 +328,7 @@ extern long rpl_ftell (FILE *fp);
 #  undef getline
 #  define getline rpl_getline
 # endif
-# if address@hidden@
+# if address@hidden@ || @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: doc/gnulib.texi
===================================================================
RCS file: /sources/gnulib/gnulib/doc/gnulib.texi,v
retrieving revision 1.42
diff -u -p -r1.42 gnulib.texi
--- doc/gnulib.texi     15 Jul 2007 14:05:43 -0000      1.42
+++ doc/gnulib.texi     23 Aug 2007 01:58:57 -0000
@@ -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
address@hidden 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
address@hidden functions/getline.texi
 @include functions/getlogin.texi
 @include functions/getlogin_r.texi
 @include functions/getmsg.texi
Index: doc/functions/getdelim.texi
===================================================================
RCS file: doc/functions/getdelim.texi
diff -N doc/functions/getdelim.texi
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ doc/functions/getdelim.texi 23 Aug 2007 01:58:57 -0000
@@ -0,0 +1,23 @@
address@hidden getdelim
address@hidden @code{getdelim}
address@hidden getdelim
+
+POSIX specification: Draft 3 of 200x; free membership at
address@hidden://www.opengroup.org/austin/} is required
+
+Gnulib module: getdelim
+
+Portability problems fixed by Gnulib:
address@hidden
address@hidden
+This function is missing on some platforms:
+mingw
+
address@hidden
+This function is missing a declaration on some platforms:
+BeOS
address@hidden itemize
+
+Portability problems not fixed by Gnulib:
address@hidden
address@hidden itemize
Index: doc/functions/getline.texi
===================================================================
RCS file: doc/functions/getline.texi
diff -N doc/functions/getline.texi
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ doc/functions/getline.texi  23 Aug 2007 01:58:57 -0000
@@ -0,0 +1,27 @@
address@hidden getline
address@hidden @code{getline}
address@hidden getline
+
+POSIX specification: Draft 3 of 200x; free membership at
address@hidden://www.opengroup.org/austin/} is required
+
+Gnulib module: getline
+
+Portability problems fixed by Gnulib:
address@hidden
address@hidden
+This function is missing on some platforms:
+mingw
+
address@hidden
+This function is missing a declaration on some platforms:
+BeOS
+
address@hidden
+Some platforms provide a function by this name but with the wrong
+signature, for example in -linet.
address@hidden itemize
+
+Portability problems not fixed by Gnulib:
address@hidden
address@hidden itemize
Index: m4/getdelim.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/getdelim.m4,v
retrieving revision 1.3
diff -u -p -r1.3 getdelim.m4
--- m4/getdelim.m4      22 Aug 2007 12:54:22 -0000      1.3
+++ m4/getdelim.m4      23 Aug 2007 01:58:57 -0000
@@ -6,7 +6,7 @@ dnl This file is free software; the Free
 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: m4/getline.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/getline.m4,v
retrieving revision 1.19
diff -u -p -r1.19 getline.m4
--- m4/getline.m4       22 Aug 2007 12:54:23 -0000      1.19
+++ m4/getline.m4       23 Aug 2007 01:58:57 -0000
@@ -7,7 +7,7 @@ dnl This file is free software; the Free
 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]