[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: Jim Meyering
Subject: Re: [Bug-gnulib] invalid use of errno after ferror
Date: Tue, 16 Sep 2003 14:01:47 +0200

Paul Eggert <address@hidden> wrote:
> Bruno Haible <address@hidden> writes:
> 2003-09-15  Paul Eggert  <address@hidden>
>       Don't assume ferror sets errno.  Bug reported by Bruno Haible.
>       * src/cksum.c (cksum): Don't assume ferror sets errno.

Thanks for all of that work, Paul.
And thanks for pointing out the general problem, Bruno.

But is the above really necessary?
Here's the code in question:

  if (print_name)
    printf ("%u %s %s\n", (unsigned) crc, hp, file);
    printf ("%u %s\n", (unsigned) crc, hp);

  if (ferror (stdout))
    error (EXIT_FAILURE, errno, "-: %s", _("write error"));

When ferror returns nonzero, doesn't that suggest that
the preceding printf failed, e.g., with a write error?

  $ cksum /dev/null > /dev/full
  cksum: write error: No space left on device
  [Exit 1]

I haven't looked carefully at the other changes, but at first
glance, I don't like the cases where the changed code would no
longer use a valid errno in some cases.

I did see that in some cases, errno could be clobbered by
e.g. an intervening free.  In general, I'd really like to
continue to use errno values, especially those that result
from failing to close or to flush an output stream.

reply via email to

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