projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix mismatched signatures for strtod_l family
[musl]
/
src
/
stdio
/
fgetwc.c
diff --git
a/src/stdio/fgetwc.c
b/src/stdio/fgetwc.c
index
5e42059
..
aa10b81
100644
(file)
--- a/
src/stdio/fgetwc.c
+++ b/
src/stdio/fgetwc.c
@@
-1,40
+1,57
@@
#include "stdio_impl.h"
#include "stdio_impl.h"
+#include "locale_impl.h"
+#include <wchar.h>
+#include <errno.h>
-
wint_t __fgetwc_unlocked
(FILE *f)
+
static wint_t __fgetwc_unlocked_internal
(FILE *f)
{
{
- mbstate_t st = { 0 };
wchar_t wc;
int c;
wchar_t wc;
int c;
- unsigned char b;
size_t l;
size_t l;
- f->mode |= f->mode+1;
-
/* Convert character from buffer if possible */
/* Convert character from buffer if possible */
- if (f->rpos
<
f->rend) {
- l = mb
rtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st
);
- if (l+
2 >= 2
) {
+ if (f->rpos
!=
f->rend) {
+ l = mb
towc(&wc, (void *)f->rpos, f->rend - f->rpos
);
+ if (l+
1 >= 1
) {
f->rpos += l + !l; /* l==0 means 1 byte, null */
return wc;
}
f->rpos += l + !l; /* l==0 means 1 byte, null */
return wc;
}
- if (l == -1) {
- f->rpos++;
- return WEOF;
- }
- } else l = -2;
+ }
/* Convert character byte-by-byte */
/* Convert character byte-by-byte */
- while (l == -2) {
+ mbstate_t st = { 0 };
+ unsigned char b;
+ int first = 1;
+ do {
b = c = getc_unlocked(f);
if (c < 0) {
b = c = getc_unlocked(f);
if (c < 0) {
- if (!mbsinit(&st)) errno = EILSEQ;
+ if (!first) {
+ f->flags |= F_ERR;
+ errno = EILSEQ;
+ }
return WEOF;
}
l = mbrtowc(&wc, (void *)&b, 1, &st);
return WEOF;
}
l = mbrtowc(&wc, (void *)&b, 1, &st);
- if (l == -1) return WEOF;
- }
+ if (l == -1) {
+ if (!first) {
+ f->flags |= F_ERR;
+ ungetc(b, f);
+ }
+ return WEOF;
+ }
+ first = 0;
+ } while (l == -2);
- FUNLOCK(f);
+ return wc;
+}
+
+wint_t __fgetwc_unlocked(FILE *f)
+{
+ locale_t *ploc = &CURRENT_LOCALE, loc = *ploc;
+ if (f->mode <= 0) fwide(f, 1);
+ *ploc = f->locale;
+ wchar_t wc = __fgetwc_unlocked_internal(f);
+ *ploc = loc;
return wc;
}
return wc;
}