In article <20160324125858.516aa36bc70bddd1b180e...@schemamania.org>, James K. Lowden <tech-userlevel@netbsd.org> wrote: >On Thu, 24 Mar 2016 14:29:39 +0000 (UTC) >mlel...@serpens.de (Michael van Elst) wrote: > >> >(I agree that calling strerror(0) is odd and a likely sign of a bug, >> >but that's separate from complying with standards when compliance >> >isn't harmful.) >> >> Well, if calling strerror(0) is a bug, then usually because it's >> called after an error condition that didn't set errno. > >Has that happened to you? I feel sure that's never happened to me, but >maybe I'm less adventurous. > >IMO it's incorrect to say 0 is an "undefined error". It's defined as >success by nearly every syscall. The emitted string should reflect >that, even if [sic] Posix says so. Perhaps,
Actually not; syscalls set errno on error, don't clear errno on success [1]. Thus it is incorrect code to test errno if the syscall succeeded. It shows nothing, try: #include <stdio.h> #include <fcntl.h> #include <errno.h> int main(void) { errno = 3; open("/", O_RDONLY); printf("%d\n", errno); return 0; } [1] There is at least one syscall stub that clears errno before the syscall which I find bogus; can you guess which one? christos