Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

errno or -errno or -1 or...WTF?!

Name: Anonymous 2015-01-12 0:41

http://man7.org/linux/man-pages/man2/syscalls.2.html

Note: system calls indicate a failure by returning a negative error number to the caller; when this happens, the wrapper function negates the returned error number (to make it positive), copies it to errno, and returns -1 to the caller of the wrapper.

So the system calls quite sensibly return a negative number to indicate an error, but then someone added code to be executed every single time a syscall is made just to check its return value and store that in a separate variable, turning all errors into -1? Now every time you use a syscall you have to check for errors and then pull the correct error number back out of errno instead of straightforwardly passing the error value through as the return value? Which brain-damaged idiot thought this was a good idea!?

Name: Anonymous 2015-01-12 7:07

>>1
You can blame Ken Thompson (probably) for the way errno works. Linux returns the error code in a register (on most architectures, anyway) because it's faster and simpler than storing it in the caller's memory.

In all honesty though, this sort of trivial API translation is not even close to being the most expensive component of making a system call. Nothing stops you from bypassing the libc and exercising the kernel ABI directly if you really care that much.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List