major stdio overhaul, using readv/writev, plus other changes
[musl] / src / stdio / fputwc.c
1 #include "stdio_impl.h"
2
3 wint_t __fputwc_unlocked(wchar_t c, FILE *f)
4 {
5         char mbc[MB_LEN_MAX];
6         int l;
7
8         f->mode |= f->mode+1;
9
10         if (isascii(c)) {
11                 c = putc_unlocked(c, f);
12         } else if (f->wpos + MB_LEN_MAX < f->wend) {
13                 l = wctomb((void *)f->wpos, c);
14                 if (l < 0) c = WEOF;
15                 else f->wpos += l;
16         } else {
17                 l = wctomb(mbc, c);
18                 if (l < 0 || __fwritex((void *)mbc, l, f) < l) c = WEOF;
19         }
20         return c;
21 }
22
23 wint_t fputwc(wchar_t c, FILE *f)
24 {
25         FLOCK(f);
26         c = __fputwc_unlocked(c, f);
27         FUNLOCK(f);
28         return 0;
29 }
30
31 weak_alias(__fputwc_unlocked, fputwc_unlocked);
32 weak_alias(__fputwc_unlocked, putwc_unlocked);