2003-12-05 14:13:44 +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>
|
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
|
|
|
_wcrtomb_r (struct _reent *ptr,
|
2017-12-04 09:31:41 +08:00
|
|
|
char *s,
|
|
|
|
wchar_t wc,
|
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
|
|
|
char buf[10];
|
|
|
|
|
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_WCRTOMB_STATE(ptr));
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-23 09:56:05 +08:00
|
|
|
|
|
|
|
if (s == NULL)
|
2016-07-21 04:05:59 +08:00
|
|
|
retval = __WCTOMB (ptr, buf, L'\0', ps);
|
2002-08-23 09:56:05 +08:00
|
|
|
else
|
2016-07-21 04:05:59 +08:00
|
|
|
retval = __WCTOMB (ptr, s, wc, 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
|
|
|
wcrtomb (char *__restrict s,
|
2017-12-04 09:31:41 +08:00
|
|
|
wchar_t wc,
|
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 _wcrtomb_r (_REENT, s, wc, 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
|
|
|
char buf[10];
|
|
|
|
|
|
|
|
#ifdef _MB_CAPABLE
|
|
|
|
if (ps == NULL)
|
|
|
|
{
|
2013-04-30 05:06:23 +08:00
|
|
|
_REENT_CHECK_MISC(reent);
|
|
|
|
ps = &(_REENT_WCRTOMB_STATE(reent));
|
2009-11-18 17:49:57 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (s == NULL)
|
2016-07-21 04:05:59 +08:00
|
|
|
retval = __WCTOMB (reent, buf, L'\0', ps);
|
2009-11-18 17:49:57 +08:00
|
|
|
else
|
2016-07-21 04:05:59 +08:00
|
|
|
retval = __WCTOMB (reent, s, wc, 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 */
|