Avoid gcc warnings because of #pragma GCC system_header on older gcc.
[gnulib.git] / lib / spawn.in.h
1 /* Definitions for POSIX spawn interface.
2    Copyright (C) 2000, 2003, 2004, 2008 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #ifndef _GL_SPAWN_H
19
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23
24 /* The include_next requires a split double-inclusion guard.  */
25 #if @HAVE_SPAWN_H@
26 # @INCLUDE_NEXT@ @NEXT_SPAWN_H@
27 #endif
28
29 #ifndef _GL_SPAWN_H
30 #define _GL_SPAWN_H
31
32 #include <sched.h>
33 #include <signal.h>
34 #include <sys/types.h>
35
36 #ifndef __THROW
37 # define __THROW
38 #endif
39
40 /* GCC 2.95 and later have "__restrict"; C99 compilers have
41    "restrict", and "configure" may have defined "restrict".
42    Other compilers use __restrict, __restrict__, and _Restrict, and
43    'configure' might #define 'restrict' to those words, so pick a
44    different name.  */
45 #ifndef _Restrict_
46 # if 199901L <= __STDC_VERSION__
47 #  define _Restrict_ restrict
48 # elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
49 #  define _Restrict_ __restrict
50 # else
51 #  define _Restrict_
52 # endif
53 #endif
54 /* gcc 3.1 and up support the [restrict] syntax.  Don't trust
55    sys/cdefs.h's definition of __restrict_arr, though, as it
56    mishandles gcc -ansi -pedantic.  */
57 #ifndef _Restrict_arr_
58 # if ((199901L <= __STDC_VERSION__                                      \
59        || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__))     \
60            && !__STRICT_ANSI__))                                        \
61       && !defined __GNUG__)
62 #  define _Restrict_arr_ _Restrict_
63 # else
64 #  define _Restrict_arr_
65 # endif
66 #endif
67
68 /* The definition of GL_LINK_WARNING is copied here.  */
69
70
71 /* Data structure to contain attributes for thread creation.  */
72 #if @REPLACE_POSIX_SPAWN@
73 # define posix_spawnattr_t rpl_posix_spawnattr_t
74 #endif
75 typedef struct
76 {
77   short int _flags;
78   pid_t _pgrp;
79   sigset_t _sd;
80   sigset_t _ss;
81   struct sched_param _sp;
82   int _policy;
83   int __pad[16];
84 } posix_spawnattr_t;
85
86
87 /* Data structure to contain information about the actions to be
88    performed in the new process with respect to file descriptors.  */
89 #if @REPLACE_POSIX_SPAWN@
90 # define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t
91 #endif
92 typedef struct
93 {
94   int _allocated;
95   int _used;
96   struct __spawn_action *_actions;
97   int __pad[16];
98 } posix_spawn_file_actions_t;
99
100
101 /* Flags to be set in the `posix_spawnattr_t'.  */
102 #if @REPLACE_POSIX_SPAWN@
103 /* Use the values from the system, for better compatibility.  */
104 /* But this implementation does not support AIX extensions.  */
105 # undef POSIX_SPAWN_FORK_HANDLERS
106 #else
107 # define POSIX_SPAWN_RESETIDS           0x01
108 # define POSIX_SPAWN_SETPGROUP          0x02
109 # define POSIX_SPAWN_SETSIGDEF          0x04
110 # define POSIX_SPAWN_SETSIGMASK         0x08
111 # define POSIX_SPAWN_SETSCHEDPARAM      0x10
112 # define POSIX_SPAWN_SETSCHEDULER       0x20
113 #endif
114 /* A GNU extension.  Use the next free bit position.  */
115 #define POSIX_SPAWN_USEVFORK \
116   ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1)                   \
117     | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1)               \
118     | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1)               \
119     | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1)             \
120     | POSIX_SPAWN_SETSCHEDPARAM | (POSIX_SPAWN_SETSCHEDPARAM - 1)       \
121     | POSIX_SPAWN_SETSCHEDULER | (POSIX_SPAWN_SETSCHEDULER - 1))        \
122    + 1)
123 typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap
124             [2 * (((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
125                     | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK
126                     | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)
127                    & POSIX_SPAWN_USEVFORK) == 0) - 1];
128
129
130 #ifdef __cplusplus
131 extern "C" {
132 #endif
133
134
135 #if @GNULIB_POSIX_SPAWN@
136 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
137    Before running the process perform the actions described in FILE-ACTIONS.
138
139    This function is a possible cancellation points and therefore not
140    marked with __THROW. */
141 # if @REPLACE_POSIX_SPAWN@
142 #  define posix_spawn rpl_posix_spawn
143 # endif
144 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
145 extern int posix_spawn (pid_t *_Restrict_ __pid,
146                         const char *_Restrict_ __path,
147                         const posix_spawn_file_actions_t *_Restrict_ __file_actions,
148                         const posix_spawnattr_t *_Restrict_ __attrp,
149                         char *const argv[_Restrict_arr_],
150                         char *const envp[_Restrict_arr_]);
151 # endif
152 #endif
153
154 #if @GNULIB_POSIX_SPAWNP@
155 /* Similar to `posix_spawn' but search for FILE in the PATH.
156
157    This function is a possible cancellation points and therefore not
158    marked with __THROW.  */
159 # if @REPLACE_POSIX_SPAWN@
160 #  define posix_spawnp rpl_posix_spawnp
161 # endif
162 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
163 extern int posix_spawnp (pid_t *__pid, const char *__file,
164                          const posix_spawn_file_actions_t *__file_actions,
165                          const posix_spawnattr_t *__attrp,
166                          char *const argv[], char *const envp[]);
167 # endif
168 #endif
169
170
171 #if @GNULIB_POSIX_SPAWNATTR_INIT@
172 /* Initialize data structure with attributes for `spawn' to default values.  */
173 # if @REPLACE_POSIX_SPAWN@
174 #  define posix_spawnattr_init rpl_posix_spawnattr_init
175 # endif
176 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
177 extern int posix_spawnattr_init (posix_spawnattr_t *__attr) __THROW;
178 # endif
179 #endif
180
181 #if @GNULIB_POSIX_SPAWNATTR_DESTROY@
182 /* Free resources associated with ATTR.  */
183 # if @REPLACE_POSIX_SPAWN@
184 #  define posix_spawnattr_destroy rpl_posix_spawnattr_destroy
185 # endif
186 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
187 extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) __THROW;
188 # endif
189 #endif
190
191 #if @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@
192 /* Store signal mask for signals with default handling from ATTR in
193    SIGDEFAULT.  */
194 # if @REPLACE_POSIX_SPAWN@
195 #  define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault
196 # endif
197 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
198 extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *_Restrict_ __attr,
199                                           sigset_t *_Restrict_ __sigdefault)
200      __THROW;
201 # endif
202 #endif
203
204 #if @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@
205 /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT.  */
206 # if @REPLACE_POSIX_SPAWN@
207 #  define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault
208 # endif
209 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
210 extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *_Restrict_ __attr,
211                                           const sigset_t *_Restrict_ __sigdefault)
212      __THROW;
213 # endif
214 #endif
215
216 #if @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@
217 /* Store signal mask for the new process from ATTR in SIGMASK.  */
218 # if @REPLACE_POSIX_SPAWN@
219 #  define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask
220 # endif
221 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
222 extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *_Restrict_ __attr,
223                                        sigset_t *_Restrict_ __sigmask) __THROW;
224 # endif
225 #endif
226
227 #if @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@
228 /* Set signal mask for the new process in ATTR to SIGMASK.  */
229 # if @REPLACE_POSIX_SPAWN@
230 #  define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask
231 # endif
232 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
233 extern int posix_spawnattr_setsigmask (posix_spawnattr_t *_Restrict_ __attr,
234                                        const sigset_t *_Restrict_ __sigmask)
235      __THROW;
236 # endif
237 #endif
238
239 #if @GNULIB_POSIX_SPAWNATTR_GETFLAGS@
240 /* Get flag word from the attribute structure.  */
241 # if @REPLACE_POSIX_SPAWN@
242 #  define posix_spawnattr_getflags rpl_posix_spawnattr_getflags
243 # endif
244 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
245 extern int posix_spawnattr_getflags (const posix_spawnattr_t *_Restrict_ __attr,
246                                      short int *_Restrict_ __flags) __THROW;
247 # endif
248 #endif
249
250 #if @GNULIB_POSIX_SPAWNATTR_SETFLAGS@
251 /* Store flags in the attribute structure.  */
252 # if @REPLACE_POSIX_SPAWN@
253 #  define posix_spawnattr_setflags rpl_posix_spawnattr_setflags
254 # endif
255 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
256 extern int posix_spawnattr_setflags (posix_spawnattr_t *__attr,
257                                      short int __flags) __THROW;
258 # endif
259 #endif
260
261 #if @GNULIB_POSIX_SPAWNATTR_GETPGROUP@
262 /* Get process group ID from the attribute structure.  */
263 # if @REPLACE_POSIX_SPAWN@
264 #  define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup
265 # endif
266 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
267 extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *_Restrict_ __attr,
268                                       pid_t *_Restrict_ __pgroup)
269      __THROW;
270 # endif
271 #endif
272
273 #if @GNULIB_POSIX_SPAWNATTR_SETPGROUP@
274 /* Store process group ID in the attribute structure.  */
275 # if @REPLACE_POSIX_SPAWN@
276 #  define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup
277 # endif
278 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
279 extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
280                                       pid_t __pgroup) __THROW;
281 # endif
282 #endif
283
284 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@
285 /* Get scheduling policy from the attribute structure.  */
286 # if @REPLACE_POSIX_SPAWN@
287 #  define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy
288 # endif
289 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
290 extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *_Restrict_ __attr,
291                                            int *_Restrict_ __schedpolicy)
292      __THROW;
293 # endif
294 #endif
295
296 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@
297 /* Store scheduling policy in the attribute structure.  */
298 # if @REPLACE_POSIX_SPAWN@
299 #  define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy
300 # endif
301 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
302 extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
303                                            int __schedpolicy) __THROW;
304 # endif
305 #endif
306
307 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@
308 /* Get scheduling parameters from the attribute structure.  */
309 # if @REPLACE_POSIX_SPAWN@
310 #  define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam
311 # endif
312 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
313 extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *_Restrict_ __attr,
314                                           struct sched_param *_Restrict_ __schedparam) __THROW;
315 # endif
316 #endif
317
318 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@
319 /* Store scheduling parameters in the attribute structure.  */
320 # if @REPLACE_POSIX_SPAWN@
321 #  define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam
322 # endif
323 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
324 extern int posix_spawnattr_setschedparam (posix_spawnattr_t *_Restrict_ __attr,
325                                           const struct sched_param *_Restrict_ __schedparam) __THROW;
326 # endif
327 #endif
328
329
330 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@
331 /* Initialize data structure for file attribute for `spawn' call.  */
332 # if @REPLACE_POSIX_SPAWN@
333 #  define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init
334 # endif
335 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
336 extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *__file_actions) __THROW;
337 # endif
338 #endif
339
340 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@
341 /* Free resources associated with FILE-ACTIONS.  */
342 # if @REPLACE_POSIX_SPAWN@
343 #  define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy
344 # endif
345 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
346 extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *__file_actions) __THROW;
347 # endif
348 #endif
349
350 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
351 /* Add an action to FILE-ACTIONS which tells the implementation to call
352    `open' for the given file during the `spawn' call.  */
353 # if @REPLACE_POSIX_SPAWN@
354 #  define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen
355 # endif
356 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
357 extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *_Restrict_ __file_actions,
358                                              int __fd,
359                                              const char *_Restrict_ __path,
360                                              int __oflag, mode_t __mode)
361      __THROW;
362 # endif
363 #endif
364
365 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
366 /* Add an action to FILE-ACTIONS which tells the implementation to call
367    `close' for the given file descriptor during the `spawn' call.  */
368 # if @REPLACE_POSIX_SPAWN@
369 #  define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose
370 # endif
371 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
372 extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *__file_actions,
373                                               int __fd)
374      __THROW;
375 # endif
376 #endif
377
378 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
379 /* Add an action to FILE-ACTIONS which tells the implementation to call
380    `dup2' for the given file descriptors during the `spawn' call.  */
381 # if @REPLACE_POSIX_SPAWN@
382 #  define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2
383 # endif
384 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
385 extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *__file_actions,
386                                              int __fd, int __newfd) __THROW;
387 # endif
388 #endif
389
390
391 #ifdef __cplusplus
392 }
393 #endif
394
395
396 #endif /* _GL_SPAWN_H */
397 #endif /* _GL_SPAWN_H */