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