What's the behavior if we fprintf chars to a wide orient file stream?

Corinna Vinschen vinschen@redhat.com
Fri Aug 2 07:48:00 GMT 2013


On Aug  2 10:33, Can Finner wrote:
> Hi,
> I noticed that vfprintf calls to __sprint_r/__sfputs_r in newlib and
> function __sprint_r checks whether the file stream has wide
> orientation.  It seems if we fprintf chars to a wide orient file, we
> will get wrong output characters because consecutive chars are treated
> as wchar.
> 
> So the first question is: Is this undefined behavior?
> 
> Furthermore, if it is undefined behavior, could we split __sprint_r
> into two versions each for vfprintf and vfwprintf, and don't support
> wide char in the version for vfprintf.  If this can be done, the newly
> added --disable-newlib-wide-orient option can be cleaned up, meanwhile
> code size of vfprintf can be kept small.
> 
> Thanks in advance for your explanation.

The behaviour with respect to wide oriented streams is based on the
POSIX requirements and the implmentation follows closely one of the BSDs
(I just don't recall which one ATM, probably FreeBSD).  If you see a
behaviour deviation from POSIX, testcases and patches are welcome.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat



More information about the Newlib mailing list