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.

Thanks for the typo fix, by the way.


Reply via email to