This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ECOS] wcstombs


Jonathan Larmour wrote:

Sorry, you're right - that's a different nuance than is normally used for these types of things. I'll correct that now.

Patch below.


Jifl

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/i18n/current/ChangeLog,v
retrieving revision 1.9
diff -u -5 -p -r1.9 ChangeLog
--- ChangeLog   10 Aug 2006 13:20:06 -0000      1.9
+++ ChangeLog   11 Aug 2006 12:15:02 -0000
@@ -1,5 +1,10 @@
+2006-08-11  Jonathan Larmour  <jifl@eCosCentric.com>
+
+       * src/wcstombs.cxx (wcstombs): Previous change should have
+       disregarded 'n'. Now fixed. Thanks to Klaas Gadeyne.
+
 2006-08-10  Jonathan Larmour  <jifl@eCosCentric.com>

* src/wcstombs.cxx (wcstombs): Follow Single Unix Spec
and if string is NULL, return chars that would have been
returned.
Index: src/wcstombs.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/i18n/current/src/wcstombs.cxx,v
retrieving revision 1.4
diff -u -5 -p -r1.4 wcstombs.cxx
--- src/wcstombs.cxx 10 Aug 2006 13:20:06 -0000 1.4
+++ src/wcstombs.cxx 11 Aug 2006 12:15:02 -0000
@@ -89,11 +89,11 @@ This implementation of <<wcstombs>> retu
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. If <[s]> is <<NULL>> it returns the number of
-bytes that would have been transferred.
+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
 string will be modified to contain a wchar_t nul terminator if
 <<n>> > 0.
@@ -194,19 +194,22 @@ wcstombs ( char *s, const wchar_t *pwcs,
 #endif /* CYGINT_LIBC_I18N_MB_REQUIRED */

   int count = 0;
   char c;

-  if (n != 0) {
-    do {
-      c = (char) *pwcs++;
-      if (s)
-        *s++ = c;
-      if (0 == c)
-        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;
   CYG_REPORT_RETVAL( retval );
   return retval;

--
eCosCentric    http://www.eCosCentric.com/    The eCos and RedBoot experts
------["The best things in life aren't things."]------      Opinions==mine


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]