Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2007-10-23 23:50:29 +0400
committerJeff Johnston <jjohnstn@redhat.com>2007-10-23 23:50:29 +0400
commit2a3a02a6876422425fc3ca94bffd54103328a457 (patch)
tree1fb7ee7a1c1c378291859a34dd13d2685149a6ab
parent09ecdc85044c736c25ac58c0f37b3fb5394c2733 (diff)
2007-10-23 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdlib/wcstombs_r.c: Add SUSV2 support for calculating size if output buffer is NULL.
-rw-r--r--newlib/ChangeLog5
-rw-r--r--newlib/libc/stdlib/wcstombs_r.c35
2 files changed, 27 insertions, 13 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 6cc23b77c..f8609cb10 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,8 @@
+2007-10-23 Jeff Johnston <jjohnstn@redhat.com>
+
+ * libc/stdlib/wcstombs_r.c: Add SUSV2 support for calculating
+ size if output buffer is NULL.
+
2007-10-17 Jeff Johnston <jjohnstn@redhat.com>
* libm/mathfp/s_logarithm.c: Fix error introduced by previous
diff --git a/newlib/libc/stdlib/wcstombs_r.c b/newlib/libc/stdlib/wcstombs_r.c
index 70f680a82..dd82bd383 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;
}