On 05/17/2014 01:23 AM, Paul Eggert wrote:
> Pádraig Brady wrote:
>> To me, mbrtowc returning 0 for empty input is not surprising.
>> Also POSIX says for mbr{len,towc} that they shall return 0
>> "If the next n or fewer bytes complete the character that corresponds to the
>> null wide character
>
> At least 1 byte is needed to represent a null wide character. Therefore, zero
> bytes cannot possibly complete a null wide character, which means mbrtowc on
> empty input cannot return 0 if it wants to conform to POSIX and/or C11.
>
> A similar argument shows why mbrtowc can't return (size_t) -1 on empty input:
> it's because you need at least 1 byte to represent an encoding error.
Ah I saw the empty _string_ "" in the test case and got confused.
This is only for the empty _input_ case (n==0). So all good :)
thanks,
Pádraig.