embeddedartistry / libc

libc targeted for embedded systems usage. Reduced set of functionality (due to embedded nature). Chosen for portability and quick bringup.
MIT License
504 stars 67 forks source link

strerror: String returned for code zero (0) violates POSIX #178

Closed smcpeak closed 2 years ago

smcpeak commented 2 years ago

Currently, strerror(0) returns "No error information".

However, POSIX says:

if the value of errnum is zero, the message string shall either be an empty string or indicate that no error occurred

Now, I haven't seen any explicit statement that this libc intends to comply with POSIX, and C11 7.23.6.2 does not contain this requirement, but it would seem like bringing strerror into POSIX compliance ought to be easy, and doing so would be beneficial to those with POSIX expectations.

smcpeak commented 2 years ago

Thanks for the quick response!

But there's a problem with this change. The way the code currently works, the E(0, ...) entry applies to both the case of err_no being zero and the case of it being unrecognized. Here's the full paragraph from POSIX:

If the value of errnum is a valid error number, the message string shall indicate what error occurred; if the value of errnum is zero, the message string shall either be an empty string or indicate that no error occurred; otherwise, if these functions complete successfully, the message string shall indicate that an unknown error occurred.

Note the final clause, requiring that upon an invalid and non-zero error number, "the message string shall indicate that an unknown error occurred." That part is now violated.

phillipjohnston commented 2 years ago

Addressed in latest PR.