positive POSIX error codes
benedekkupper opened this issue · 3 comments
Why aren't the POSIX error codes returned with negative sign?
To my knowledge, not all POSIX functions return error codes as negative values. E.g. pthread_once. Especially the errno codes that by definition are positive.
Is it a generic question or you have any particular function in mind?
It's a generic question, negative error codes make it clearer in general that an erroneous condition occurred, so the positive range can be used for normal operation return values.
It is correct in theory. In practice it is not so simple. It depends what function should return. Sometimes negative value is a correct value (or normal operation value). I guess POSIX is trying to be consistent to return 0 on success. Even then, some functions can return NULL (malloc for example) which in many systems is 0.
In my implementation I tried to follow POSIX specification in terms what functions return. I was checking function by function what it should return but bugs happen (example in #11) .