159243Sobrien/*
259243Sobrien * tc.wait.h: <sys/wait.h> for machines that don't have it or have it and
359243Sobrien *	      is incorrect.
459243Sobrien */
559243Sobrien/*-
659243Sobrien * Copyright (c) 1980, 1991 The Regents of the University of California.
759243Sobrien * All rights reserved.
859243Sobrien *
959243Sobrien * Redistribution and use in source and binary forms, with or without
1059243Sobrien * modification, are permitted provided that the following conditions
1159243Sobrien * are met:
1259243Sobrien * 1. Redistributions of source code must retain the above copyright
1359243Sobrien *    notice, this list of conditions and the following disclaimer.
1459243Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1559243Sobrien *    notice, this list of conditions and the following disclaimer in the
1659243Sobrien *    documentation and/or other materials provided with the distribution.
17100616Smp * 3. Neither the name of the University nor the names of its contributors
1859243Sobrien *    may be used to endorse or promote products derived from this software
1959243Sobrien *    without specific prior written permission.
2059243Sobrien *
2159243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2259243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2359243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2459243Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2559243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2659243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2759243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2859243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2959243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3059243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3159243Sobrien * SUCH DAMAGE.
3259243Sobrien */
3359243Sobrien#ifndef _h_tc_wait
3459243Sobrien#define _h_tc_wait
3559243Sobrien
3659243Sobrien/*
3759243Sobrien * a little complicated #include <sys/wait.h>! :-(
3859243Sobrien * We try to use the system's wait.h when we can...
3959243Sobrien */
4059243Sobrien
41231990Smp#if SYSVREL > 0 && !defined(__linux__) && !defined(__GNU__) && !defined(__GLIBC__)
4259243Sobrien# ifdef hpux
4359243Sobrien#  ifndef __hpux
4459243Sobrien#   define NEEDwait
4559243Sobrien#  else
4659243Sobrien#   ifndef POSIX
4759243Sobrien#    define _BSD
4859243Sobrien#   endif
4959243Sobrien#   ifndef _CLASSIC_POSIX_TYPES
5059243Sobrien#    define _CLASSIC_POSIX_TYPES
5159243Sobrien#   endif
5259243Sobrien#   include <sys/wait.h> /* 7.0 fixed it again */
5359243Sobrien#  endif /* __hpux */
5459243Sobrien# else /* hpux */
5559243Sobrien#  if (defined(OREO) || defined(IRIS4D) || defined(POSIX)) && !defined(_VMS_POSIX)
5659243Sobrien#   include <sys/wait.h>
5759243Sobrien#  else	/* OREO || IRIS4D || POSIX */
5859243Sobrien#   define NEEDwait
5959243Sobrien#  endif /* OREO || IRIS4D || POSIX */
6059243Sobrien# endif	/* hpux */
61145479Smp#else /* SYSVREL == 0 || glibc */
6259243Sobrien# ifdef _MINIX
6359243Sobrien#  undef NEEDwait
6459243Sobrien#  include "mi.wait.h"
6559243Sobrien# else
6669408Sache#  ifndef WINNT_NATIVE
6759243Sobrien#   include <sys/wait.h>
6869408Sache#  endif /* WINNT_NATIVE */
6959243Sobrien# endif /* _MINIX */
70145479Smp#endif /* SYSVREL == 0 || glibc */
7159243Sobrien
7259243Sobrien#ifdef NEEDwait
7359243Sobrien/*
7459243Sobrien *	This wait is for big-endians and little endians
7559243Sobrien */
7659243Sobrienunion wait {
7759243Sobrien    int     w_status;
7859243Sobrien# ifdef _SEQUENT_
7959243Sobrien    struct {
8059243Sobrien	unsigned short w_Termsig:7;
8159243Sobrien	unsigned short w_Coredump:1;
8259243Sobrien	unsigned short w_Retcode:8;
8359243Sobrien    }       w_T;
8459243Sobrien    struct {
8559243Sobrien	unsigned short w_Stopval:8;
8659243Sobrien	unsigned short w_Stopsig:8;
8759243Sobrien    }       w_S;
8859243Sobrien};
8959243Sobrien
9059243Sobrien#  define w_termsig     w_T.w_Termsig
9159243Sobrien#  define w_coredump    w_T.w_Coredump
9259243Sobrien#  define w_retcode     w_T.w_Retcode
9359243Sobrien#  define w_stopval     w_S.w_Stopval
9459243Sobrien#  define w_stopsig     w_S.w_Stopsig
9559243Sobrien# else /* _SEQUENT_ */
96100616Smp#  if defined(vax) || defined(__vax__) || defined(i386) || defined(_I386) || defined(__i386__)
9759243Sobrien    union {
9859243Sobrien	struct {
9959243Sobrien	    unsigned int w_Termsig:7;
10059243Sobrien	    unsigned int w_Coredump:1;
10159243Sobrien	    unsigned int w_Retcode:8;
10259243Sobrien	    unsigned int w_Dummy:16;
10359243Sobrien	}       w_T;
10459243Sobrien	struct {
10559243Sobrien	    unsigned int w_Stopval:8;
10659243Sobrien	    unsigned int w_Stopsig:8;
10759243Sobrien	    unsigned int w_Dummy:16;
10859243Sobrien	}       w_S;
10959243Sobrien    }       w_P;
11059243Sobrien#  else /* mc68000 || sparc || ??? */
11159243Sobrien#    if defined(_CRAY) || defined(ANY_OTHER_64BIT_MACHINE)
11259243Sobrien#      define DUMMY_BITS	48
11359243Sobrien#    else /* _CRAY */
11459243Sobrien#      define DUMMY_BITS	16
11559243Sobrien#    endif /* _CRAY */
11659243Sobrien    union {
11759243Sobrien	struct {
11859243Sobrien	    unsigned int w_Dummy:DUMMY_BITS;
11959243Sobrien	    unsigned int w_Retcode:8;
12059243Sobrien	    unsigned int w_Coredump:1;
12159243Sobrien	    unsigned int w_Termsig:7;
12259243Sobrien	}       w_T;
12359243Sobrien	struct {
12459243Sobrien	    unsigned int w_Dummy:DUMMY_BITS;
12559243Sobrien	    unsigned int w_Stopsig:8;
12659243Sobrien	    unsigned int w_Stopval:8;
12759243Sobrien	}       w_S;
12859243Sobrien    }       w_P;
129100616Smp#  endif /* vax || __vax__ || i386 || _I386 || __i386__ */
13059243Sobrien};
13159243Sobrien
13259243Sobrien#  define w_termsig	w_P.w_T.w_Termsig
13359243Sobrien#  define w_coredump	w_P.w_T.w_Coredump
13459243Sobrien#  define w_retcode	w_P.w_T.w_Retcode
13559243Sobrien#  define w_stopval	w_P.w_S.w_Stopval
13659243Sobrien#  define w_stopsig	w_P.w_S.w_Stopsig
13759243Sobrien# endif /* _SEQUENT_ */
13859243Sobrien
13959243Sobrien
14059243Sobrien# ifndef WNOHANG
14159243Sobrien#  define WNOHANG	1	/* dont hang in wait */
14259243Sobrien# endif
14359243Sobrien
14459243Sobrien# ifndef WUNTRACED
14559243Sobrien#  define WUNTRACED	2	/* tell about stopped, untraced children */
14659243Sobrien# endif
14759243Sobrien
14859243Sobrien# define WSTOPPED 0177
14959243Sobrien# define WIFSTOPPED(x)	((x).w_stopval == WSTOPPED)
15059243Sobrien# define WIFSIGNALED(x)	(((x).w_stopval != WSTOPPED) && ((x).w_termsig != 0))
15159243Sobrien
15259243Sobrien#endif /* NEEDwait */
15359243Sobrien
15459243Sobrien#endif /* _h_tc_wait */
155