Help with BSD 4.2!!

Guy Harris guy at sun.uucp
Sun May 26 08:11:28 AEST 1985


> There are discrepancies between #include files in /usr/include
> and /usr/include/sys on two systems.
> One thing I do not have is BSD 4.2 #include file wait.h.

"wait.h" defines a structure with bit fields for pulling apart the "int"
that "wait" fills in.

1) If the program doesn't use "wait3" (if it does, you're sunk; it's a
4.xBSD-only feature), just use masks to pull apart the value.

	w_termsig	is the signal that caused the process to terminate
			(0 if it was terminated by "exit"ing).  Lower 7
			bits of the "int" (mask of 0177).
	w_coredump	is the bit that indicates if the signal in question
			caused a core dump or not.  0200 bit of the "int".
	w_retcode	is the exit status of the program.  Next 8 bits
			of the "int" (mask of 0377, then shift right 8).
	w_stopval	is 0177 if the process is stopped, not terminated.
			Same lower 7 bits as "w_termsig".
	w_stopsig	is the signal that stopped the process.  Same
			"next 8 bits" as "w_retcode".

	WSTOPPED	is a manifest constant for the magic 0177 mentioned
			under "w_stopval".  Just replace it with 0177.

	WIFSTOPPED(x)	is a predicate that takes the "wait" return
			value and checks whether the process is stopped.
			Replace it with a test of

			((int_value & 0177) == 0177)

	WIFSIGNALED(x)	is a predicate that takes the "wait" return
			value and checks whether the process was terminated
			with a signal.  Replace it with a test of

			((int_value & 0177) != 0177
			    && (int_value & 0177) != 0)

	WIFEXITED(x)	is a predicate that takes the "wait" return
			value and checks whether the process "exit"ed.
			Replace it with a test of

			((int_value & 0177) == 0)

People: please don't use the "wait.h" stuff unless you *really* have to or
you absolutely *K*N*O*W* that the program will never ever EVER run under any
non-4.xBSD-based UNIX.  ("wait" is declared in the non-4.xBSD manual pages
and in the non-4.xBSD lint libraries as taking a pointer to "int" as an
argument, not a pointer to a "union wait".  Furthermore, the bit fields
inside that "int" are defined relative to the least-significant bit, so that
two structure definitions are needed, one for big-endian machines and one
for little-endian machines; code that uses shifts and masks will work
regardless of the byte sex of the machine.)

> Another is CBREAK #define'd somewhere in /usr/include/* or /usr/include/*/*.

None of the above.  CBREAK was part of the V7 terminal driver that the
4.xBSD driver is based on.  Turning CBREAK on is equivalent to turning
ICANON off.  WARNING: programs written for the V7 driver or V7-based drivers
like the 4.xBSD driver use TIOCGETP and TIOCSETP "ioctl"s (or the "gtty" and
"stty" calls which are equivalent) with "struct sgttyb" structures.  System
{III,V} have these "ioctl"s (as well as "gtty" and "stty") BUT 1) they are not
compatible with the V7 calls and 2) they are described as "conversion
aide(s) (sic) only" in the comments in the S{3,5} terminal driver.  As such,
all calls to "gtty"/"ioctl(TIOCGETP)" or to "stty"/"ioctl(TIOCSETP)" should
NOT be left intact if a V7/4.xBSD program is being moved to S{3,5}.

Conversion of these calls, at least for programs that don't do anything
fancy (most programs that fiddle the terminal modes of the standard input or
output are just "full-screen" programs which don't do anything fancy) is
straightforward but tedious.  Grab a 4.xBSD manual (it describes the added
features and corrects some errors in the V7 manual page) and an S{3,5}
manual, and study the appropriate manual pages - TTY(4) in the Berkeley
manual (Programmer's Manual for the multi-volume hand-held sets) and
TERMIO(7) in the *ADMINISTRATOR'S* manual (yes, this is the wrong place for
it - it belongs in the Programmer's manual; go yell at the AT&T documenation
people) for S5 (User's Manual for S3).

	Guy Harris



More information about the Comp.unix mailing list