> It seems to be that the MSL lib implements the mbstowcs function
> differently from Apple's implementation in case the first pointer is NULL.
> Apple's implementation seems to return the length of the "in"-string
> while MSL always returns 0. When looking at Apple's man pages even
> (size_t) -1 should be returned.
Where does it say that?
> Now, what is the right functionality?
I haven't got the C99 specification to hand, but this is the relevant
part of the Single Unix definition for the function:
> RETURN VALUE
> If an invalid character is encountered, mbstowcs() returns (size_t)-1 and may
> set errno to indicate the error. Otherwise, mbstowcs() returns the number of
> the array elements modified (or required if pwcs is null), not including a
> terminating 0 code, if any. The array will not be zero-terminated if the
> value returned is n.
<http://www.opengroup.org/onlinepubs/007908799/xsh/mbstowcs.html>
Note the words in brackets: 'or required if pwcs is null'.
Alwyn
Hartwig Wiesmann - 06 Jan 2006 17:39 GMT
Hi Alwyn,
Apple says:
The mbstowcs() function returns the number of wide characters converted,
not counting any terminating null wide character, or -1 if an invalid
multibyte character was encountered.
Sorry, misread. Actually zero should be returned as no characters are
converted when the wchar* pointer is NULL.
Your definition would return the length of the byte character sequence.
MSL always returns 0 when a NULL pointer is passed to mbstowcs.
Hartwig
>>It seems to be that the MSL lib implements the mbstowcs function
>>differently from Apple's implementation in case the first pointer is NULL.
[quoted text clipped - 21 lines]
>
> Alwyn