1 /* 2 Copyright (c) 2002 Thomas Fitzsimmons <fitzsim@redhat.com> 3 */ 4 #include <newlib.h> 5 #include <wchar.h> 6 #include <stdlib.h> 7 #include <stdio.h> 8 #include <errno.h> 9 #include "local.h" 10 11 #ifndef _REENT_ONLY 12 size_t wcrtomb(char * __restrict s,wchar_t wc,mbstate_t * __restrict ps)13wcrtomb (char *__restrict s, 14 wchar_t wc, 15 mbstate_t *__restrict ps) 16 { 17 int retval = 0; 18 char buf[10]; 19 20 #ifdef _MB_CAPABLE 21 if (ps == NULL) 22 { 23 static NEWLIB_THREAD_LOCAL mbstate_t _wcrtomb_state; 24 ps = &_wcrtomb_state; 25 } 26 #endif 27 28 if (s == NULL) 29 retval = __WCTOMB (buf, L'\0', ps); 30 else 31 retval = __WCTOMB (s, wc, ps); 32 33 if (retval == -1) 34 { 35 ps->__count = 0; 36 _REENT_ERRNO(reent) = EILSEQ; 37 return (size_t)(-1); 38 } 39 else 40 return (size_t)retval; 41 } 42 #endif /* !_REENT_ONLY */ 43