]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/language/c/libc/i18n/v2_0/src/wcstombs.cxx
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / language / c / libc / i18n / v2_0 / src / wcstombs.cxx
index dce94caceb23a7a509176874de7b2343301d1024..dd75754f1e517e894a280a56dc625248c65c81bb 100644 (file)
@@ -85,12 +85,13 @@ be restricted to a defined set of locales.
 
 RETURNS
 This implementation of <<wcstombs>> returns <<0>> if
-<[s]> is <<NULL>> or is the empty string; 
+<[s]> is the empty string;
 it returns <<-1>> if CYGINT_LIBC_I18N_MB_REQUIRED and one of the
 wide-char characters does not represent a valid multi-byte character;
 otherwise it returns the minimum of: <<n>> or the
 number of bytes that are transferred to <<s>>, not including the
-nul terminator.
+nul terminator. If <[s]> is <<NULL>> it returns the number of
+bytes that would have been transferred, regardless of <<[n]>>.
 
 If the return value is -1, the state of the <<pwc>> string is
 indeterminate.  If the input has a length of 0, the output
@@ -194,12 +195,18 @@ wcstombs ( char *s, const wchar_t *pwcs, size_t n )
   
   int count = 0;
 
-  if (n != 0) {
-    do {
-      if ((*s++ = (char) *pwcs++) == 0)
-       break;
-      count++;
-    } while (--n != 0);
+  if (s == NULL) {
+      while (*pwcs++ != 0) {
+          count++;
+      }
+  } else {
+      if (n != 0) {
+          do {
+              if ((*s++ = (char) *pwcs++) == 0) 
+                  break;
+              count++;
+          } while (--n != 0);
+      }
   }
   
   retval = count;