diff options
author | Thomas Fitzsimmons <fitzsim@redhat.com> | 2002-08-23 01:56:05 +0000 |
---|---|---|
committer | Thomas Fitzsimmons <fitzsim@redhat.com> | 2002-08-23 01:56:05 +0000 |
commit | 8d9112f2f3ac7c0aa656ceb8da7b4248df228833 (patch) | |
tree | 237c3983e83fb5bd0ccbfff91a30844b7906afd3 /newlib/libc/stdlib | |
parent | 1c5dcf3b0a42efcc8a7fcac148e2714d9766b871 (diff) | |
download | newlib-8d9112f2f3ac7c0aa656ceb8da7b4248df228833.zip newlib-8d9112f2f3ac7c0aa656ceb8da7b4248df228833.tar.gz newlib-8d9112f2f3ac7c0aa656ceb8da7b4248df228833.tar.bz2 |
* libc/include/langinfo.h: New file.
* libc/include/wchar.h: Likewise.
* libc/include/sys/syslimits.h: Likewise.
* libc/locale/fix_grouping.c: Likewise.
* libc/locale/ldpart.c: Likewise.
* libc/locale/ldpart.h: Likewise.
* libc/locale/lmessages.c: Likewise.
* libc/locale/lmessages.h: Likewise.
* libc/locale/lmonetary.c: Likewise.
* libc/locale/lmonetary.h: Likewise.
* libc/locale/lnumeric.c: Likewise.
* libc/locale/lnumeric.h: Likewise.
* libc/locale/nl_langinfo.3: Likewise.
* libc/locale/nl_langinfo.c: Likewise.
* libc/locale/timelocal.c: Likewise.
* libc/locale/timelocal.h: Likewise.
* libc/stdlib/btowc.c: Likewise.
* libc/stdlib/mbrlen.c: Likewise.
* libc/stdlib/mbrtowc.c: Likewise.
* libc/stdlib/mbsinit.c: Likewise.
* libc/stdlib/mbsrtowcs.c: Likewise.
* libc/stdlib/wcrtomb.c: Likewise.
* libc/stdlib/wcsrtombs.c: Likewise.
* libc/stdlib/wctob.c: Likewise.
* libc/sys/linux/prof-freq.c: Likewise.
* libc/sys/linux/profile.c: Likewise.
* libc/sys/linux/machine/i386/dl-procinfo.c: Likewise.
* libc/sys/linux/machine/i386/dl-procinfo.h: Likewise.
* libc/include/stdlib.h: Change re-entrant functions to take
mbstate_t pointers.
* libc/include/sys/_types.h: Define _mbstate_t.
* libc/include/sys/config.h (MB_LEN_MAX): New macro.
* libc/include/sys/errno.h (EILSEQ): New error code.
* libc/include/sys/reent.h: Include wchar.h. Change reentrant
structure to use mbstate_t.
* libc/locale/Makefile.am (LIB_SOURCES): Add new files.
* libc/machine/powerpc/vfprintf.c: Use mbstate_t.
* libc/machine/powerpc/vfscanf.c: Likewise.
* libc/stdio/getdelim.c: Reallocate buffer only when necessary.
* libc/stdio/vfprintf.c: Likewise.
* libc/stdio/vfscanf.c: Likewise.
* libc/stdlib/Makefile.am (LIB_SOURCES): Add new files.
* libc/stdlib/mblen.c: Use mbstate_t.
* libc/stdlib/mblen_r.c: Likewise.
* libc/stdlib/mbstowcs.c: Likewise.
* libc/stdlib/mbstowcs_r.c: Likewise.
* libc/stdlib/mbtowc.c: Likewise.
* libc/stdlib/mbtowc_r.c: Likewise.
* libc/stdlib/wcstombs.c: Likewise.
* libc/stdlib/wcstombs_r.c: Likewise.
* libc/stdlib/wctomb_r.c: Likewise.
* libc/sys/linux/Makefile.am (LIB_SOURCES): Add prof-freq.c and
profile.c.
* libc/sys/linux/machine/i386/Makefile.am (LIB_SOURCES): Add
dl-procinfo.c.
* libc/sys/linux/sys/errno.h (EILSEQ): New error code.
* libc/sys/linux/sys/types.h (off_t): Define type.
* testsuite/newlib.locale/UTF-8.c: Change locale name from UTF-8
to C-UTF-8.
* testsuite/newlib.locale/UTF-8.exp: Likewise.
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r-- | newlib/libc/stdlib/Makefile.am | 10 | ||||
-rw-r--r-- | newlib/libc/stdlib/Makefile.in | 18 | ||||
-rw-r--r-- | newlib/libc/stdlib/btowc.c | 27 | ||||
-rw-r--r-- | newlib/libc/stdlib/mblen.c | 9 | ||||
-rw-r--r-- | newlib/libc/stdlib/mblen_r.c | 3 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbrlen.c | 13 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbrtowc.c | 29 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbsinit.c | 14 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbsrtowcs.c | 24 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbstowcs.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbstowcs_r.c | 5 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbtowc.c | 8 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbtowc_r.c | 35 | ||||
-rw-r--r-- | newlib/libc/stdlib/wcrtomb.c | 25 | ||||
-rw-r--r-- | newlib/libc/stdlib/wcsrtombs.c | 22 | ||||
-rw-r--r-- | newlib/libc/stdlib/wcstombs.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/wcstombs_r.c | 3 | ||||
-rw-r--r-- | newlib/libc/stdlib/wctob.c | 25 | ||||
-rw-r--r-- | newlib/libc/stdlib/wctomb_r.c | 13 |
19 files changed, 256 insertions, 35 deletions
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am index 13608ea..baf3de9 100644 --- a/newlib/libc/stdlib/Makefile.am +++ b/newlib/libc/stdlib/Makefile.am @@ -79,7 +79,15 @@ LIB_SOURCES = \ wcstombs.c \ wcstombs_r.c \ wctomb.c \ - wctomb_r.c + wctomb_r.c \ + btowc.c \ + mbrlen.c \ + mbrtowc.c \ + mbsinit.c \ + mbsrtowcs.c \ + wcrtomb.c \ + wcsrtombs.c \ + wctob.c # Because of how libtool moves objects around, mallocr must be built last. LIBADD_OBJS = freer.$(oext) reallocr.$(oext) callocr.$(oext) cfreer.$(oext) malignr.$(oext) \ diff --git a/newlib/libc/stdlib/Makefile.in b/newlib/libc/stdlib/Makefile.in index 98b64b8..6f7cd98 100644 --- a/newlib/libc/stdlib/Makefile.in +++ b/newlib/libc/stdlib/Makefile.in @@ -185,7 +185,15 @@ LIB_SOURCES = \ wcstombs.c \ wcstombs_r.c \ wctomb.c \ - wctomb_r.c + wctomb_r.c \ + btowc.c \ + mbrlen.c \ + mbrtowc.c \ + mbsinit.c \ + mbsrtowcs.c \ + wcrtomb.c \ + wcsrtombs.c \ + wctob.c # Because of how libtool moves objects around, mallocr must be built last. @@ -294,7 +302,10 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@strtoull_r.$(OBJEXT) system.$(OBJEXT) \ @USE_LIBTOOL_FALSE@valloc.$(OBJEXT) wcstombs.$(OBJEXT) \ @USE_LIBTOOL_FALSE@wcstombs_r.$(OBJEXT) wctomb.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wctomb_r.$(OBJEXT) +@USE_LIBTOOL_FALSE@wctomb_r.$(OBJEXT) btowc.$(OBJEXT) mbrlen.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@mbrtowc.$(OBJEXT) mbsinit.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@mbsrtowcs.$(OBJEXT) wcrtomb.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wcsrtombs.$(OBJEXT) wctob.$(OBJEXT) LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@libstdlib_la_DEPENDENCIES = freer.$(oext) \ @@ -318,7 +329,8 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@strtod.lo strtol.lo strtoll.lo strtoll_r.lo \ @USE_LIBTOOL_TRUE@strtoul.lo strtoull.lo strtoull_r.lo system.lo \ @USE_LIBTOOL_TRUE@valloc.lo wcstombs.lo wcstombs_r.lo wctomb.lo \ -@USE_LIBTOOL_TRUE@wctomb_r.lo +@USE_LIBTOOL_TRUE@wctomb_r.lo btowc.lo mbrlen.lo mbrtowc.lo mbsinit.lo \ +@USE_LIBTOOL_TRUE@mbsrtowcs.lo wcrtomb.lo wcsrtombs.lo wctob.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/stdlib/btowc.c b/newlib/libc/stdlib/btowc.c new file mode 100644 index 0000000..a1ea920 --- /dev/null +++ b/newlib/libc/stdlib/btowc.c @@ -0,0 +1,27 @@ +#include <wchar.h> +#include <stdlib.h> +#include <stdio.h> +#include <reent.h> + +wint_t +btowc (int c) +{ + mbstate_t mbs; + int retval = 0; + wchar_t pwc; + unsigned char b; + + b = (unsigned char)c; + + /* Put mbs in initial state. */ + memset (&mbs, '\0', sizeof (mbs)); + + _REENT_CHECK_MISC(_REENT); + + retval = _mbtowc_r (_REENT, &pwc, &b, 1, &mbs); + + if (c == EOF || retval != 1) + return WEOF; + else + return (wint_t)pwc; +} diff --git a/newlib/libc/stdlib/mblen.c b/newlib/libc/stdlib/mblen.c index c85a6a7..a0ed29a 100644 --- a/newlib/libc/stdlib/mblen.c +++ b/newlib/libc/stdlib/mblen.c @@ -44,6 +44,7 @@ effects vary with the locale. #ifndef _REENT_ONLY #include <stdlib.h> +#include <wchar.h> int _DEFUN (mblen, (s, n), @@ -51,9 +52,15 @@ _DEFUN (mblen, (s, n), size_t n) { #ifdef MB_CAPABLE + int retval = 0; _REENT_CHECK_MISC(_REENT); - return _mbtowc_r (_REENT, NULL, s, n, &(_REENT_MBLEN_STATE(_REENT))); + retval = _mbtowc_r (_REENT, NULL, s, n, &(_REENT_MBLEN_STATE(_REENT))); + if (retval < 0) + return -1; + else + return retval; + #else /* not MB_CAPABLE */ if (s == NULL || *s == '\0') return 0; diff --git a/newlib/libc/stdlib/mblen_r.c b/newlib/libc/stdlib/mblen_r.c index 22d1d40..cff7395 100644 --- a/newlib/libc/stdlib/mblen_r.c +++ b/newlib/libc/stdlib/mblen_r.c @@ -44,13 +44,14 @@ effects vary with the locale. */ #include <stdlib.h> +#include <wchar.h> int _DEFUN (_mblen_r, (r, s, n, state), struct _reent *r _AND const char *s _AND size_t n _AND - int *state) + mbstate_t *state) { #ifdef MB_CAPABLE diff --git a/newlib/libc/stdlib/mbrlen.c b/newlib/libc/stdlib/mbrlen.c new file mode 100644 index 0000000..8f0c648 --- /dev/null +++ b/newlib/libc/stdlib/mbrlen.c @@ -0,0 +1,13 @@ +#include <wchar.h> +#include <stdlib.h> +#include <stdio.h> +#include <reent.h> +#include <errno.h> + +size_t +mbrlen(const char *s, size_t n, mbstate_t *ps) +{ + mbstate_t internal; + + return mbrtowc(NULL, s, n, ps != NULL ? ps : &internal); +} diff --git a/newlib/libc/stdlib/mbrtowc.c b/newlib/libc/stdlib/mbrtowc.c new file mode 100644 index 0000000..7934ca1 --- /dev/null +++ b/newlib/libc/stdlib/mbrtowc.c @@ -0,0 +1,29 @@ +#include <wchar.h> +#include <stdlib.h> +#include <stdio.h> +#include <reent.h> +#include <errno.h> +#include <string.h> + +size_t +mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) +{ + int retval = 0; + _REENT_CHECK_MISC(_REENT); + + if (s == NULL) + retval = _mbtowc_r (_REENT, pwc, "", 1, ps); + else + retval = _mbtowc_r (_REENT, pwc, s, n, ps); + + if (*pwc == NULL) + memset (ps, '\0', sizeof (mbstate_t)); + + if (retval == -1) + { + _REENT->_errno = EILSEQ; + return (size_t)(-1); + } + else + return (size_t)retval; +} diff --git a/newlib/libc/stdlib/mbsinit.c b/newlib/libc/stdlib/mbsinit.c new file mode 100644 index 0000000..a353cb1 --- /dev/null +++ b/newlib/libc/stdlib/mbsinit.c @@ -0,0 +1,14 @@ +#include <wchar.h> +#include <stdlib.h> +#include <stdio.h> +#include <reent.h> +#include <errno.h> + +int +mbsinit(const mbstate_t *ps) +{ + if (ps == NULL || ps->__count == 0) + return 1; + else + return 0; +} diff --git a/newlib/libc/stdlib/mbsrtowcs.c b/newlib/libc/stdlib/mbsrtowcs.c new file mode 100644 index 0000000..256ab0d --- /dev/null +++ b/newlib/libc/stdlib/mbsrtowcs.c @@ -0,0 +1,24 @@ +#include <wchar.h> +#include <stdlib.h> +#include <stdio.h> +#include <reent.h> +#include <errno.h> + +size_t +mbsrtowcs(wchar_t *dst, const char **src, size_t len, mbstate_t *ps) +{ + int retval = 0; + mbstate_t internal; + + _REENT_CHECK_MISC(_REENT); + + retval = _mbstowcs_r (_REENT, dst, *src, len, ps != NULL ? ps : &internal); + + if (retval == -1) + { + _REENT->_errno = EILSEQ; + return (size_t)(-1); + } + else + return (size_t)retval; +} diff --git a/newlib/libc/stdlib/mbstowcs.c b/newlib/libc/stdlib/mbstowcs.c index fee621a..eb0ccd7 100644 --- a/newlib/libc/stdlib/mbstowcs.c +++ b/newlib/libc/stdlib/mbstowcs.c @@ -50,6 +50,7 @@ effects vary with the locale. #ifndef _REENT_ONLY #include <stdlib.h> +#include <wchar.h> size_t _DEFUN (mbstowcs, (pwcs, s, n), @@ -58,7 +59,8 @@ _DEFUN (mbstowcs, (pwcs, s, n), size_t n) { #ifdef MB_CAPABLE - int state = 0; + mbstate_t state; + state.__count = 0; return _mbstowcs_r (_REENT, pwcs, s, n, &state); #else /* not MB_CAPABLE */ diff --git a/newlib/libc/stdlib/mbstowcs_r.c b/newlib/libc/stdlib/mbstowcs_r.c index 5478849..89cda03 100644 --- a/newlib/libc/stdlib/mbstowcs_r.c +++ b/newlib/libc/stdlib/mbstowcs_r.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <wchar.h> size_t _DEFUN (_mbstowcs_r, (reent, pwcs, s, n, state), @@ -6,7 +7,7 @@ _DEFUN (_mbstowcs_r, (reent, pwcs, s, n, state), wchar_t *pwcs _AND const char *s _AND size_t n _AND - int *state) + mbstate_t *state) { wchar_t *ptr = pwcs; size_t max = n; @@ -16,7 +17,7 @@ _DEFUN (_mbstowcs_r, (reent, pwcs, s, n, state), while (n > 0) { bytes = _mbtowc_r (r, ptr, t, MB_CUR_MAX, state); - if (bytes == -1) + if (bytes < 0) return -1; else if (bytes == 0) return ptr - pwcs; diff --git a/newlib/libc/stdlib/mbtowc.c b/newlib/libc/stdlib/mbtowc.c index 0d16f0d..6da735a 100644 --- a/newlib/libc/stdlib/mbtowc.c +++ b/newlib/libc/stdlib/mbtowc.c @@ -60,9 +60,15 @@ _DEFUN (mbtowc, (pwc, s, n), size_t n) { #ifdef MB_CAPABLE + int retval = 0; _REENT_CHECK_MISC(_REENT); - return _mbtowc_r (_REENT, pwc, s, n, &(_REENT_MBTOWC_STATE(_REENT))); + retval = _mbtowc_r (_REENT, pwc, s, n, &(_REENT_MBTOWC_STATE(_REENT))); + + if (retval < 0) + return -1; + else + return retval; #else /* not MB_CAPABLE */ if (s == NULL) return 0; diff --git a/newlib/libc/stdlib/mbtowc_r.c b/newlib/libc/stdlib/mbtowc_r.c index 866789f..b7909d3 100644 --- a/newlib/libc/stdlib/mbtowc_r.c +++ b/newlib/libc/stdlib/mbtowc_r.c @@ -1,6 +1,8 @@ #include <stdlib.h> #include <locale.h> #include "mbctype.h" +#include <wchar.h> +#include <string.h> #ifdef MB_CAPABLE typedef enum { ESCAPE, DOLLAR, BRACKET, AT, B, J, @@ -51,7 +53,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), wchar_t *pwc _AND const char *s _AND size_t n _AND - int *state) + mbstate_t *state) { wchar_t dummy; unsigned char *t = (unsigned char *)s; @@ -60,13 +62,13 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), pwc = &dummy; if (s != NULL && n == 0) - return -1; + return -2; #ifdef MB_CAPABLE if (r->_current_locale == NULL || (strlen (r->_current_locale) <= 1)) { /* fall-through */ } - else if (!strcmp (r->_current_locale, "UTF-8")) + else if (!strcmp (r->_current_locale, "C-UTF-8")) { wchar_t char1 = 0; @@ -139,7 +141,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), return 3; } else - return -1; + return -2; } else if (char1 >= 0xf0 && char1 <= 0xf7) { @@ -172,7 +174,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), return 4; } else - return -1; + return -2; } else if (char1 >= 0xf8 && char1 <= 0xfb) { @@ -208,7 +210,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), return 5; } else - return -1; + return -2; } else if (char1 >= 0xfc && char1 <= 0xfd) { @@ -248,7 +250,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), return 6; } else - return -1; + return -2; } else return -1; @@ -263,7 +265,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), { int char2 = t[1]; if (n <= 1) - return -1; + return -2; if (_issjis2 (char2)) { *pwc = (((wchar_t)*t) << 8) + (wchar_t)(*(t+1)); @@ -283,7 +285,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), { int char2 = t[1]; if (n <= 1) - return -1; + return -2; if (_iseucjp (char2)) { *pwc = (((wchar_t)*t) << 8) + (wchar_t)(*(t+1)); @@ -303,11 +305,11 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), if (s == NULL) { - *state = 0; + state->__count = 0; return 1; /* state-dependent */ } - curr_state = (*state == 0 ? ASCII : JIS); + curr_state = (state->__count == 0 ? ASCII : JIS); ptr = t; for (i = 0; i < n; ++i) @@ -351,19 +353,19 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), case NOOP: break; case EMPTY: - *state = 0; + state->__count = 0; *pwc = (wchar_t)0; return i; case COPY_A: - *state = 0; + state->__count = 0; *pwc = (wchar_t)*ptr; return (i + 1); case COPY_J: - *state = 0; + state->__count = 0; *pwc = (((wchar_t)*ptr) << 8) + (wchar_t)(*(ptr+1)); return (i + 1); case COPY_J2: - *state = 1; + state->__count = 1; *pwc = (((wchar_t)*ptr) << 8) + (wchar_t)(*(ptr+1)); return (ptr - t) + 2; case MAKE_A: @@ -377,7 +379,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), } - return -1; /* n < bytes needed */ + return -2; /* n < bytes needed */ } #endif /* MB_CAPABLE */ @@ -392,4 +394,3 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state), return 1; } - diff --git a/newlib/libc/stdlib/wcrtomb.c b/newlib/libc/stdlib/wcrtomb.c new file mode 100644 index 0000000..f68533c --- /dev/null +++ b/newlib/libc/stdlib/wcrtomb.c @@ -0,0 +1,25 @@ +#include <wchar.h> +#include <stdlib.h> +#include <stdio.h> +#include <reent.h> +#include <errno.h> + +size_t +wcrtomb(char *s, wchar_t wc, mbstate_t *ps) +{ + int retval = 0; + _REENT_CHECK_MISC(_REENT); + + if (s == NULL) + retval = _wctomb_r (_REENT, "", wc, ps); + else + retval = _wctomb_r (_REENT, s, wc, ps); + + if (retval == -1) + { + _REENT->_errno = EILSEQ; + return (size_t)(-1); + } + else + return (size_t)retval; +} diff --git a/newlib/libc/stdlib/wcsrtombs.c b/newlib/libc/stdlib/wcsrtombs.c new file mode 100644 index 0000000..22512c0 --- /dev/null +++ b/newlib/libc/stdlib/wcsrtombs.c @@ -0,0 +1,22 @@ +#include <wchar.h> +#include <stdlib.h> +#include <stdio.h> +#include <reent.h> +#include <errno.h> + +size_t +wcsrtombs (char *dst, const wchar_t **src, size_t len, mbstate_t *ps) +{ + int retval = 0; + _REENT_CHECK_MISC(_REENT); + + retval = _wcstombs_r (_REENT, dst, *src, len, ps); + + if (retval == -1) + { + _REENT->_errno = EILSEQ; + return (size_t)(-1); + } + else + return (size_t)retval; +} diff --git a/newlib/libc/stdlib/wcstombs.c b/newlib/libc/stdlib/wcstombs.c index ca99f2e..c984746 100644 --- a/newlib/libc/stdlib/wcstombs.c +++ b/newlib/libc/stdlib/wcstombs.c @@ -51,6 +51,7 @@ effects vary with the locale. #ifndef _REENT_ONLY #include <stdlib.h> +#include <wchar.h> size_t _DEFUN (wcstombs, (s, pwcs, n), @@ -59,7 +60,8 @@ _DEFUN (wcstombs, (s, pwcs, n), size_t n) { #ifdef MB_CAPABLE - int state = 0; + mbstate_t state; + state.__count = 0; return _wcstombs_r (_REENT, s, pwcs, n, &state); #else /* not MB_CAPABLE */ diff --git a/newlib/libc/stdlib/wcstombs_r.c b/newlib/libc/stdlib/wcstombs_r.c index 69c82d4..70f680a 100644 --- a/newlib/libc/stdlib/wcstombs_r.c +++ b/newlib/libc/stdlib/wcstombs_r.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <wchar.h> size_t _DEFUN (_wcstombs_r, (reent, s, pwcs, n, state), @@ -6,7 +7,7 @@ _DEFUN (_wcstombs_r, (reent, s, pwcs, n, state), char *s _AND const wchar_t *pwcs _AND size_t n _AND - int *state) + mbstate_t *state) { char *ptr = s; size_t max = n; diff --git a/newlib/libc/stdlib/wctob.c b/newlib/libc/stdlib/wctob.c new file mode 100644 index 0000000..4288c54 --- /dev/null +++ b/newlib/libc/stdlib/wctob.c @@ -0,0 +1,25 @@ +#include <wchar.h> +#include <wchar.h> +#include <stdlib.h> +#include <stdio.h> +#include <reent.h> + +int +wctob (wint_t c) +{ + mbstate_t mbs; + int retval = 0; + unsigned char pwc; + + /* Put mbs in initial state. */ + memset (&mbs, '\0', sizeof (mbs)); + + _REENT_CHECK_MISC(_REENT); + + retval = _wctomb_r (_REENT, &pwc, c, &mbs); + + if (c == EOF || retval != 1) + return WEOF; + else + return (int)pwc; +} diff --git a/newlib/libc/stdlib/wctomb_r.c b/newlib/libc/stdlib/wctomb_r.c index 991e0a6..7cd84b6 100644 --- a/newlib/libc/stdlib/wctomb_r.c +++ b/newlib/libc/stdlib/wctomb_r.c @@ -1,5 +1,6 @@ #include <stdlib.h> #include <string.h> +#include <wchar.h> #include <locale.h> #include "mbctype.h" @@ -8,11 +9,11 @@ _DEFUN (_wctomb_r, (r, s, wchar, state), struct _reent *r _AND char *s _AND wchar_t wchar _AND - int *state) + mbstate_t *state) { if (strlen (r->_current_locale) <= 1) { /* fall-through */ } - else if (!strcmp (r->_current_locale, "UTF-8")) + else if (!strcmp (r->_current_locale, "C-UTF-8")) { if (s == NULL) return 0; /* UTF-8 encoding is not state-dependent */ @@ -125,10 +126,10 @@ _DEFUN (_wctomb_r, (r, s, wchar, state), /* first byte is non-zero..validate multi-byte char */ if (_isjis (char1) && _isjis (char2)) { - if (*state == 0) + if (state->__count == 0) { /* must switch from ASCII to JIS state */ - *state = 1; + state->__count = 1; *s++ = ESC_CHAR; *s++ = '$'; *s++ = 'B'; @@ -143,10 +144,10 @@ _DEFUN (_wctomb_r, (r, s, wchar, state), } else { - if (*state != 0) + if (state->__count != 0) { /* must switch from JIS to ASCII state */ - *state = 0; + state->__count = 0; *s++ = ESC_CHAR; *s++ = '('; *s++ = 'B'; |