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 | 6 |
7 wint_t __fputwc_unlocked(wchar_t c, FILE *f) | 7 wint_t __fputwc_unlocked(wchar_t c, FILE* f) { |
8 { | 8 char mbc[MB_LEN_MAX]; |
9 » char mbc[MB_LEN_MAX]; | 9 int l; |
10 » int l; | 10 locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; |
11 » locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; | |
12 | 11 |
13 » if (f->mode <= 0) fwide(f, 1); | 12 if (f->mode <= 0) |
14 » *ploc = f->locale; | 13 fwide(f, 1); |
| 14 *ploc = f->locale; |
15 | 15 |
16 » if (isascii(c)) { | 16 if (isascii(c)) { |
17 » » c = putc_unlocked(c, f); | 17 c = putc_unlocked(c, f); |
18 » } else if (f->wpos + MB_LEN_MAX < f->wend) { | 18 } else if (f->wpos + MB_LEN_MAX < f->wend) { |
19 » » l = wctomb((void *)f->wpos, c); | 19 l = wctomb((void*)f->wpos, c); |
20 » » if (l < 0) c = WEOF; | 20 if (l < 0) |
21 » » else f->wpos += l; | 21 c = WEOF; |
22 » } else { | 22 else |
23 » » l = wctomb(mbc, c); | 23 f->wpos += l; |
24 » » if (l < 0 || __fwritex((void *)mbc, l, f) < l) c = WEOF; | 24 } else { |
25 » } | 25 l = wctomb(mbc, c); |
26 » if (c==WEOF) f->flags |= F_ERR; | 26 if (l < 0 || __fwritex((void*)mbc, l, f) < l) |
27 » *ploc = loc; | 27 c = WEOF; |
28 » return c; | 28 } |
| 29 if (c == WEOF) |
| 30 f->flags |= F_ERR; |
| 31 *ploc = loc; |
| 32 return c; |
29 } | 33 } |
30 | 34 |
31 wint_t fputwc(wchar_t c, FILE *f) | 35 wint_t fputwc(wchar_t c, FILE* f) { |
32 { | 36 FLOCK(f); |
33 » FLOCK(f); | 37 c = __fputwc_unlocked(c, f); |
34 » c = __fputwc_unlocked(c, f); | 38 FUNLOCK(f); |
35 » FUNLOCK(f); | 39 return c; |
36 » return c; | |
37 } | 40 } |
38 | 41 |
39 weak_alias(__fputwc_unlocked, fputwc_unlocked); | 42 weak_alias(__fputwc_unlocked, fputwc_unlocked); |
40 weak_alias(__fputwc_unlocked, putwc_unlocked); | 43 weak_alias(__fputwc_unlocked, putwc_unlocked); |
OLD | NEW |