1 #include "locale_impl.h"
2 #include "stdio_impl.h"
3 #include <wchar.h>
4
fputws(const wchar_t * restrict ws,FILE * restrict f)5 int fputws(const wchar_t* restrict ws, FILE* restrict f) {
6 unsigned char buf[BUFSIZ];
7 size_t l = 0;
8 locale_t *ploc = &CURRENT_LOCALE, loc = *ploc;
9
10 FLOCK(f);
11
12 fwide(f, 1);
13 *ploc = f->locale;
14
15 while (ws && (l = wcsrtombs((void*)buf, (void*)&ws, sizeof buf, 0)) + 1 > 1)
16 if (__fwritex(buf, l, f) < l) {
17 FUNLOCK(f);
18 *ploc = loc;
19 return -1;
20 }
21
22 FUNLOCK(f);
23
24 *ploc = loc;
25 return l; /* 0 or -1 */
26 }
27
28 weak_alias(fputws, fputws_unlocked);
29