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: Cudder !MhMRSATORI 2015-01-12 15:54

DOS has much saner error handling; on error, CF is setted(sic) and an error code is returned in AX. On success, CF is cleared (and AX might contain something useful, depending on the syscall.)

>>5
http://man.cat-v.org/unix-1st/2/sys-open

The error bit (c--bit) is set if the file does not exist [...]

Looks like Unix was the same as DOS from the beginning, so whoever wrote the C interface wrappers (I fucking hate that word...) screwed up. If you look at the Linux syscall code you'll see they do things like return -ENOENT; on the kernel side already. See http://lxr.free-electrons.com/source/fs/open.c#L1072

Instead of something like this (this is open()'s description):

Upon successful completion, these functions shall open the file and return a non-negative integer representing the lowest numbered unused file descriptor. Otherwise, these functions shall return -1 and set errno to indicate the error.

Why not

Upon successful completion, these functions shall open the file and return a non-negative integer representing the lowest numbered unused file descriptor. Otherwise, these functions shall return the negative value indicating the error code.

Incidentally, this is how the Anonix syscalls work... no errno shit except at the APRI layer which isn't needed for native API code.

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