PR kern/164674

Matthew Story matthewstory at
Mon Mar 12 18:38:57 UTC 2012

On Sun, Mar 4, 2012 at 2:03 PM, John Baldwin <jhb at> 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.


More information about the freebsd-standards mailing list