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 -0000 1.4
+++ wcrtomb.3 7 Mar 2013 16:33:06 -0000
@@ -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