Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Mar 2012 14:38:56 -0400
From:      Matthew Story <matthewstory@gmail.com>
To:        standards@freebsd.org
Subject:   Re: PR kern/164674
Message-ID:  <CAB%2B9ogfLych1xcCR1eVT%2BAMCsUah0EC6nZ-%2Bm3ixHtwJ5Pb5aw@mail.gmail.com>
In-Reply-To: <201203041403.29020.jhb@freebsd.org>
References:  <201203041403.29020.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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.
>

The gist of this patch is to provide uniform successful behavior for
un|buffered FILEs in cases where any printf function is called directed to
FILE.  The C11 specification (referenced in the PR) states that vfprintf
(and all derivatives) shall return the total number of bytes transmitted,
or -1 if an encoding or transmission error occurs.  It does not make
mention the ferror state of a FILE.

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

While the patch attached to the PR is large, the vast bulk of that patch
provides a new regression test for the case of vfprintf on FILEs with
ferror.  The changes to vfprintf and vfwprintf are minimal.

-- 
regards,
matt



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAB%2B9ogfLych1xcCR1eVT%2BAMCsUah0EC6nZ-%2Bm3ixHtwJ5Pb5aw>