/* * Non-MT-safe version. */ wint_t __fputwc(wchar_t wc, FILE *fp) { char buf[MB_LEN_MAX]; size_t i, len; if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) { /* * Assume single-byte locale with no special encoding. * A more careful test would be to check * _CurrentRuneLocale->encoding. */ *buf = (unsigned char)wc; len = 1; } else { if ((len = __wcrtomb(buf, wc, &fp->_mbstate)) == (size_t)-1) { fp->_flags |= __SERR; return (WEOF); } } for (i = 0; i < len; i++) if (__sputc((unsigned char)buf[i], fp) == EOF) return (WEOF); return ((wint_t)wc); }
size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) { static mbstate_t mbs; if (ps == NULL) ps = &mbs; return (__wcrtomb(s, wc, ps)); }
int __wctomb_chk (char *s, wchar_t wchar, size_t buflen) { /* We do not have to implement the full wctomb semantics since we know that S cannot be NULL when we come here. */ if (buflen < MB_CUR_MAX) __chk_fail (); return __wcrtomb (s, wchar, &__wctomb_state); }
int wctomb(char *s, wchar_t wchar) { static const mbstate_t initial; static mbstate_t mbs; size_t rval; if (s == NULL) { /* No support for state dependent encodings. */ mbs = initial; return (0); } if ((rval = __wcrtomb(s, wchar, &mbs)) == (size_t)-1) return (-1); return ((int)rval); }
/* * Non-MT-safe version. */ wint_t __ungetwc(wint_t wc, FILE *fp) { char buf[MB_LEN_MAX]; size_t len; if (wc == WEOF) return (WEOF); if ((len = __wcrtomb(buf, wc, &fp->_mbstate)) == (size_t)-1) { fp->_flags |= __SERR; return (WEOF); } while (len-- != 0) if (__ungetc((unsigned char)buf[len], fp) == EOF) return (WEOF); return (wc); }
size_t _Locale_wctomb(struct _Locale_ctype *l, char *to, size_t n, const wchar_t c, mbstate_t *shift_state) { char buf [MB_LEN_MAX]; int ret; char* mb = buf; ret = __wcrtomb(mb, c, shift_state); if (ret > n) return (size_t)-2; else if (ret <= 0) return ret; n = ret; while (n--) *to++ = *mb++; return ret; }
/* Convert WCHAR into its multibyte character representation, putting this in S and returning its length. Attention: this function should NEVER be intentionally used. The interface is completely stupid. The state is shared between all conversion functions. You should use instead the restartable version `wcrtomb'. */ int wctomb (char *s, wchar_t wchar) { /* If S is NULL the function has to return null or not null depending on the encoding having a state depending encoding or not. */ if (s == NULL) { const struct gconv_fcts *fcts; /* Get the conversion functions. */ fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE)); /* This is an extension in the Unix standard which does not directly violate ISO C. */ memset (&__wctomb_state, '\0', sizeof __wctomb_state); return fcts->tomb->__stateful; } return __wcrtomb (s, wchar, &__wctomb_state); }
/* * Non-MT-safe version. */ wint_t __ungetwc(wint_t wc, FILE *fp) { char buf[MB_LEN_MAX]; size_t len; if (wc == WEOF) return (WEOF); #ifndef __SYMBIAN32__ if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) == (size_t)-1) { #else //__SYMBIAN32__ if ((len = wcrtomb(buf, wc, &fp->_extra->mbstate)) == (size_t)-1) { #endif //__SYMBIAN32__ fp->_flags |= __SERR; return (WEOF); } while (len-- != 0) if (__ungetc((unsigned char)buf[len], fp) == EOF) return (WEOF); return (wc); } /* * MT-safe version. */ EXPORT_C wint_t ungetwc(wint_t wc, FILE *fp) { wint_t r; FLOCKFILE(fp); ORIENT(fp, 1); r = __ungetwc(wc, fp); FUNLOCKFILE(fp); return (r); }