Subversion Repositories Kolibri OS

Rev

Rev 4874 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <reent.h>
  2. #include <newlib.h>
  3. #include <wchar.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <errno.h>
  7. #include "local.h"
  8.  
  9. size_t
  10. _DEFUN (_wcrtomb_r, (ptr, s, wc, ps),
  11.         struct _reent *ptr _AND
  12.         char *s _AND
  13.         wchar_t wc _AND
  14.         mbstate_t *ps)
  15. {
  16.   int retval = 0;
  17.   char buf[10];
  18.  
  19. #ifdef _MB_CAPABLE
  20.   if (ps == NULL)
  21.     {
  22.       _REENT_CHECK_MISC(ptr);
  23.       ps = &(_REENT_WCRTOMB_STATE(ptr));
  24.     }
  25. #endif
  26.  
  27.   if (s == NULL)
  28.     retval = __wctomb (ptr, buf, L'\0', __locale_charset (), ps);
  29.   else
  30.     retval = __wctomb (ptr, s, wc, __locale_charset (), ps);
  31.  
  32.   if (retval == -1)
  33.     {
  34.       ps->__count = 0;
  35.       ptr->_errno = EILSEQ;
  36.       return (size_t)(-1);
  37.     }
  38.   else
  39.     return (size_t)retval;
  40. }
  41.  
  42. #ifndef _REENT_ONLY
  43. size_t
  44. _DEFUN (wcrtomb, (s, wc, ps),
  45.         char *__restrict s _AND
  46.         wchar_t wc _AND
  47.         mbstate_t *__restrict ps)
  48. {
  49. #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
  50.   return _wcrtomb_r (_REENT, s, wc, ps);
  51. #else
  52.   int retval = 0;
  53.   struct _reent *reent = _REENT;
  54.   char buf[10];
  55.  
  56. #ifdef _MB_CAPABLE
  57.   if (ps == NULL)
  58.     {
  59.       _REENT_CHECK_MISC(reent);
  60.       ps = &(_REENT_WCRTOMB_STATE(reent));
  61.     }
  62. #endif
  63.  
  64.   if (s == NULL)
  65.     retval = __wctomb (reent, buf, L'\0', __locale_charset (), ps);
  66.   else
  67.     retval = __wctomb (reent, s, wc, __locale_charset (), ps);
  68.  
  69.   if (retval == -1)
  70.     {
  71.       ps->__count = 0;
  72.       reent->_errno = EILSEQ;
  73.       return (size_t)(-1);
  74.     }
  75.   else
  76.     return (size_t)retval;
  77. #endif /* not PREFER_SIZE_OVER_SPEED */
  78. }
  79. #endif /* !_REENT_ONLY */
  80.