This is the mail archive of the
mailing list for the newlib project.
Re: What's the behavior if we fprintf chars to a wide orient file stream?
- From: Corinna Vinschen <vinschen at redhat dot com>
- To: newlib at sourceware dot org
- Date: Fri, 2 Aug 2013 09:48:44 +0200
- Subject: Re: What's the behavior if we fprintf chars to a wide orient file stream?
- References: <CANnWgkAggZoT6s8UshS+=jS7WtdB8oMZ3eKL22H-VyrayXNCLQ at mail dot gmail dot com>
- Reply-to: newlib at sourceware dot org
On Aug 2 10:33, Can Finner wrote:
> 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.