[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] invalid use of errno after ferror
From: |
Bruno Haible |
Subject: |
Re: [Bug-gnulib] invalid use of errno after ferror |
Date: |
Wed, 17 Sep 2003 12:29:53 +0200 |
User-agent: |
KMail/1.5 |
Paul Eggert wrote:
> Isn't this also true for lib/mountlist.c?
You are right; I had overlooked that the third argument of fread() is 1.
If Jim doesn't object, I'll add a comment about this:
--- mountlist.c 9 Sep 2003 22:47:38 -0000 1.42
+++ mountlist.c 17 Sep 2003 10:19:40 -0000
@@ -612,6 +612,7 @@
if (ferror (fp))
{
+ /* The last fread() call must have failed. */
int saved_errno = errno;
fclose (fp);
errno = saved_errno;
--------------------------------------------------------------------------
> 2003-09-15 Paul Eggert <address@hidden>
>
> * lib/getndelim2.c (getndelim2): Don't trash errno when a read
> fails, so that the caller gets the proper errno.
Thanks for this patch. Following it, I'd like to change the description
of the getndelim2 and related functions to read:
Return the number of bytes read and stored at *LINEPTR + OFFSET (not
including the NUL terminator), or -1 on error or EOF. Error can be
distinguished from EOF through ferror (stream); in the case of error
'errno' will be set upon return.
However this description does not hold on non-POSIX systems that don't
set errno in their stdio routines. To fix this, I'd propose this patch:
--- getndelim2.c 15 Sep 2003 22:34:18 -0000 1.4
+++ getndelim2.c 17 Sep 2003 10:25:47 -0000
@@ -95,12 +95,16 @@
}
}
+ /* Clear errno, so that on non-POSIX systems the caller doesn't see a
+ wrong value of errno when we return -1. */
+ errno = 0;
+
c = getc (stream);
if (c == EOF)
{
/* Return partial line, if any. */
if (read_pos == *lineptr)
- return -1;
+ return -1; /* if error occurred, errno is set here */
else
break;
}
--------------------------------------------------------------------------
> Don't assume ferror sets errno. Bug reported by Bruno Haible.
> * src/cksum.c (cksum): Don't assume ferror sets errno.
But here you could actually still provide the errno value by calling
fwriteerror (stdout) instead of ferror (stdout). That's why I added the
fwriteerror module to gnulib.
Bruno
- [Bug-gnulib] invalid use of errno after ferror, Bruno Haible, 2003/09/15
- Re: [Bug-gnulib] invalid use of errno after ferror, Paul Eggert, 2003/09/15
- Re: [Bug-gnulib] invalid use of errno after ferror, Jim Meyering, 2003/09/16
- Re: [Bug-gnulib] invalid use of errno after ferror,
Bruno Haible <=
- Re: [Bug-gnulib] invalid use of errno after ferror, Jim Meyering, 2003/09/17
- Re: [Bug-gnulib] invalid use of errno after ferror, Paul Eggert, 2003/09/17
- Re: [Bug-gnulib] invalid use of errno after ferror, Bruno Haible, 2003/09/18
- Re: [Bug-gnulib] invalid use of errno after ferror, Paul Eggert, 2003/09/18
- Re: [Bug-gnulib] invalid use of errno after ferror, Bruno Haible, 2003/09/19
- Re: [Bug-gnulib] invalid use of errno after ferror, Paul Eggert, 2003/09/22
- Re: [Bug-gnulib] invalid use of errno after ferror, Bruno Haible, 2003/09/22