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>
|
|
|
|
|
|
|
|
size_t
|
2002-09-10 05:42:14 +08:00
|
|
|
_DEFUN (_wcsrtombs_r, (r, dst, src, len, ps),
|
|
|
|
struct _reent *r _AND
|
|
|
|
char *dst _AND
|
|
|
|
const wchar_t **src _AND
|
|
|
|
size_t len _AND
|
|
|
|
mbstate_t *ps)
|
2002-08-23 09:56:05 +08:00
|
|
|
{
|
2002-09-10 05:42:14 +08:00
|
|
|
char *ptr = dst;
|
|
|
|
char buff[10];
|
2003-11-06 08:46:59 +08:00
|
|
|
wchar_t *pwcs;
|
|
|
|
size_t n;
|
|
|
|
int i;
|
2002-08-23 09:56:05 +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(r);
|
|
|
|
ps = &(_REENT_WCSRTOMBS_STATE(r));
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-23 09:56:05 +08:00
|
|
|
|
2003-11-06 08:46:59 +08:00
|
|
|
/* If no dst pointer, treat len as maximum possible value. */
|
|
|
|
if (dst == NULL)
|
|
|
|
len = (size_t)-1;
|
2002-09-10 05:42:14 +08:00
|
|
|
|
2003-11-06 08:46:59 +08:00
|
|
|
n = 0;
|
|
|
|
pwcs = (wchar_t *)(*src);
|
|
|
|
|
|
|
|
while (n < len)
|
2002-08-23 09:56:05 +08:00
|
|
|
{
|
2002-09-10 05:42:14 +08:00
|
|
|
int count = ps->__count;
|
|
|
|
wint_t wch = ps->__value.__wch;
|
2004-01-22 04:09:16 +08:00
|
|
|
int bytes = _wcrtomb_r (r, buff, *pwcs, ps);
|
2002-09-10 05:42:14 +08:00
|
|
|
if (bytes == -1)
|
|
|
|
{
|
|
|
|
r->_errno = EILSEQ;
|
|
|
|
ps->__count = 0;
|
|
|
|
return (size_t)-1;
|
|
|
|
}
|
2008-08-29 01:36:49 +08:00
|
|
|
if (n + bytes <= len)
|
2002-09-10 05:42:14 +08:00
|
|
|
{
|
2003-11-06 08:46:59 +08:00
|
|
|
n += bytes;
|
|
|
|
if (dst)
|
|
|
|
{
|
|
|
|
for (i = 0; i < bytes; ++i)
|
|
|
|
*ptr++ = buff[i];
|
|
|
|
++(*src);
|
|
|
|
}
|
|
|
|
if (*pwcs++ == 0x00)
|
2002-09-10 05:42:14 +08:00
|
|
|
{
|
2003-11-06 08:46:59 +08:00
|
|
|
if (dst)
|
|
|
|
*src = NULL;
|
2002-09-10 05:42:14 +08:00
|
|
|
ps->__count = 0;
|
2003-11-06 08:46:59 +08:00
|
|
|
return n - 1;
|
2002-09-10 05:42:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* not enough room, we must back up state to before _wctomb_r call */
|
|
|
|
ps->__count = count;
|
|
|
|
ps->__value.__wch = wch;
|
2003-11-06 08:46:59 +08:00
|
|
|
len = 0;
|
2002-09-10 05:42:14 +08:00
|
|
|
}
|
2002-08-23 09:56:05 +08:00
|
|
|
}
|
2002-09-10 05:42:14 +08:00
|
|
|
|
2003-11-06 08:46:59 +08:00
|
|
|
return n;
|
2002-09-10 05:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
size_t
|
|
|
|
_DEFUN (wcsrtombs, (dst, src, len, ps),
|
|
|
|
char *dst _AND
|
|
|
|
const wchar_t **src _AND
|
|
|
|
size_t len _AND
|
|
|
|
mbstate_t *ps)
|
|
|
|
{
|
|
|
|
return _wcsrtombs_r (_REENT, dst, src, len, ps);
|
2002-08-23 09:56:05 +08:00
|
|
|
}
|
2002-09-10 05:42:14 +08:00
|
|
|
#endif /* !_REENT_ONLY */
|