[net.unix-wizards] Syscall Return Values

cottrell@NBS-VMS.ARPA (COTTRELL, JAMES) (10/25/85)

/*
> 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@nbs
*/
------

lcc.rich-wiz@ucla-locus.ARPA (Richard Mathews) (10/30/85)

Key: >> Niket; > Cottrell

>/*
>> 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.

For once, I agree with Niket.  Can you name any system calls which will
return something other than -1 when they get an error?

It is not new for a system call to return -1 even though it normally
returns a pointer.  Take a look at sbrk(2) and signal(2).  It is, however,
very unfortunate.  It is just as unfortunate that System V's nice(2) can
return -1 even when it is successful.  The only real way to test for error
in these cases is to set errno to zero before the call and take advantage
of the fact that errno is modified iff the call is unsuccessful.

Richard M. Mathews
Locus Computing Corporation		       lcc.richard@LOCUS.UCLA.EDU
					       lcc.richard@UCLA-CS
				{ucivax,trwrb}!lcc!richard
 {ihnp4,randvax,sdcrdcf,ucbvax,trwspp}!ucla-cs!lcc!richard