One line fix for _citrus_none_ctype_wcrtomb

2013-03-07 Thread Vladimir Támara Patiño
Working on collations again (based on FreeBSD implementation) and reading 
wcrtomb I see that return value of wcrtomb should be either positive or 
(size_t)-1, then:


diff -ruN src53orig/lib/libc/citrus/citrus_none.c
src53coll/lib/libc/citrus/citr
us_none.c
--- src53orig/lib/libc/citrus/citrus_none.c Sat Feb  9 14:26:51 2013
+++ src53coll/lib/libc/citrus/citrus_none.c Sat Mar  2 06:59:58 2013
@@ -115,7 +115,7 @@
/* ps appears to be unused */

if (s == NULL)
-   return (0);
+   return (1);

if (wc  0 || wc  0xff) {
errno = EILSEQ;



--
Dios, gracias por tu amor infinito.
--  
 Vladimir Támara Patiño.  http://vtamara.pasosdeJesus.org/

 http://www.pasosdejesus.org/dominio_publico_colombia.html



Re: One line fix for _citrus_none_ctype_wcrtomb

2013-03-07 Thread Stefan Sperling
On Thu, Mar 07, 2013 at 10:51:13AM -0500, Vladimir Támara Patiño wrote:
 Working on collations again (based on FreeBSD implementation) and
 reading wcrtomb I see that return value of wcrtomb should be
 either positive or (size_t)-1, then:
 
 diff -ruN src53orig/lib/libc/citrus/citrus_none.c
 src53coll/lib/libc/citrus/citr
 us_none.c
 --- src53orig/lib/libc/citrus/citrus_none.c Sat Feb  9 14:26:51 2013
 +++ src53coll/lib/libc/citrus/citrus_none.c Sat Mar  2 06:59:58 2013
 @@ -115,7 +115,7 @@
 /* ps appears to be unused */
 
   if (s == NULL)
 -   return (0);
 +   return (1);
 
   if (wc  0 || wc  0xff) {
   errno = EILSEQ;
 

It's perfectly fine to return zero according to
http://pubs.opengroup.org/onlinepubs/009695399/functions/wcrtomb.html
  The wcrtomb() function shall return the number of bytes stored in the
  array object (including any shift sequences).

But our man page is unclear. I guess we could fix the man page.

Index: wcrtomb.3
===
RCS file: /cvs/src/lib/libc/locale/wcrtomb.3,v
retrieving revision 1.4
diff -u -p -r1.4 wcrtomb.3
--- wcrtomb.3   26 Mar 2010 19:30:41 -  1.4
+++ wcrtomb.3   7 Mar 2013 16:33:06 -
@@ -103,17 +103,15 @@ which is initialized at startup time of 
 .\ --
 .Sh RETURN VALUES
 .Fn wcrtomb
-returns:
-.Bl -tag -width 012345678901
-.It positive
-The number of bytes (including any shift sequences)
-which are stored in the array.
-.It (size_t)-1
+returns the number of bytes (including any shift sequences)
+which are stored in the array pointed to by
+.Fa s .
+If
 .Fa wc
-is not a valid wide character.
-In this case,
+is not a valid wide character,
 .Fn wcrtomb
-also sets
+returns (size_t)-1
+and sets
 .Va errno
 to indicate error.
 .El



Re: One line fix for _citrus_none_ctype_wcrtomb

2013-03-07 Thread Philip Guenther
On Thu, Mar 7, 2013 at 8:36 AM, Stefan Sperling s...@openbsd.org wrote:
 On Thu, Mar 07, 2013 at 10:51:13AM -0500, Vladimir Támara Patiño wrote:
 Working on collations again (based on FreeBSD implementation) and
 reading wcrtomb I see that return value of wcrtomb should be
 either positive or (size_t)-1, then:
...
 --- src53orig/lib/libc/citrus/citrus_none.c Sat Feb  9 14:26:51 2013
 +++ src53coll/lib/libc/citrus/citrus_none.c Sat Mar  2 06:59:58 2013
 @@ -115,7 +115,7 @@
 /* ps appears to be unused */

   if (s == NULL)
 -   return (0);
 +   return (1);

 It's perfectly fine to return zero according to
 http://pubs.opengroup.org/onlinepubs/009695399/functions/wcrtomb.html
   The wcrtomb() function shall return the number of bytes stored in the
   array object (including any shift sequences).

Ah, but that has to be read in light of the description section, which says:

If s is a null pointer, the wcrtomb() function shall be equivalent
to the call:

wcrtomb(buf, L'\0', ps)

where buf is an internal buffer.

Since that call returns 1 when you pass in a buffer of your own,
wcrtomb(NULL, whatever, ps) should return 1 too.


Philip Guenther



Re: One line fix for _citrus_none_ctype_wcrtomb

2013-03-07 Thread Stefan Sperling
On Thu, Mar 07, 2013 at 09:40:40AM -0800, Philip Guenther wrote:
 On Thu, Mar 7, 2013 at 8:36 AM, Stefan Sperling s...@openbsd.org wrote:
  On Thu, Mar 07, 2013 at 10:51:13AM -0500, Vladimir Támara Patiño wrote:
  Working on collations again (based on FreeBSD implementation) and
  reading wcrtomb I see that return value of wcrtomb should be
  either positive or (size_t)-1, then:
 ...
  --- src53orig/lib/libc/citrus/citrus_none.c Sat Feb  9 14:26:51 2013
  +++ src53coll/lib/libc/citrus/citrus_none.c Sat Mar  2 06:59:58 2013
  @@ -115,7 +115,7 @@
  /* ps appears to be unused */
 
if (s == NULL)
  -   return (0);
  +   return (1);
 
  It's perfectly fine to return zero according to
  http://pubs.opengroup.org/onlinepubs/009695399/functions/wcrtomb.html
The wcrtomb() function shall return the number of bytes stored in the
array object (including any shift sequences).
 
 Ah, but that has to be read in light of the description section, which says:
 
 If s is a null pointer, the wcrtomb() function shall be equivalent
 to the call:
 
 wcrtomb(buf, L'\0', ps)
 
 where buf is an internal buffer.
 
 Since that call returns 1 when you pass in a buffer of your own,
 wcrtomb(NULL, whatever, ps) should return 1 too.
 
 
 Philip Guenther

Right. Thanks for pointing that out.
In fact, the UTF-8 implementation also returns 1 in this case.
So I'm fine with Vladimir's change.