OSDN Git Service

Patch from "D. Jeff Dionne / VE3DJF" <jeff@rt-control.com>
[uclinux-h8/uClibc.git] / include / sys / wait.h
1 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB.  If
16 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA.  */
18
19 /*
20  *      POSIX Standard: 3.2.1 Wait for Process Termination      <sys/wait.h>
21  */
22
23 #ifndef _SYS_WAIT_H
24
25 #define _SYS_WAIT_H     1
26 #include <features.h>
27 #include <errno.h>
28
29 __BEGIN_DECLS
30
31 #include <gnu/types.h>
32
33 /* This will define the `W*' macros for the flag
34    bits to `waitpid', `wait3', and `wait4'.  */
35 #include <waitflags.h>
36
37 #ifdef  __USE_BSD
38
39 /* Lots of hair to allow traditional BSD use of `union wait'
40    as well as POSIX.1 use of `int' for the status word.  */
41
42 #ifdef  __GNUC__
43 #define __WAIT_INT(status)                                                    \
44   (__extension__ ({ union { __typeof(status) __in; int __i; } __u;            \
45                     __u.__in = (status); __u.__i; }))
46 #else
47 #define __WAIT_INT(status)      (*(int *) &(status))
48 #endif
49
50 /* This is the type of the argument to `wait'.  With GCC 2.6.1 and later,
51    the funky union causes redeclarations with either `int *' or `union wait
52    *' to be allowed without complaint.  __WAIT_STATUS_DEFN is the type used
53    in the actual function definitions. */
54
55 /* g++ in gcc 2.6.1 doesn't work. Maybe 2.7.x. H.J. */
56 #if !defined (__GNUC__) || defined (__cplusplus) || \
57          __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || \
58          (defined(_MIT_POSIX_THREADS) && _MIT_POSIX_THREADS > 0)
59 #define __WAIT_STATUS   __ptr_t
60 #define __WAIT_STATUS_DEFN      __ptr_t
61 #else
62 /* This works in GCC 2.6.1 and later.  */
63 typedef union
64   {
65     union wait *__uptr;
66     int *__iptr;
67   } __WAIT_STATUS __attribute__ ((transparent_union));
68 #define __WAIT_STATUS_DEFN      int *
69 #endif
70
71 #else /* Don't use BSD.  */
72
73 #define __WAIT_INT(status)      (status)
74 #define __WAIT_STATUS           int *
75
76 #endif /* Use BSD.  */
77
78 /* This will define all the `__W*' macros.  */
79 #include <waitstatus.h>
80
81 #define WEXITSTATUS(status)     __WEXITSTATUS(__WAIT_INT(status))
82 #define WTERMSIG(status)        __WTERMSIG(__WAIT_INT(status))
83 #define WSTOPSIG(status)        __WSTOPSIG(__WAIT_INT(status))
84 #define WIFEXITED(status)       __WIFEXITED(__WAIT_INT(status))
85 #define WIFSIGNALED(status)     __WIFSIGNALED(__WAIT_INT(status))
86 #define WIFSTOPPED(status)      __WIFSTOPPED(__WAIT_INT(status))
87
88 #ifdef  __USE_BSD
89 #define WCOREDUMP(status)       __WCOREDUMP(__WAIT_INT(status))
90 #define W_EXITCODE(ret, sig)    __W_EXITCODE(ret, sig)
91 #define W_STOPCODE(sig)         __W_STOPCODE(sig)
92 #endif
93
94
95 /* Wait for a child to die.  When one does, put its status in *STAT_LOC
96    and return its process ID.  For errors, return (pid_t) -1.  */
97 extern __pid_t __wait __P ((__WAIT_STATUS __stat_loc));
98 extern __pid_t wait __P ((__WAIT_STATUS __stat_loc));
99
100 #ifdef  __USE_BSD
101 /* Special values for the PID argument to `waitpid' and `wait4'.  */
102 #define WAIT_ANY        (-1)    /* Any process.  */
103 #define WAIT_MYPGRP     0       /* Any process in my process group.  */
104 #endif
105
106 /* Wait for a child matching PID to die.
107    If PID is greater than 0, match any process whose process ID is PID.
108    If PID is (pid_t) -1, match any process.
109    If PID is (pid_t) 0, match any process with the
110    same process group as the current process.
111    If PID is less than -1, match any process whose
112    process group is the absolute value of PID.
113    If the WNOHANG bit is set in OPTIONS, and that child
114    is not already dead, return (pid_t) 0.  If successful,
115    return PID and store the dead child's status in STAT_LOC.
116    Return (pid_t) -1 for errors.  If the WUNTRACED bit is
117    set in OPTIONS, return status for stopped children; otherwise don't.  */
118 extern __pid_t __waitpid __P ((__pid_t __pid, int *__stat_loc,
119                                int __options));
120 extern __pid_t waitpid __P ((__pid_t __pid, int *__stat_loc,
121                              int __options));
122 #ifdef  __USE_BSD
123 /* This being here makes the prototypes valid whether or not
124    we have already included <sys/resource.h> to define `struct rusage'.  */
125 struct rusage;
126
127 /* Wait for a child to exit.  When one does, put its status in *STAT_LOC and
128    return its process ID.  For errors return (pid_t) -1.  If USAGE is not
129    nil, store information about the child's resource usage there.  If the
130    WUNTRACED bit is set in OPTIONS, return status for stopped children;
131    otherwise don't.  */
132 extern __pid_t __wait3 __P ((__WAIT_STATUS __stat_loc,
133                              int __options, struct rusage * __usage));
134 extern __pid_t wait3 __P ((__WAIT_STATUS __stat_loc,
135                            int __options, struct rusage * __usage));
136
137 /* PID is like waitpid.  Other args are like wait3.  */
138 extern __pid_t __wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
139                              int __options, struct rusage *__usage));
140 extern __pid_t wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
141                            int __options, struct rusage *__usage));
142 #endif /* Use BSD.  */
143
144
145 __END_DECLS
146
147 #endif /* sys/wait.h  */