The value in errno is significant only when the return value of the call indicated an error (i.e., -1 from most system calls; -1 or NULL from most library functions); a function that succeeds is allowed to change errno. The value of errno is never set to zero by any system call or library function.

For some system calls and library functions (e.g., getpriority(2)), -1 is a valid return on success. In such cases, a successful return can be distinguished from an error return by setting errno to zero before the call, and then, if the call returns a status that indicates that an error may have occurred, checking to see if errno has a nonzero value.

0

If you have a fediverse account, you can quote this note from your own instance. Search https://tech.lgbt/users/void_friend/statuses/114738251839407926 on your instance and quote it. (Note that quoting is not supported in Mastodon.)