SHMOP (SYSV)

rml at hpfcla.UUCP rml at hpfcla.UUCP
Tue Oct 29 11:16:00 AEST 1985


Shmat(2) and sbrk(2) aren't the only two calls which return pointers;
look at signal(2).  This is one case where NULL wouldn't do as an
error return, since there are two out-of-band values for successful
returns, and SIG_DFL is generally #define'd as 0.  There has
been some effort toward easing type-correct code here, as BSD has
added

	#define	BADSIG		(int (*)())-1

and the SVID mentions under FUTURE DIRECTIONS that AT&T will add a
similar macro (with a different name, SIG_ERR).  Things are, at least,
greatly improved from V6, when SIG_DFL and SIG_IGN didn't exist and
the hard-coded constants 0 and 1 were used.

>From the way most UN*X implementations (including the early ones) have
been written, *all* system calls return -1 on failure.  Since they all
pass through a common trap routine, they all pass back success/failure
indication and return values via a common mechanism.  The C library
stubs all check this common success/failure indication and, on error,
brach to common code which sets a return value of -1.  Of course it
would be quite easy to write the stub for a particular system call to
set a return value of NULL, but this hasn't been done.  It would also
have been possible to have shmat return its pointer through another
parameter.  Realistically, there's enough code which checks sbrk and
signal return values for -1 that a machine on which -1 was a valid
return for either would have importability problems.  I agree that at
least the error return from shmat could be documented as (char *)-1.

			Bob Lenk
			{ihnp4, hplabs}!hpfcla!rml



More information about the Comp.unix.wizards mailing list