2003-12-05 14:02:31 +08:00
|
|
|
#include <reent.h>
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* configure.in: Define _MB_CAPABLE if mb supported.
* configure: Regenerated.
* configure.host: Remove manual setting of MB_CAPABLE compiler
flag.
* newlib.hin: Add _MB_CAPABLE flag.
* libc/ctype/iswalpha.c, libc/ctype/iswblank.c: Include <newlib.h>
and check for _MB_CAPABLE flag instead of MB_CAPABLE.
* libc/ctype/iswcntrl.c, libc/ctype/iswprint.c: Ditto.
* libc/ctype/iswpunct.c, libc/ctype/iswspace.c: Ditto.
* libc/ctype/jp2uc.c: Ditto.
* libc/ctype/towlower.c, libc/ctype/towupper.c: Ditto.
* libc/locale/locale.c: Ditto
* libc/machine/powerpc/vfscanf.c: Ditto
* libc/stdio/vfprintf.c, libc/stdio/vfscanf.c: Ditto
* libc/stdlib/mblen.c: Ditto
* libc/stdlib/mblen_r.c, libc/stdlib/mbrlen.c: Ditto
* libc/stdlib/mbrtowc.c, libc/stdlib/mbsrtowcs.c: Ditto
* libc/stdlib/mbstowcs.c, libc/stdlib/mbtowc.c: Ditto
* libc/stdlib/mbtowc_r.c, libc/stdlib/wcrtomb.c: Ditto
* libc/stdlib/wcsrtombs.c, libc/stdlib/wcstombs.c: Ditto
* libc/stdlib/wctomb.c, libc/sys/linux/intl/dcigettext.c: Ditto
* libc/sys/linux/intl/explodename.c: Ditto
* libc/sys/linux/intl/finddomain.c: Ditto
* libc/sys/linux/intl/l10nflist.c: Ditto
* libc/sys/linux/intl/loadmsgcat.c: Ditto
* libc/sys/linux/intl/localealias.c: Ditto
2004-04-24 05:44:22 +08:00
|
|
|
#include <newlib.h>
|
2002-08-23 09:56:05 +08:00
|
|
|
#include <wchar.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2009-11-18 17:49:57 +08:00
|
|
|
#include "local.h"
|
2002-08-23 09:56:05 +08:00
|
|
|
|
|
|
|
size_t
|
2017-12-04 11:43:30 +08:00
|
|
|
_mbrtowc_r (struct _reent *ptr,
|
2017-12-04 09:31:41 +08:00
|
|
|
wchar_t *pwc,
|
|
|
|
const char *s,
|
|
|
|
size_t n,
|
2002-09-10 05:42:14 +08:00
|
|
|
mbstate_t *ps)
|
2002-08-23 09:56:05 +08:00
|
|
|
{
|
|
|
|
int retval = 0;
|
2002-09-10 05:42:14 +08:00
|
|
|
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* configure.in: Define _MB_CAPABLE if mb supported.
* configure: Regenerated.
* configure.host: Remove manual setting of MB_CAPABLE compiler
flag.
* newlib.hin: Add _MB_CAPABLE flag.
* libc/ctype/iswalpha.c, libc/ctype/iswblank.c: Include <newlib.h>
and check for _MB_CAPABLE flag instead of MB_CAPABLE.
* libc/ctype/iswcntrl.c, libc/ctype/iswprint.c: Ditto.
* libc/ctype/iswpunct.c, libc/ctype/iswspace.c: Ditto.
* libc/ctype/jp2uc.c: Ditto.
* libc/ctype/towlower.c, libc/ctype/towupper.c: Ditto.
* libc/locale/locale.c: Ditto
* libc/machine/powerpc/vfscanf.c: Ditto
* libc/stdio/vfprintf.c, libc/stdio/vfscanf.c: Ditto
* libc/stdlib/mblen.c: Ditto
* libc/stdlib/mblen_r.c, libc/stdlib/mbrlen.c: Ditto
* libc/stdlib/mbrtowc.c, libc/stdlib/mbsrtowcs.c: Ditto
* libc/stdlib/mbstowcs.c, libc/stdlib/mbtowc.c: Ditto
* libc/stdlib/mbtowc_r.c, libc/stdlib/wcrtomb.c: Ditto
* libc/stdlib/wcsrtombs.c, libc/stdlib/wcstombs.c: Ditto
* libc/stdlib/wctomb.c, libc/sys/linux/intl/dcigettext.c: Ditto
* libc/sys/linux/intl/explodename.c: Ditto
* libc/sys/linux/intl/finddomain.c: Ditto
* libc/sys/linux/intl/l10nflist.c: Ditto
* libc/sys/linux/intl/loadmsgcat.c: Ditto
* libc/sys/linux/intl/localealias.c: Ditto
2004-04-24 05:44:22 +08:00
|
|
|
#ifdef _MB_CAPABLE
|
2002-09-10 05:42:14 +08:00
|
|
|
if (ps == NULL)
|
|
|
|
{
|
|
|
|
_REENT_CHECK_MISC(ptr);
|
|
|
|
ps = &(_REENT_MBRTOWC_STATE(ptr));
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-23 09:56:05 +08:00
|
|
|
|
|
|
|
if (s == NULL)
|
2016-07-21 04:05:59 +08:00
|
|
|
retval = __MBTOWC (ptr, NULL, "", 1, ps);
|
2002-08-23 09:56:05 +08:00
|
|
|
else
|
2016-07-21 04:05:59 +08:00
|
|
|
retval = __MBTOWC (ptr, pwc, s, n, ps);
|
2002-08-23 09:56:05 +08:00
|
|
|
|
|
|
|
if (retval == -1)
|
|
|
|
{
|
2002-09-10 05:42:14 +08:00
|
|
|
ps->__count = 0;
|
|
|
|
ptr->_errno = EILSEQ;
|
2002-08-23 09:56:05 +08:00
|
|
|
return (size_t)(-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (size_t)retval;
|
|
|
|
}
|
2002-09-10 05:42:14 +08:00
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
size_t
|
2017-12-04 11:43:30 +08:00
|
|
|
mbrtowc (wchar_t *__restrict pwc,
|
2017-12-04 09:31:41 +08:00
|
|
|
const char *__restrict s,
|
|
|
|
size_t n,
|
2013-11-27 01:21:01 +08:00
|
|
|
mbstate_t *__restrict ps)
|
2002-09-10 05:42:14 +08:00
|
|
|
{
|
2009-11-18 17:49:57 +08:00
|
|
|
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
|
2002-09-10 05:42:14 +08:00
|
|
|
return _mbrtowc_r (_REENT, pwc, s, n, ps);
|
2009-11-18 17:49:57 +08:00
|
|
|
#else
|
|
|
|
int retval = 0;
|
2013-04-30 05:06:23 +08:00
|
|
|
struct _reent *reent = _REENT;
|
2009-11-18 17:49:57 +08:00
|
|
|
|
|
|
|
#ifdef _MB_CAPABLE
|
|
|
|
if (ps == NULL)
|
|
|
|
{
|
2013-04-30 05:06:23 +08:00
|
|
|
_REENT_CHECK_MISC(reent);
|
|
|
|
ps = &(_REENT_MBRTOWC_STATE(reent));
|
2009-11-18 17:49:57 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (s == NULL)
|
2016-07-21 04:05:59 +08:00
|
|
|
retval = __MBTOWC (reent, NULL, "", 1, ps);
|
2009-11-18 17:49:57 +08:00
|
|
|
else
|
2016-07-21 04:05:59 +08:00
|
|
|
retval = __MBTOWC (reent, pwc, s, n, ps);
|
2009-11-18 17:49:57 +08:00
|
|
|
|
|
|
|
if (retval == -1)
|
|
|
|
{
|
|
|
|
ps->__count = 0;
|
2013-04-30 05:06:23 +08:00
|
|
|
reent->_errno = EILSEQ;
|
2009-11-18 17:49:57 +08:00
|
|
|
return (size_t)(-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (size_t)retval;
|
|
|
|
#endif /* not PREFER_SIZE_OVER_SPEED */
|
2002-09-10 05:42:14 +08:00
|
|
|
}
|
|
|
|
#endif /* !_REENT_ONLY */
|