initial check-in, version 0.5.0
[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                 if (c != f->lbf && f->wpos + 1 < f->wend) *f->wpos++ = c;
12                 else c = __overflow(f, c);
13         } else if (f->wpos + MB_LEN_MAX < f->wend) {
14                 l = wctomb(f->wpos, c);
15                 if (l < 0) c = WEOF;
16                 else f->wpos += l;
17         } else {
18                 l = wctomb(mbc, c);
19                 if (l < 0 || __fwritex(mbc, l, f) < l) c = WEOF;
20         }
21         return c;
22 }
23
24 wint_t fputwc(wchar_t c, FILE *f)
25 {
26         FLOCK(f);
27         c = __fputwc_unlocked(c, f);
28         FUNLOCK(f);
29         return 0;
30 }
31
32 weak_alias(__fputwc_unlocked, fputwc_unlocked);
33 weak_alias(__fputwc_unlocked, putwc_unlocked);