| OLD | NEW |
| 1 #include "stdio_impl.h" | 1 #include "stdio_impl.h" |
| 2 #include "locale_impl.h" | 2 #include "locale_impl.h" |
| 3 #include <wchar.h> | 3 #include <wchar.h> |
| 4 #include <limits.h> | 4 #include <limits.h> |
| 5 #include <ctype.h> | 5 #include <ctype.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 | 7 |
| 8 wint_t ungetwc(wint_t c, FILE *f) | 8 wint_t ungetwc(wint_t c, FILE* f) { |
| 9 { | 9 unsigned char mbc[MB_LEN_MAX]; |
| 10 » unsigned char mbc[MB_LEN_MAX]; | 10 int l = 1; |
| 11 » int l=1; | 11 locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; |
| 12 » locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; | |
| 13 | 12 |
| 14 » FLOCK(f); | 13 FLOCK(f); |
| 15 | 14 |
| 16 » if (f->mode <= 0) fwide(f, 1); | 15 if (f->mode <= 0) |
| 17 » *ploc = f->locale; | 16 fwide(f, 1); |
| 17 *ploc = f->locale; |
| 18 | 18 |
| 19 » if (!f->rpos) __toread(f); | 19 if (!f->rpos) |
| 20 » if (!f->rpos || f->rpos < f->buf - UNGET + l || c == WEOF || | 20 __toread(f); |
| 21 » (!isascii(c) && (l = wctomb((void *)mbc, c)) < 0)) { | 21 if (!f->rpos || f->rpos < f->buf - UNGET + l || c == WEOF || |
| 22 » » FUNLOCK(f); | 22 (!isascii(c) && (l = wctomb((void*)mbc, c)) < 0)) { |
| 23 » » *ploc = loc; | 23 FUNLOCK(f); |
| 24 » » return WEOF; | 24 *ploc = loc; |
| 25 » } | 25 return WEOF; |
| 26 } |
| 26 | 27 |
| 27 » if (isascii(c)) *--f->rpos = c; | 28 if (isascii(c)) |
| 28 » else memcpy(f->rpos -= l, mbc, l); | 29 *--f->rpos = c; |
| 30 else |
| 31 memcpy(f->rpos -= l, mbc, l); |
| 29 | 32 |
| 30 » f->flags &= ~F_EOF; | 33 f->flags &= ~F_EOF; |
| 31 | 34 |
| 32 » FUNLOCK(f); | 35 FUNLOCK(f); |
| 33 » *ploc = loc; | 36 *ploc = loc; |
| 34 » return c; | 37 return c; |
| 35 } | 38 } |
| OLD | NEW |