1202375Srdivacky/* $Header: /p/tcsh/cvsroot/tcsh/tc.wait.h,v 3.15 2011/02/04 18:00:26 christos Exp $ */
2202375Srdivacky/*
3202375Srdivacky * tc.wait.h: <sys/wait.h> for machines that don't have it or have it and
4202375Srdivacky *	      is incorrect.
5202375Srdivacky */
6202375Srdivacky/*-
7202375Srdivacky * Copyright (c) 1980, 1991 The Regents of the University of California.
8202375Srdivacky * All rights reserved.
9202375Srdivacky *
10202375Srdivacky * Redistribution and use in source and binary forms, with or without
11202375Srdivacky * modification, are permitted provided that the following conditions
12202375Srdivacky * are met:
13202375Srdivacky * 1. Redistributions of source code must retain the above copyright
14202375Srdivacky *    notice, this list of conditions and the following disclaimer.
15263508Sdim * 2. Redistributions in binary form must reproduce the above copyright
16202375Srdivacky *    notice, this list of conditions and the following disclaimer in the
17249423Sdim *    documentation and/or other materials provided with the distribution.
18202375Srdivacky * 3. Neither the name of the University nor the names of its contributors
19202375Srdivacky *    may be used to endorse or promote products derived from this software
20202375Srdivacky *    without specific prior written permission.
21202375Srdivacky *
22202375Srdivacky * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23249423Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24249423Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25249423Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26249423Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27249423Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28251662Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29249423Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30251662Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31249423Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32249423Sdim * SUCH DAMAGE.
33249423Sdim */
34249423Sdim#ifndef _h_tc_wait
35249423Sdim#define _h_tc_wait
36249423Sdim
37249423Sdim/*
38249423Sdim * a little complicated #include <sys/wait.h>! :-(
39249423Sdim * We try to use the system's wait.h when we can...
40249423Sdim */
41251662Sdim
42249423Sdim#if SYSVREL > 0 && !defined(__linux__) && !defined(__GNU__) && !defined(__GLIBC__)
43249423Sdim# ifdef hpux
44249423Sdim#  ifndef __hpux
45249423Sdim#   define NEEDwait
46251662Sdim#  else
47249423Sdim#   ifndef POSIX
48249423Sdim#    define _BSD
49249423Sdim#   endif
50251662Sdim#   ifndef _CLASSIC_POSIX_TYPES
51249423Sdim#    define _CLASSIC_POSIX_TYPES
52249423Sdim#   endif
53251662Sdim#   include <sys/wait.h> /* 7.0 fixed it again */
54249423Sdim#  endif /* __hpux */
55249423Sdim# else /* hpux */
56249423Sdim#  if (defined(OREO) || defined(IRIS4D) || defined(POSIX)) && !defined(_VMS_POSIX)
57249423Sdim#   include <sys/wait.h>
58249423Sdim#  else	/* OREO || IRIS4D || POSIX */
59249423Sdim#   define NEEDwait
60251662Sdim#  endif /* OREO || IRIS4D || POSIX */
61249423Sdim# endif	/* hpux */
62249423Sdim#else /* SYSVREL == 0 || glibc */
63249423Sdim# ifdef _MINIX
64249423Sdim#  undef NEEDwait
65251662Sdim#  include "mi.wait.h"
66249423Sdim# else
67249423Sdim#  ifndef WINNT_NATIVE
68249423Sdim#   include <sys/wait.h>
69249423Sdim#  endif /* WINNT_NATIVE */
70249423Sdim# endif /* _MINIX */
71249423Sdim#endif /* SYSVREL == 0 || glibc */
72249423Sdim
73249423Sdim#ifdef NEEDwait
74249423Sdim/*
75249423Sdim *	This wait is for big-endians and little endians
76249423Sdim */
77249423Sdimunion wait {
78251662Sdim    int     w_status;
79251662Sdim# ifdef _SEQUENT_
80251662Sdim    struct {
81251662Sdim	unsigned short w_Termsig:7;
82251662Sdim	unsigned short w_Coredump:1;
83249423Sdim	unsigned short w_Retcode:8;
84249423Sdim    }       w_T;
85249423Sdim    struct {
86251662Sdim	unsigned short w_Stopval:8;
87249423Sdim	unsigned short w_Stopsig:8;
88249423Sdim    }       w_S;
89249423Sdim};
90249423Sdim
91251662Sdim#  define w_termsig     w_T.w_Termsig
92249423Sdim#  define w_coredump    w_T.w_Coredump
93249423Sdim#  define w_retcode     w_T.w_Retcode
94249423Sdim#  define w_stopval     w_S.w_Stopval
95249423Sdim#  define w_stopsig     w_S.w_Stopsig
96251662Sdim# else /* _SEQUENT_ */
97249423Sdim#  if defined(vax) || defined(__vax__) || defined(i386) || defined(_I386) || defined(__i386__)
98249423Sdim    union {
99251662Sdim	struct {
100249423Sdim	    unsigned int w_Termsig:7;
101249423Sdim	    unsigned int w_Coredump:1;
102249423Sdim	    unsigned int w_Retcode:8;
103249423Sdim	    unsigned int w_Dummy:16;
104249423Sdim	}       w_T;
105249423Sdim	struct {
106249423Sdim	    unsigned int w_Stopval:8;
107249423Sdim	    unsigned int w_Stopsig:8;
108251662Sdim	    unsigned int w_Dummy:16;
109249423Sdim	}       w_S;
110249423Sdim    }       w_P;
111249423Sdim#  else /* mc68000 || sparc || ??? */
112249423Sdim#    if defined(_CRAY) || defined(ANY_OTHER_64BIT_MACHINE)
113249423Sdim#      define DUMMY_BITS	48
114249423Sdim#    else /* _CRAY */
115249423Sdim#      define DUMMY_BITS	16
116251662Sdim#    endif /* _CRAY */
117249423Sdim    union {
118249423Sdim	struct {
119251662Sdim	    unsigned int w_Dummy:DUMMY_BITS;
120249423Sdim	    unsigned int w_Retcode:8;
121249423Sdim	    unsigned int w_Coredump:1;
122249423Sdim	    unsigned int w_Termsig:7;
123249423Sdim	}       w_T;
124249423Sdim	struct {
125249423Sdim	    unsigned int w_Dummy:DUMMY_BITS;
126249423Sdim	    unsigned int w_Stopsig:8;
127249423Sdim	    unsigned int w_Stopval:8;
128251662Sdim	}       w_S;
129249423Sdim    }       w_P;
130251662Sdim#  endif /* vax || __vax__ || i386 || _I386 || __i386__ */
131249423Sdim};
132249423Sdim
133249423Sdim#  define w_termsig	w_P.w_T.w_Termsig
134251662Sdim#  define w_coredump	w_P.w_T.w_Coredump
135249423Sdim#  define w_retcode	w_P.w_T.w_Retcode
136249423Sdim#  define w_stopval	w_P.w_S.w_Stopval
137249423Sdim#  define w_stopsig	w_P.w_S.w_Stopsig
138251662Sdim# endif /* _SEQUENT_ */
139249423Sdim
140249423Sdim
141249423Sdim# ifndef WNOHANG
142249423Sdim#  define WNOHANG	1	/* dont hang in wait */
143249423Sdim# endif
144249423Sdim
145249423Sdim# ifndef WUNTRACED
146251662Sdim#  define WUNTRACED	2	/* tell about stopped, untraced children */
147249423Sdim# endif
148249423Sdim
149249423Sdim# define WSTOPPED 0177
150249423Sdim# define WIFSTOPPED(x)	((x).w_stopval == WSTOPPED)
151251662Sdim# define WIFSIGNALED(x)	(((x).w_stopval != WSTOPPED) && ((x).w_termsig != 0))
152249423Sdim
153249423Sdim#endif /* NEEDwait */
154249423Sdim
155249423Sdim#endif /* _h_tc_wait */
156249423Sdim