Syscall Return Values

COTTRELL, JAMES cottrell at NBS-VMS.ARPA
Fri Oct 25 07:03:10 AEST 1985


/*
> I thought that every SYSTEM CALL returned -1 on error.

Make that MOST system calls. The idea is to return an out-of-band value
of the same type. Other considerations apply. For example, typical code
goes like: `if (syscall(args) == ERROR) die(why);'. Success falls thru.
Since Zero is returned for success on many syscalls that return only
pass/fail, the `== ERROR' may be left out. Less readable tho.

> For example, read
> returns -1 if you give it a fid that hasn't been opened, is not readable etc.
> EOF is NOT considered an error, and is signalled by a 0 return. 

True enuf. However, both of these values are `int's, & readily 
comparable without casts. Minus One is not a legal file descriptor.

> Thus SHMOP
> returning -1 on an error would be consistent with all other system calls.

Consistent but stupid. What was being returned was a pointer (to either
a char or some struxure). The obvious choice is to return NULL, which is
a legal value of the same type. Minus One is not of type `pointer to 
something'. It requires explicit casts both in the calling AND called
funxions. Consistency is occaisionally not appropriate. I happen to
think that TPC's IPC mechanism is thrown together rather poorly.

System V is a trademark of The Phone Company

	jim		cottrell at nbs
*/
------



More information about the Comp.unix.wizards mailing list