Date: Thu, 16 Feb 2012 10:55:11 -0500 From: Matthew Story <matthewstory@gmail.com> To: freebsd-gnats-submit@freebsd.org, freebsd-standards@freebsd.org Subject: Re: kern/164674: vsprintf/vswprintf return error (EOF) on success if __SERR flag is already set on file Message-ID: <CAB%2B9ogeZ3T5k1hCFUDWOn%2Bbbwt_80%2BFm7pJFnTOwZf41RAGgOw@mail.gmail.com> In-Reply-To: <201201312306.q0VN6roO091429@red.freebsd.org> References: <201201312306.q0VN6roO091429@red.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jan 31, 2012 at 6:06 PM, Matthew Story <matthewstory@gmail.com>wrote: > > >Number: 164674 > >Category: kern > >Synopsis: vfprintf/vfwprintf return error (EOF) on success if > __SERR flag is already set on file > Apologies for cross-posting, but I think that standards might be a more appropriate responsible party for this than -bugs or kern. See description for more info, but the basic issue is that C99 and C11 stipulate that fprintf should return -1 "if an output or encoding error occurred." Currently, printf is encoding and outputting successfully (on line or fully buffered FILEs), but returning -1 if the FILE has an error. The C99/C11 specifications make no mention of FILE state in fprintf return conditions, so this functionality seems to not conform to the specification, attached patch resolves that issue. > >Confidential: no > >Severity: non-critical > >Priority: low > >Responsible: freebsd-bugs > >State: open > [...snip] > >Description: > The printf family of functions behaves unpredictably if the file passed to > the function has the __SERR flag set in _flags. The one consistency across > all of the cases detailed below is that regardless of the number of bytes > written to the file, and the success/failure of that operation, the printf > functions (printf, fprintf, wprintf, fwprintf) will always return -1 (EOF). > > * For the case of an unbuffered file, the operation currently fails > transmitting no bytes, and returns -1. > * For the case of a buffered file, the operation transmits all bytes and > the function returns -1. > > The problem is that the behavior here is inconsistent, and should not be. > The question is wether all should be made to fail consistently and > transmit no bytes if __SERR is set on _flags, or if failure should be > determined based on the success of byte transmission, discounting file > state. > > Per the ISO/IEC 9899:201x (C11) Section 7.21.6.1, 14: > > The fprintf function returns the number of characters transmitted, or a > negative value if an output or encoding error occurred. > > My reading of this specification is that success should be determined > based on byte-transmission, and should not factor-in file state. In > addition to the ISO standard, the glibc implementation will reliably > succeed with any error flag set if bytes are successfully transmitted > (although it will transmit partial messages prior to successful conversion, > which is unfortunate). > > The attached patch makes the operation on buffered and unbuffered files > consistent across the affected printf/wprintf functions, determines > success/failure based on successful byte-transmission alone, and preserves > _flags state for __SERR as passed in. > > [...snip] -- regards, matt
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAB%2B9ogeZ3T5k1hCFUDWOn%2Bbbwt_80%2BFm7pJFnTOwZf41RAGgOw>
