[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: Fri, 19 Sep 2003 11:11:42 +0200
User-agent: KMail/1.5

Paul Eggert wrote:
> >     if (fprintf (output_file, "set ::msgcat::header ") < 0)
> >       return -1;
> >
> > and realized that the code had become unreadable and therefore
> > unmaintainable.
> But we already need to write that kind of code for each input operation.

Input is different, because the program cannot meaningfully continue anyway
after getc() has returned EOF. Let's concentrate on discussing output here.

> Personally I'd just grit my teeth and check each output operation too.
> I see your point, though; not everybody wants to do that.

Yes. With fwrite() I can make a macro

  #define FWRITE(ptr, size, n, stream) \
    if ((size) * (n) > 0 && fwrite (ptr, (size) * (n), 1, stream) == 0) \
      return -1

but with fprintf() I don't see how to write such a macro with the means
of ANSI C.

Also, there is Jim's comment in closeout.c:

  "Besides, it's wasteful to check the return value from every call
   that writes to stdout -- just let the internal stream state record
   the failure.  That's what the ferror test is checking below."


reply via email to

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