Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Mar 2012 17:45:25 -0400
From:      David Schultz <das@FreeBSD.ORG>
To:        Matthew Story <matthewstory@gmail.com>
Cc:        standards@FreeBSD.ORG, jhb@FreeBSD.ORG
Subject:   Re: PR kern/164674
Message-ID:  <20120321214525.GA46850@zim.MIT.EDU>
In-Reply-To: <CAB%2B9ogfLych1xcCR1eVT%2BAMCsUah0EC6nZ-%2Bm3ixHtwJ5Pb5aw@mail.gmail.com>
References:  <201203041403.29020.jhb@freebsd.org> <CAB%2B9ogfLych1xcCR1eVT%2BAMCsUah0EC6nZ-%2Bm3ixHtwJ5Pb5aw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Mar 12, 2012, Matthew Story wrote:
> On Sun, Mar 4, 2012 at 2:03 PM, John Baldwin <jhb@freebsd.org> wrote:
> 
> > My standard-parsing fu is weak.  Can some other folks on this list look at
> > this PR, figure out what the correct semantics for *fprintf() in this case,
> > and evaluate the patch?  Thanks.
[...]
> libc vfprintf currently behaves differently on un|buffered FILEs with
> ferror set:
> 
> 1. Unbuffered FILEs
> 
>       -> does not transmit any bytes, and returns -1
> 
> 2. Buffered FILEs (fully buffered, or line buffered)
> 
>       -> transmits all bytes, and returns -1
> 
> I believe that this should be reconciled such that vfprintf (and all
> derivatives) returns sucess|failure based on transmission, not taking
> ferror state into account, but an alternate solution would be to reconcile
> the behavior of buffered FILEs with the current behavior of unbuffered
> FILEs (e.g. detect ferror state, transmit no bytes and return -1).

I agree with this assessment.  When the error indicator is set on
a stream, it means that an error has occurred at some point---not
that all subsequent operations on the stream should fail.

There ought to be a less ugly fix than the one proposed.  Probably
the PRINT macro and the various other evil macros in vfprintf()
should set ret to EOF, and the following lines in vfprintf.c should
be removed:

	if (__sferror(fp))
		ret = EOF;

If vfprintf() is fixed so that printing to a buffered stream
always returns success after a successful write (regardless of the
prior state of the stream's error indicator), that should fix the
problem for unbuffered streams automatically.  Unbuffered streams
go through __sbprintf(), which throws away the output if
vfprintf() returns -1.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120321214525.GA46850>