diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2004-01-21 20:09:16 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2004-01-21 20:09:16 +0000 |
commit | 7d4be1efd53045983acf1d00041e70086d2c029f (patch) | |
tree | 4cdad2387f6d331569ee13de4c171122bb6cb65e /newlib/libc | |
parent | a1dcf5d848c38877dad8c76bc295811d25dbf1d8 (diff) | |
download | newlib-7d4be1efd53045983acf1d00041e70086d2c029f.zip newlib-7d4be1efd53045983acf1d00041e70086d2c029f.tar.gz newlib-7d4be1efd53045983acf1d00041e70086d2c029f.tar.bz2 |
2004-01-21 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdlib/mbrtowc.c (_mbrtowc_r): Fix case where s is null
pointer to match C99 spec.
* libc/stdlib/mbsrtowcs.c (_mbsrtowc_r): Fix to ignore len when
dst is NULL. Also fix to not alter src pointer when dst is NULL
and call _mbrtowc_r instead of _mbtowc_r.
* libc/stdlib/wcsrtombs.c (_wcsrtombs_r): Call _wcrtomb_r instead
of _wctomb_r.
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/stdlib/mbrtowc.c | 2 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbsrtowcs.c | 21 | ||||
-rw-r--r-- | newlib/libc/stdlib/wcsrtombs.c | 2 |
3 files changed, 19 insertions, 6 deletions
diff --git a/newlib/libc/stdlib/mbrtowc.c b/newlib/libc/stdlib/mbrtowc.c index 6bf2087..3a96592 100644 --- a/newlib/libc/stdlib/mbrtowc.c +++ b/newlib/libc/stdlib/mbrtowc.c @@ -24,7 +24,7 @@ _DEFUN (_mbrtowc_r, (ptr, pwc, s, n, ps), #endif if (s == NULL) - retval = _mbtowc_r (ptr, pwc, "", 1, ps); + retval = _mbtowc_r (ptr, NULL, "", 1, ps); else retval = _mbtowc_r (ptr, pwc, s, n, ps); diff --git a/newlib/libc/stdlib/mbsrtowcs.c b/newlib/libc/stdlib/mbsrtowcs.c index 10d3a72..d050bf8 100644 --- a/newlib/libc/stdlib/mbsrtowcs.c +++ b/newlib/libc/stdlib/mbsrtowcs.c @@ -13,7 +13,9 @@ _DEFUN (_mbsrtowcs_r, (r, dst, src, n, ps), mbstate_t *ps) { wchar_t *ptr = dst; - size_t max = n; + const char *tmp_src; + size_t max; + size_t count = 0; int bytes; #ifdef MB_CAPABLE @@ -24,13 +26,24 @@ _DEFUN (_mbsrtowcs_r, (r, dst, src, n, ps), } #endif + if (dst == NULL) + { + /* Ignore original n value and do not alter src pointer if the + dst pointer is NULL. */ + n = (size_t)-1; + tmp_src = *src; + src = &tmp_src; + } + + max = n; while (n > 0) { - bytes = _mbtowc_r (r, ptr, *src, MB_CUR_MAX, ps); + bytes = _mbrtowc_r (r, ptr, *src, MB_CUR_MAX, ps); if (bytes > 0) { *src += bytes; - ++ptr; + ++count; + ptr = (dst == NULL) ? NULL : ptr + 1; --n; } else if (bytes == -2) @@ -40,7 +53,7 @@ _DEFUN (_mbsrtowcs_r, (r, dst, src, n, ps), else if (bytes == 0) { *src = NULL; - return (size_t)(ptr - dst); + return count; } else { diff --git a/newlib/libc/stdlib/wcsrtombs.c b/newlib/libc/stdlib/wcsrtombs.c index 11fdf92..8c55b08 100644 --- a/newlib/libc/stdlib/wcsrtombs.c +++ b/newlib/libc/stdlib/wcsrtombs.c @@ -37,7 +37,7 @@ _DEFUN (_wcsrtombs_r, (r, dst, src, len, ps), { int count = ps->__count; wint_t wch = ps->__value.__wch; - int bytes = _wctomb_r (r, buff, *pwcs, ps); + int bytes = _wcrtomb_r (r, buff, *pwcs, ps); if (bytes == -1) { r->_errno = EILSEQ; |