diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2007-10-23 19:50:29 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2007-10-23 19:50:29 +0000 |
commit | 2a3a02a6876422425fc3ca94bffd54103328a457 (patch) | |
tree | 1fb7ee7a1c1c378291859a34dd13d2685149a6ab /newlib/libc/stdlib/wcstombs_r.c | |
parent | 09ecdc85044c736c25ac58c0f37b3fb5394c2733 (diff) | |
download | newlib-2a3a02a6876422425fc3ca94bffd54103328a457.zip newlib-2a3a02a6876422425fc3ca94bffd54103328a457.tar.gz newlib-2a3a02a6876422425fc3ca94bffd54103328a457.tar.bz2 |
2007-10-23 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdlib/wcstombs_r.c: Add SUSV2 support for calculating
size if output buffer is NULL.
Diffstat (limited to 'newlib/libc/stdlib/wcstombs_r.c')
-rw-r--r-- | newlib/libc/stdlib/wcstombs_r.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/newlib/libc/stdlib/wcstombs_r.c b/newlib/libc/stdlib/wcstombs_r.c index 70f680a..dd82bd3 100644 --- a/newlib/libc/stdlib/wcstombs_r.c +++ b/newlib/libc/stdlib/wcstombs_r.c @@ -14,20 +14,29 @@ _DEFUN (_wcstombs_r, (reent, s, pwcs, n, state), char buff[8]; int i, num_to_copy; - while (n > 0) + if (s == NULL) { - int bytes = _wctomb_r (r, buff, *pwcs, state); - if (bytes == -1) - return -1; - num_to_copy = (n > bytes ? bytes : (int)n); - for (i = 0; i < num_to_copy; ++i) - *ptr++ = buff[i]; + size_t num_bytes = 0; + while (*pwcs != 0) + num_bytes += _wctomb_r (r, buff, *pwcs++, state); + return num_bytes; + } + else + { + while (n > 0) + { + int bytes = _wctomb_r (r, buff, *pwcs, state); + if (bytes == -1) + return -1; + num_to_copy = (n > bytes ? bytes : (int)n); + for (i = 0; i < num_to_copy; ++i) + *ptr++ = buff[i]; - if (*pwcs == 0x00) - return ptr - s - (n >= bytes); - ++pwcs; - n -= num_to_copy; + if (*pwcs == 0x00) + return ptr - s - (n >= bytes); + ++pwcs; + n -= num_to_copy; + } + return max; } - - return max; } |