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 <string.h>
  8. #include "local.h"
  9.  
  10. size_t
  11. _DEFUN (_mbrtowc_r, (ptr, pwc, s, n, ps),
  12.         struct _reent *ptr _AND
  13.         wchar_t *pwc _AND
  14.         const char *s _AND
  15.         size_t n _AND
  16.         mbstate_t *ps)
  17. {
  18.   int retval = 0;
  19.  
  20. #ifdef _MB_CAPABLE
  21.   if (ps == NULL)
  22.     {
  23.       _REENT_CHECK_MISC(ptr);
  24.       ps = &(_REENT_MBRTOWC_STATE(ptr));
  25.     }
  26. #endif
  27.  
  28.   if (s == NULL)
  29.     retval = __mbtowc (ptr, NULL, "", 1, __locale_charset (), ps);
  30.   else
  31.     retval = __mbtowc (ptr, pwc, s, n, __locale_charset (), ps);
  32.  
  33.   if (retval == -1)
  34.     {
  35.       ps->__count = 0;
  36.       ptr->_errno = EILSEQ;
  37.       return (size_t)(-1);
  38.     }
  39.   else
  40.     return (size_t)retval;
  41. }
  42.  
  43. #ifndef _REENT_ONLY
  44. size_t
  45. _DEFUN (mbrtowc, (pwc, s, n, ps),
  46.         wchar_t *__restrict pwc _AND
  47.         const char *__restrict s _AND
  48.         size_t n _AND
  49.         mbstate_t *__restrict ps)
  50. {
  51. #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
  52.   return _mbrtowc_r (_REENT, pwc, s, n, ps);
  53. #else
  54.   int retval = 0;
  55.   struct _reent *reent = _REENT;
  56.  
  57. #ifdef _MB_CAPABLE
  58.   if (ps == NULL)
  59.     {
  60.       _REENT_CHECK_MISC(reent);
  61.       ps = &(_REENT_MBRTOWC_STATE(reent));
  62.     }
  63. #endif
  64.  
  65.   if (s == NULL)
  66.     retval = __mbtowc (reent, NULL, "", 1, __locale_charset (), ps);
  67.   else
  68.     retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps);
  69.  
  70.   if (retval == -1)
  71.     {
  72.       ps->__count = 0;
  73.       reent->_errno = EILSEQ;
  74.       return (size_t)(-1);
  75.     }
  76.   else
  77.     return (size_t)retval;
  78. #endif /* not PREFER_SIZE_OVER_SPEED */
  79. }
  80. #endif /* !_REENT_ONLY */
  81.