6689 mbtowc(3C) fails to set errno for incomplete characters
Review Request #415 - Created March 27, 2017 and submitted
Quoting the bug reports/OpenBSD's commit message:If an incomplete character is passed to mbtowc(3), set errno to EILSEQ. This is unambiguously required both by POSIX and by our own manual page. It also makes a lot of sense because having a function that can fail and that sets errno in some failure modes but does not set errno in other failure modes would be a terrible idea. Such a function would be ridiculously complicated to use. To detect the reason for failure, you would have to: - save errno - reset errno to zero - call the function - inspect the return value to detect failure - inspect errno to decide about the reason for failure - if errno is zero, restore the saved errno That is completely unreasonable, in particular for a seemingly innocous function like mbtowc(3). Next to no programmer would get that right in any real-world program. Note that this bug is very widespread, it also affects NetBSD, FreeBSD, Solaris 11, and glibc. I will also send a note around to the other systems.
The fix is OpenBSD/FreeBSD for more than a year without known issues.