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


Klaas Gadeyne wrote:
On Wed, 9 Aug 2006, Jonathan Larmour wrote:
Klaas Gadeyne wrote:
So the next question: Is there reason why the implementation is not
conform the Single unix spec?

The short answer: eCos is not UNIX.


The longer answer: eCos does try to comply with C90 and C99 (although it doesn't by a long way with the latter), and selected parts of POSIX. UNIX compatibility is a "would be nice" thing, but not if it means adding bells and whistles that just bloat code until eCos slowly grows to be the size of UNIX. Therefore bells and whistles that only exist in the SUS are unlikely to be implemented.

Then, only for those who are interested: The following patch works fine for me (without too much code bloat I hope :-), but please check...

It isn't right as it disregards n. I've checked in the attached patch. Update your CVS and check it's ok.


Jifl

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/i18n/current/ChangeLog,v
retrieving revision 1.8
diff -u -5 -p -r1.8 ChangeLog
--- ChangeLog   3 Aug 2005 20:53:09 -0000       1.8
+++ ChangeLog   10 Aug 2006 13:18:49 -0000
@@ -1,5 +1,11 @@
+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.
+
 2005-07-30  Andrew Lunn  <andrew.lunn@ascom.ch>

* tests/i18nmb.c (main): Really silence the warnings.

2004-02-17 Jonathan Larmour <jifl@eCosCentric.com>
Index: src/wcstombs.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/i18n/current/src/wcstombs.cxx,v
retrieving revision 1.3
diff -u -5 -p -r1.3 wcstombs.cxx
--- src/wcstombs.cxx 23 May 2002 23:07:07 -0000 1.3
+++ src/wcstombs.cxx 10 Aug 2006 13:18:49 -0000
@@ -83,16 +83,17 @@ repeatedly to perform the conversion, pa
decoding. The result is based on the locale setting which may
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.

 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.
@@ -191,15 +192,19 @@ wcstombs ( char *s, const wchar_t *pwcs,
       return retval;
     }
 #endif /* CYGINT_LIBC_I18N_MB_REQUIRED */

   int count = 0;
+  char c;

   if (n != 0) {
     do {
-      if ((*s++ = (char) *pwcs++) == 0)
-       break;
+      c = (char) *pwcs++;
+      if (s)
+        *s++ = c;
+      if (0 == c)
+        break;
       count++;
     } while (--n != 0);
   }

retval = count;

--
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]