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
|
|
|
|
Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store
thread-specific data. This object is returned by __getreent() if the
__DYNAMIC_REENT__ Newlib configuration option is defined.
The reentrancy structure contains for example errno and the standard input,
output, and error file streams. This means that if an application only uses
errno it has a dependency on the file stream support even if it does not use
it. This is an issue for lower end targets and applications which need to
qualify the software according to safety standards (for example ECSS-E-ST-40C,
ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333).
If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct
_reent is replaced by dedicated thread-local objects for each struct _reent
member. The thread-local objects are defined in translation units which use
the corresponding object.
2022-05-16 17:51:54 +08:00
|
|
|
#ifdef _REENT_THREAD_LOCAL
|
|
|
|
_Thread_local _mbstate_t _tls_mbrtowc_state;
|
|
|
|
#endif
|
|
|
|
|
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;
|
2022-01-18 17:13:04 +08:00
|
|
|
_REENT_ERRNO(ptr) = 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;
|
2022-01-18 17:13:04 +08:00
|
|
|
_REENT_ERRNO(reent) = 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 */
|