2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<mbstowcs>>---minimal multibyte string to wide char converter
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
mbstowcs
|
|
|
|
|
2017-11-30 16:17:18 +08:00
|
|
|
SYNOPSIS
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <stdlib.h>
|
2013-11-18 Sahil Patnayakuni <sahilp@oarcorp.com>
* libc/include/stdlib.h, libc/stdlib/mbstowcs.c,
libc/stdlib/mbstowcs_r.c, libc/stdlib/mbtowc.c,
libc/stdlib/mbtowc_r.c, libc/stdlib/strtod.c,
libc/stdlib/strtol.c, libc/stdlib/strtold.c,
libc/stdlib/strtoll.c, libc/stdlib/strtoll_r.c,
libc/stdlib/strtoul.c, libc/stdlib/strtoull.c,
libc/stdlib/strtoull_r.c, libc/stdlib/wcstombs.c,
libc/stdlib/wcstombs_r.c: Add restrict keyword.
2013-11-19 01:26:52 +08:00
|
|
|
int mbstowcs(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
DESCRIPTION
|
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
|
|
|
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
|
2000-02-18 03:39:52 +08:00
|
|
|
implementation of <<mbstowcs>>. In this case, the
|
|
|
|
only ``multi-byte character sequences'' recognized are single bytes,
|
|
|
|
and they are ``converted'' to wide-char versions simply by byte
|
|
|
|
extension.
|
|
|
|
|
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
|
|
|
When _MB_CAPABLE is defined, this routine calls <<_mbstowcs_r>> to perform
|
2000-02-18 03:39:52 +08:00
|
|
|
the conversion, passing a state variable to allow state dependent
|
|
|
|
decoding. The result is based on the locale setting which may
|
|
|
|
be restricted to a defined set of locales.
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
This implementation of <<mbstowcs>> returns <<0>> if
|
|
|
|
<[s]> is <<NULL>> or is the empty string;
|
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
|
|
|
it returns <<-1>> if _MB_CAPABLE and one of the
|
2000-02-18 03:39:52 +08:00
|
|
|
multi-byte characters is invalid or incomplete;
|
|
|
|
otherwise it returns the minimum of: <<n>> or the
|
|
|
|
number of multi-byte characters in <<s>> plus 1 (to
|
|
|
|
compensate for the nul character).
|
|
|
|
If the return value is -1, the state of the <<pwc>> string is
|
|
|
|
indeterminate. If the input has a length of 0, the output
|
|
|
|
string will be modified to contain a wchar_t nul terminator.
|
|
|
|
|
|
|
|
PORTABILITY
|
|
|
|
<<mbstowcs>> is required in the ANSI C standard. However, the precise
|
|
|
|
effects vary with the locale.
|
|
|
|
|
|
|
|
<<mbstowcs>> requires no supporting OS subroutines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
|
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>
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <stdlib.h>
|
2002-08-23 09:56:05 +08:00
|
|
|
#include <wchar.h>
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
size_t
|
|
|
|
_DEFUN (mbstowcs, (pwcs, s, n),
|
2013-11-18 Sahil Patnayakuni <sahilp@oarcorp.com>
* libc/include/stdlib.h, libc/stdlib/mbstowcs.c,
libc/stdlib/mbstowcs_r.c, libc/stdlib/mbtowc.c,
libc/stdlib/mbtowc_r.c, libc/stdlib/strtod.c,
libc/stdlib/strtol.c, libc/stdlib/strtold.c,
libc/stdlib/strtoll.c, libc/stdlib/strtoll_r.c,
libc/stdlib/strtoul.c, libc/stdlib/strtoull.c,
libc/stdlib/strtoull_r.c, libc/stdlib/wcstombs.c,
libc/stdlib/wcstombs_r.c: Add restrict keyword.
2013-11-19 01:26:52 +08:00
|
|
|
wchar_t *__restrict pwcs _AND
|
|
|
|
const char *__restrict s _AND
|
2000-02-18 03:39:52 +08:00
|
|
|
size_t n)
|
|
|
|
{
|
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
|
|
|
mbstate_t state;
|
|
|
|
state.__count = 0;
|
|
|
|
|
|
|
|
return _mbstowcs_r (_REENT, pwcs, s, n, &state);
|
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
|
|
|
#else /* not _MB_CAPABLE */
|
2002-09-10 05:42:14 +08:00
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (n != 0) {
|
|
|
|
do {
|
|
|
|
if ((*pwcs++ = (wchar_t) *s++) == 0)
|
|
|
|
break;
|
|
|
|
count++;
|
|
|
|
} while (--n != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
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
|
|
|
#endif /* not _MB_CAPABLE */
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !_REENT_ONLY */
|