fputwc.c (421B)
1 #include <limits.h> 2 #include <stdio.h> 3 #include <string.h> 4 #include <wchar.h> 5 6 #undef fputwc 7 8 wint_t 9 _fputwc(wchar_t wc, FILE *fp, int *np) 10 { 11 int n; 12 char buf[MB_LEN_MAX]; 13 14 if ((n = wcrtomb(buf, wc, NULL)) == -1) 15 goto err; 16 if (fwrite(buf, 1, n, fp) < n) 17 goto err; 18 19 if (np) 20 *np = n; 21 22 return wc; 23 24 err: 25 fp->flags |= _IOERR; 26 return WEOF; 27 } 28 29 wint_t 30 fputwc(wchar_t wc, FILE *fp) 31 { 32 return _fputwc(wc, fp, NULL); 33 }