1#include <limits.h>2#include <stdio.h>3#include <string.h>4#include <wchar.h>56#undef fputwc78wint_t9_fputwc(wchar_t wc, FILE *fp, int *np)10{11 int n;12 char buf[MB_LEN_MAX];1314 if ((n = wcrtomb(buf, wc, &fp->mbs)) == -1)15 goto err;16 if (fwrite(buf, 1, n, fp) < n)17 goto err;1819 if (np)20 *np = n;2122 return wc;2324err:25 fp->flags |= _IOERR;26 return WEOF;27}2829wint_t30fputwc(wchar_t wc, FILE *fp)31{32 return _fputwc(wc, fp, NULL);33}