5 ms·
Most of the POSIX functions that use errno for error signaling simply return 0 for success and -1 for error. They could have returned errno directly.
by bdd8f1df777b 3y ago
Most of the POSIX functions that use errno for error signaling simply return 0 for success and -1 for error. They could have returned errno directly.
- tedunangst 3y agoWhat about the rest?
- deleted 3y ago[deleted]
- bdd8f1df777b 3y agoPut the original return value in a pointer argument, and return errno (or -errno).
- ronsor 3y agoLast I checked, the Linux kernel ABI does return -errno for errors. Then libc mangles that all up.
- wahern 3y agoSome newer POSIX APIs, such as pthreads, do return the error this way. But many legacy APIs, such as dup or read, use the positive integer space, thus the negation pattern you often see in syscalls. Notably, POSIX guarantees <errno.h> values to be positive integers.
- bdd8f1df777b 3y ago`dup` and `read` returns -1 on error and set the `errno` variable. If they were redesigned, they should just return `-errno` on failure.