[comp.os.minix] Posix Headers

cechew@bruce.OZ (Earl Chew) (11/09/89)

From article <1655@bruce.OZ>, by cechew@bruce.OZ (Earl Chew):
> My interpretation of the standard is:
> 
> 		   msb      lsb
> 		+-----------------+
> stopped:	| signal |  0x7f  |
> 		+-----------------+
> exit:		| status |   0    |
> 		+-----------------+
> signal:	|   0    | signal |
> 		+-----------------+
> 
> #define WIFEXITED(x)	((*((int *) (&(x))) & 0xff) == 0)
> #define WEXITSTATUS(x)	((*((int *) (&(x))) >> 8) & 0xff)
> #define WIFSIGNALED(x)	((unsigned int) (*((int *) (&(x))) & 0xffff) < \
> 			 (unsigned int) 0x100)
> #define WTERMSIG(x)	(*((int *) (&(x))) & 0x7f)
> #define WIFSTOPPED(x)	((*((int *) (&(x))) & 0xff) == 0x7f)
> #define WSTOPSIG(x)	((*((int *) (&(x))) >> 8) & 0xff)

I made one mistake --- plus there is one contentious point. For
Minix, I think that the coding should be:

#define WIFEXITED(x)	(((x) & 0xff) == 0)
#define WEXITSTATUS(x)	(((x) >> 8) & 0xff)
#define WIFSIGNALED(x)	(((unsigned int) (x) - 1 & 0xffff) < 0xff)
#define WTERMSIG(x)	((x) & 0x7f)
#define WIFSTOPPED(x)	(((x) & 0xff) == 0x7f)
#define WSTOPSIG(x)	(((x) >> 8) & 0xff)

From my reading of Posix, it is not clear whether the arguments to W* need to
be lvalues. In any case, for Minix the casting is not required.

Secondly, my original implementation of WIFSIGNALED got confused by exit(0).

Earl
-- 
Earl Chew, Dept of Computer Science, Monash University, Australia 3168
ARPA: cechew%bruce.cs.monash.oz.au@uunet.uu.net  ACS : cechew@bruce.oz
----------------------------------------------------------------------