bug-gnulib
[Top][All Lists]
Advanced

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

Re: getline.h


From: Jim Meyering
Subject: Re: getline.h
Date: Thu, 23 Aug 2007 09:22:16 +0200

Eric Blake <address@hidden> wrote:

> 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.

I almost wrote this:

  Even with that patch, errno may still end up being changed inappropriately
  when getdelim succeeds yet funlockfile fails.  And what about flockfile?

But then I looked it up and saw that those functions are guaranteed
not to set errno.  So that's a red herring.  Sorry about that.

Here's a patch to remove that unnecessary code, including the
errno = ENOMEM business, assuming that we'll eventually have
malloc/realloc/calloc wrappers that make mingw do the right thing:

[is this ok with you, Simon? ]

        Getdelim touchup.
        * lib/getdelim.c (getdelim): Don't bother to save/restore errno
        around the funlockfile call, since funlockfile never sets errno.
        Don't set errno upon failed realloc.

Index: lib/getdelim.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getdelim.c,v
retrieving revision 1.9
diff -u -p -r1.9 getdelim.c
--- lib/getdelim.c      23 Aug 2007 02:00:19 -0000      1.9
+++ lib/getdelim.c      23 Aug 2007 06:56:55 -0000
@@ -58,7 +58,6 @@ 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)
     {
@@ -75,7 +74,6 @@ getdelim (char **lineptr, size_t *n, int
       if (*lineptr == NULL)
        {
          result = -1;
-         e = ENOMEM;
          goto unlock_return;
        }
     }
@@ -88,7 +86,6 @@ getdelim (char **lineptr, size_t *n, int
       if (i == EOF)
        {
          result = -1;
-         e = errno;
          break;
        }

@@ -105,7 +102,7 @@ getdelim (char **lineptr, size_t *n, int
          if (cur_len + 1 >= needed)
            {
              result = -1;
-             e = EOVERFLOW;
+             errno = EOVERFLOW;
              goto unlock_return;
            }

@@ -113,7 +110,6 @@ getdelim (char **lineptr, size_t *n, int
          if (new_lineptr == NULL)
            {
              result = -1;
-             e = ENOMEM;
              goto unlock_return;
            }

@@ -131,8 +127,7 @@ getdelim (char **lineptr, size_t *n, int
   result = cur_len ? cur_len : result;

  unlock_return:
-  funlockfile (fp);
-  if (result == -1)
-    errno = e;
+  funlockfile (fp); /* doesn't set errno */
+
   return result;
 }




reply via email to

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