Re: [PATCH] newlib: libc: Fix bugs in the commit 3d94e07c49b5.
Takashi Yano <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 10 Nov 2023 17:08:40 +0100
Corinna Vinschen wrote:
> On Nov 10 16:17, Corinna Vinschen wrote:
> > Didn't you forget ungetwc?
> >
> > But then again, I checked GLibC, and there's something weird:
> >
> > ungetc does not at all set or test the orientation.
> >
> > ungetwc sets the orientation to 1, but doesn't check it.
> >
> > Puzzeling. I wonder about the reasoning behind this.
>
> Apparently, ungetwc has been added only later. ungetc, OTOH, was
> defined in a way which allowed to use it on wide-char oriented streams
> as well.
>
> So the stance in GLibC is, for backward compatibility reasons, ungetc
> can't and must not check or set the orientation at all.
>
> The fact that ungetwc doesn't test the orientation might be a bug in
> glibc. We can follow suit (being "bug-compatible" :)), or we can test
> the orientation. Given that using the correctly oriented functions is
> ultimately the responsibility of the application, both ways to handle
> this should be fine.
I noticed that getchar/getwchar/gets etc. in newlib do not set
orientation. For example, both getwchar() and getchar() success
in the following code.
#include <stdio.h>
#include <wchar.h>
int main()
{
wchar_t w;
char c;
w = getwchar();
ungetwc(w, stdin);
c = getchar();
printf("%lc,%c\n", w, c);
return 0;
}
Hmmmmm...
--
Takashi Yano <[email protected]>