]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/pexecute.c
hashtab.c, [...]: Include string.h if HAVE_STRING_H.
[thirdparty/gcc.git] / libiberty / pexecute.c
CommitLineData
6599da04
JM
1/* Utilities to execute a program in a subprocess (possibly linked by pipes
2 with other subprocesses), and wait for it.
aeecce42 3 Copyright (C) 1996-2000 Free Software Foundation, Inc.
6599da04
JM
4
5This file is part of the libiberty library.
6Libiberty is free software; you can redistribute it and/or
7modify it under the terms of the GNU Library General Public
8License as published by the Free Software Foundation; either
9version 2 of the License, or (at your option) any later version.
10
11Libiberty is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14Library General Public License for more details.
15
16You should have received a copy of the GNU Library General Public
17License along with libiberty; see the file COPYING.LIB. If not,
18write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21/* This file exports two functions: pexecute and pwait. */
22
23/* This file lives in at least two places: libiberty and gcc.
24 Don't change one without the other. */
25
c5f7c445 26#ifdef HAVE_CONFIG_H
19ddc834 27#include "config.h"
c5f7c445 28#endif
11a0bb74 29
6599da04
JM
30#include <stdio.h>
31#include <errno.h>
aeecce42
MK
32#ifdef HAVE_STRING_H
33#include <string.h>
34#endif
c5f7c445
KG
35#ifdef HAVE_UNISTD_H
36#include <unistd.h>
37#endif
d11ec6f0
ZW
38#ifdef HAVE_STDLIB_H
39#include <stdlib.h>
40#endif
3f3726a3 41#define ISSPACE (x) isspace(x)
a6458d1d
KG
42#ifdef HAVE_SYS_WAIT_H
43#include <sys/wait.h>
44#endif
6599da04 45
c5f7c445
KG
46#ifdef vfork /* Autoconf may define this to fork for us. */
47# define VFORK_STRING "fork"
48#else
49# define VFORK_STRING "vfork"
50#endif
51#ifdef HAVE_VFORK_H
52#include <vfork.h>
53#endif
54#ifdef VMS
55#define vfork() (decc$$alloc_vfork_blocks() >= 0 ? \
56 lib$get_current_invo_context(decc$$get_vfork_jmpbuf()) : -1)
57#endif /* VMS */
58
6599da04 59#include "libiberty.h"
6599da04
JM
60
61/* stdin file number. */
62#define STDIN_FILE_NO 0
63
64/* stdout file number. */
65#define STDOUT_FILE_NO 1
66
67/* value of `pipe': port index for reading. */
68#define READ_PORT 0
69
70/* value of `pipe': port index for writing. */
71#define WRITE_PORT 1
72
73static char *install_error_msg = "installation problem, cannot exec `%s'";
74
75/* pexecute: execute a program.
76
77 PROGRAM and ARGV are the arguments to execv/execvp.
78
79 THIS_PNAME is name of the calling program (i.e. argv[0]).
80
81 TEMP_BASE is the path name, sans suffix, of a temporary file to use
82 if needed. This is currently only needed for MSDOS ports that don't use
83 GO32 (do any still exist?). Ports that don't need it can pass NULL.
84
85 (FLAGS & PEXECUTE_SEARCH) is non-zero if $PATH should be searched
86 (??? It's not clear that GCC passes this flag correctly).
87 (FLAGS & PEXECUTE_FIRST) is nonzero for the first process in chain.
88 (FLAGS & PEXECUTE_FIRST) is nonzero for the last process in chain.
89 FIRST_LAST could be simplified to only mark the last of a chain of processes
90 but that requires the caller to always mark the last one (and not give up
91 early if some error occurs). It's more robust to require the caller to
92 mark both ends of the chain.
93
94 The result is the pid on systems like Unix where we fork/exec and on systems
95 like WIN32 and OS2 where we use spawn. It is up to the caller to wait for
96 the child.
97
98 The result is the WEXITSTATUS on systems like MSDOS where we spawn and wait
99 for the child here.
100
101 Upon failure, ERRMSG_FMT and ERRMSG_ARG are set to the text of the error
102 message with an optional argument (if not needed, ERRMSG_ARG is set to
103 NULL), and -1 is returned. `errno' is available to the caller to use.
104
105 pwait: cover function for wait.
106
107 PID is the process id of the task to wait for.
108 STATUS is the `status' argument to wait.
109 FLAGS is currently unused (allows future enhancement without breaking
110 upward compatibility). Pass 0 for now.
111
112 The result is the pid of the child reaped,
113 or -1 for failure (errno says why).
114
115 On systems that don't support waiting for a particular child, PID is
116 ignored. On systems like MSDOS that don't really multitask pwait
117 is just a mechanism to provide a consistent interface for the caller.
118
119 pfinish: finish generation of script
120
121 pfinish is necessary for systems like MPW where a script is generated that
122 runs the requested programs.
123*/
124
125#ifdef __MSDOS__
126
127/* MSDOS doesn't multitask, but for the sake of a consistent interface
128 the code behaves like it does. pexecute runs the program, tucks the
129 exit code away, and returns a "pid". pwait must be called to fetch the
130 exit code. */
131
132#include <process.h>
133
134/* For communicating information from pexecute to pwait. */
135static int last_pid = 0;
136static int last_status = 0;
137static int last_reaped = 0;
138
139int
140pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
141 const char *program;
142 char * const *argv;
143 const char *this_pname;
144 const char *temp_base;
145 char **errmsg_fmt, **errmsg_arg;
146 int flags;
147{
148 int rc;
149
150 last_pid++;
151 if (last_pid < 0)
152 last_pid = 1;
153
154 if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
155 abort ();
156
157#ifdef __GO32__
158 /* ??? What are the possible return values from spawnv? */
159 rc = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (1, program, argv);
160#else
161 char *scmd, *rf;
162 FILE *argfile;
163 int i, el = flags & PEXECUTE_SEARCH ? 4 : 0;
164
19e28e2a
ME
165 if (temp_base == 0)
166 temp_base = choose_temp_base ();
6599da04
JM
167 scmd = (char *) xmalloc (strlen (program) + strlen (temp_base) + 6 + el);
168 rf = scmd + strlen(program) + 2 + el;
169 sprintf (scmd, "%s%s @%s.gp", program,
170 (flags & PEXECUTE_SEARCH ? ".exe" : ""), temp_base);
171 argfile = fopen (rf, "w");
172 if (argfile == 0)
173 {
174 int errno_save = errno;
175 free (scmd);
176 errno = errno_save;
177 *errmsg_fmt = "cannot open `%s.gp'";
178 *errmsg_arg = temp_base;
179 return -1;
180 }
181
182 for (i=1; argv[i]; i++)
183 {
184 char *cp;
185 for (cp = argv[i]; *cp; cp++)
186 {
3f3726a3 187 if (*cp == '"' || *cp == '\'' || *cp == '\\' || ISSPACE (*cp))
6599da04
JM
188 fputc ('\\', argfile);
189 fputc (*cp, argfile);
190 }
191 fputc ('\n', argfile);
192 }
193 fclose (argfile);
194
195 rc = system (scmd);
196
197 {
198 int errno_save = errno;
199 remove (rf);
200 free (scmd);
201 errno = errno_save;
202 }
203#endif
204
205 if (rc == -1)
206 {
207 *errmsg_fmt = install_error_msg;
208 *errmsg_arg = program;
209 return -1;
210 }
211
212 /* Tuck the status away for pwait, and return a "pid". */
213 last_status = rc << 8;
214 return last_pid;
215}
216
217int
218pwait (pid, status, flags)
219 int pid;
220 int *status;
221 int flags;
222{
223 /* On MSDOS each pexecute must be followed by it's associated pwait. */
224 if (pid != last_pid
225 /* Called twice for the same child? */
226 || pid == last_reaped)
227 {
228 /* ??? ECHILD would be a better choice. Can we use it here? */
229 errno = EINVAL;
230 return -1;
231 }
232 /* ??? Here's an opportunity to canonicalize the values in STATUS.
233 Needed? */
234 *status = last_status;
235 last_reaped = last_pid;
236 return last_pid;
237}
238
239#endif /* MSDOS */
240
36eb4217 241#if defined (_WIN32) && ! defined (_UWIN)
6599da04
JM
242
243#include <process.h>
6599da04 244
89f602a7 245#ifdef __CYGWIN__
19ddc834
JM
246
247#define fix_argv(argvec) (argvec)
248
77aff459
MK
249extern int _spawnv ();
250extern int _spawnvp ();
251
89f602a7 252#else /* ! __CYGWIN__ */
19ddc834
JM
253
254/* This is a kludge to get around the Microsoft C spawn functions' propensity
255 to remove the outermost set of double quotes from all arguments. */
256
257const char * const *
258fix_argv (argvec)
259 char **argvec;
260{
261 int i;
262
263 for (i = 1; argvec[i] != 0; i++)
264 {
265 int len, j;
266 char *temp, *newtemp;
267
268 temp = argvec[i];
269 len = strlen (temp);
270 for (j = 0; j < len; j++)
271 {
272 if (temp[j] == '"')
273 {
274 newtemp = xmalloc (len + 2);
275 strncpy (newtemp, temp, j);
276 newtemp [j] = '\\';
277 strncpy (&newtemp [j+1], &temp [j], len-j);
278 newtemp [len+1] = 0;
279 temp = newtemp;
280 len++;
281 j++;
282 }
283 }
284
285 argvec[i] = temp;
286 }
287
aeecce42
MK
288 for (i = 0; argvec[i] != 0; i++)
289 {
290 if (strpbrk (argvec[i], " \t"))
291 {
292 int len, trailing_backslash;
293 char *temp;
294
295 len = strlen (argvec[i]);
296 trailing_backslash = 0;
297
298 /* There is an added complication when an arg with embedded white
299 space ends in a backslash (such as in the case of -iprefix arg
300 passed to cpp). The resulting quoted strings gets misinterpreted
301 by the command interpreter -- it thinks that the ending quote
302 is escaped by the trailing backslash and things get confused.
303 We handle this case by escaping the trailing backslash, provided
304 it was not escaped in the first place. */
305 if (len > 1
306 && argvec[i][len-1] == '\\'
307 && argvec[i][len-2] != '\\')
308 {
309 trailing_backslash = 1;
310 ++len; /* to escape the final backslash. */
311 }
312
313 len += 2; /* and for the enclosing quotes. */
314
315 temp = xmalloc (len + 1);
316 temp[0] = '"';
317 strcpy (temp + 1, argvec[i]);
318 if (trailing_backslash)
319 temp[len-2] = '\\';
320 temp[len-1] = '"';
321 temp[len] = '\0';
322
323 argvec[i] = temp;
324 }
325 }
326
19ddc834
JM
327 return (const char * const *) argvec;
328}
89f602a7 329#endif /* __CYGWIN__ */
19ddc834 330
77aff459
MK
331#include <io.h>
332#include <fcntl.h>
333#include <signal.h>
334
335/* mingw32 headers may not define the following. */
336
337#ifndef _P_WAIT
338# define _P_WAIT 0
339# define _P_NOWAIT 1
340# define _P_OVERLAY 2
341# define _P_NOWAITO 3
342# define _P_DETACH 4
343
344# define WAIT_CHILD 0
345# define WAIT_GRANDCHILD 1
346#endif
19ddc834 347
77aff459 348/* Win32 supports pipes */
6599da04
JM
349int
350pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
351 const char *program;
352 char * const *argv;
353 const char *this_pname;
354 const char *temp_base;
355 char **errmsg_fmt, **errmsg_arg;
356 int flags;
357{
358 int pid;
77aff459
MK
359 int pdes[2], org_stdin, org_stdout;
360 int input_desc, output_desc;
361 int retries, sleep_interval;
362
363 /* Pipe waiting from last process, to be used as input for the next one.
364 Value is STDIN_FILE_NO if no pipe is waiting
365 (i.e. the next command is the first of a group). */
366 static int last_pipe_input;
367
368 /* If this is the first process, initialize. */
369 if (flags & PEXECUTE_FIRST)
370 last_pipe_input = STDIN_FILE_NO;
371
372 input_desc = last_pipe_input;
373
374 /* If this isn't the last process, make a pipe for its output,
375 and record it as waiting to be the input to the next process. */
376 if (! (flags & PEXECUTE_LAST))
377 {
378 if (_pipe (pdes, 256, O_BINARY) < 0)
379 {
380 *errmsg_fmt = "pipe";
381 *errmsg_arg = NULL;
382 return -1;
383 }
384 output_desc = pdes[WRITE_PORT];
385 last_pipe_input = pdes[READ_PORT];
386 }
387 else
388 {
389 /* Last process. */
390 output_desc = STDOUT_FILE_NO;
391 last_pipe_input = STDIN_FILE_NO;
392 }
393
394 if (input_desc != STDIN_FILE_NO)
395 {
396 org_stdin = dup (STDIN_FILE_NO);
397 dup2 (input_desc, STDIN_FILE_NO);
398 close (input_desc);
399 }
400
401 if (output_desc != STDOUT_FILE_NO)
402 {
403 org_stdout = dup (STDOUT_FILE_NO);
404 dup2 (output_desc, STDOUT_FILE_NO);
405 close (output_desc);
406 }
6599da04 407
19ddc834
JM
408 pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv)
409 (_P_NOWAIT, program, fix_argv(argv));
77aff459
MK
410
411 if (input_desc != STDIN_FILE_NO)
412 {
413 dup2 (org_stdin, STDIN_FILE_NO);
414 close (org_stdin);
415 }
416
417 if (output_desc != STDOUT_FILE_NO)
418 {
419 dup2 (org_stdout, STDOUT_FILE_NO);
420 close (org_stdout);
421 }
422
6599da04
JM
423 if (pid == -1)
424 {
425 *errmsg_fmt = install_error_msg;
426 *errmsg_arg = program;
427 return -1;
428 }
77aff459 429
6599da04
JM
430 return pid;
431}
432
77aff459
MK
433/* MS CRTDLL doesn't return enough information in status to decide if the
434 child exited due to a signal or not, rather it simply returns an
435 integer with the exit code of the child; eg., if the child exited with
436 an abort() call and didn't have a handler for SIGABRT, it simply returns
437 with status = 3. We fix the status code to conform to the usual WIF*
438 macros. Note that WIFSIGNALED will never be true under CRTDLL. */
439
6599da04
JM
440int
441pwait (pid, status, flags)
442 int pid;
443 int *status;
444 int flags;
445{
89f602a7 446#ifdef __CYGWIN__
8d525fa8
CF
447 return wait (status);
448#else
77aff459
MK
449 int termstat;
450
451 pid = _cwait (&termstat, pid, WAIT_CHILD);
452
6599da04
JM
453 /* ??? Here's an opportunity to canonicalize the values in STATUS.
454 Needed? */
77aff459
MK
455
456 /* cwait returns the child process exit code in termstat.
457 A value of 3 indicates that the child caught a signal, but not
458 which one. Since only SIGABRT, SIGFPE and SIGINT do anything, we
459 report SIGABRT. */
460 if (termstat == 3)
461 *status = SIGABRT;
462 else
463 *status = (((termstat) & 0xff) << 8);
464
465 return pid;
89f602a7 466#endif /* __CYGWIN__ */
6599da04
JM
467}
468
36eb4217 469#endif /* _WIN32 && ! _UWIN */
6599da04
JM
470
471#ifdef OS2
472
473/* ??? Does OS2 have process.h? */
474extern int spawnv ();
475extern int spawnvp ();
476
477int
478pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
479 const char *program;
480 char * const *argv;
481 const char *this_pname;
482 const char *temp_base;
483 char **errmsg_fmt, **errmsg_arg;
484 int flags;
485{
486 int pid;
487
488 if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
489 abort ();
490 /* ??? Presumably 1 == _P_NOWAIT. */
491 pid = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (1, program, argv);
492 if (pid == -1)
493 {
494 *errmsg_fmt = install_error_msg;
495 *errmsg_arg = program;
496 return -1;
497 }
498 return pid;
499}
500
501int
502pwait (pid, status, flags)
503 int pid;
504 int *status;
505 int flags;
506{
507 /* ??? Here's an opportunity to canonicalize the values in STATUS.
508 Needed? */
509 int pid = wait (status);
510 return pid;
511}
512
513#endif /* OS2 */
514
515#ifdef MPW
516
517/* MPW pexecute doesn't actually run anything; instead, it writes out
518 script commands that, when run, will do the actual executing.
519
520 For example, in GCC's case, GCC will write out several script commands:
521
522 cpp ...
523 cc1 ...
524 as ...
525 ld ...
526
527 and then exit. None of the above programs will have run yet. The task
528 that called GCC will then execute the script and cause cpp,etc. to run.
529 The caller must invoke pfinish before calling exit. This adds
530 the finishing touches to the generated script. */
531
532static int first_time = 1;
533
534int
535pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
536 const char *program;
3f3726a3 537 char * const *argv;
6599da04
JM
538 const char *this_pname;
539 const char *temp_base;
540 char **errmsg_fmt, **errmsg_arg;
541 int flags;
542{
543 char tmpprogram[255];
544 char *cp, *tmpname;
545 int i;
546
547 mpwify_filename (program, tmpprogram);
548 if (first_time)
549 {
550 printf ("Set Failed 0\n");
551 first_time = 0;
552 }
553
554 fputs ("If {Failed} == 0\n", stdout);
555 /* If being verbose, output a copy of the command. It should be
556 accurate enough and escaped enough to be "clickable". */
557 if (flags & PEXECUTE_VERBOSE)
558 {
559 fputs ("\tEcho ", stdout);
560 fputc ('\'', stdout);
561 fputs (tmpprogram, stdout);
562 fputc ('\'', stdout);
563 fputc (' ', stdout);
564 for (i=1; argv[i]; i++)
565 {
6599da04 566 fputc ('\'', stdout);
3f3726a3
JL
567 /* See if we have an argument that needs fixing. */
568 if (strchr(argv[i], '/'))
569 {
570 tmpname = (char *) xmalloc (256);
571 mpwify_filename (argv[i], tmpname);
572 argv[i] = tmpname;
573 }
6599da04
JM
574 for (cp = argv[i]; *cp; cp++)
575 {
3f3726a3
JL
576 /* Write an Option-d escape char in front of special chars. */
577 if (strchr("'+", *cp))
6599da04
JM
578 fputc ('\266', stdout);
579 fputc (*cp, stdout);
580 }
581 fputc ('\'', stdout);
582 fputc (' ', stdout);
583 }
584 fputs ("\n", stdout);
585 }
586 fputs ("\t", stdout);
587 fputs (tmpprogram, stdout);
588 fputc (' ', stdout);
589
590 for (i=1; argv[i]; i++)
591 {
3f3726a3
JL
592 /* See if we have an argument that needs fixing. */
593 if (strchr(argv[i], '/'))
594 {
595 tmpname = (char *) xmalloc (256);
596 mpwify_filename (argv[i], tmpname);
597 argv[i] = tmpname;
598 }
6599da04
JM
599 if (strchr (argv[i], ' '))
600 fputc ('\'', stdout);
601 for (cp = argv[i]; *cp; cp++)
602 {
3f3726a3
JL
603 /* Write an Option-d escape char in front of special chars. */
604 if (strchr("'+", *cp))
605 fputc ('\266', stdout);
6599da04
JM
606 fputc (*cp, stdout);
607 }
608 if (strchr (argv[i], ' '))
609 fputc ('\'', stdout);
610 fputc (' ', stdout);
611 }
612
613 fputs ("\n", stdout);
614
615 /* Output commands that arrange to clean up and exit if a failure occurs.
616 We have to be careful to collect the status from the program that was
617 run, rather than some other script command. Also, we don't exit
618 immediately, since necessary cleanups are at the end of the script. */
619 fputs ("\tSet TmpStatus {Status}\n", stdout);
620 fputs ("\tIf {TmpStatus} != 0\n", stdout);
621 fputs ("\t\tSet Failed {TmpStatus}\n", stdout);
622 fputs ("\tEnd\n", stdout);
623 fputs ("End\n", stdout);
624
625 /* We're just composing a script, can't fail here. */
626 return 0;
627}
628
629int
630pwait (pid, status, flags)
631 int pid;
632 int *status;
633 int flags;
634{
635 *status = 0;
636 return 0;
637}
638
639/* Write out commands that will exit with the correct error code
640 if something in the script failed. */
641
642void
643pfinish ()
644{
645 printf ("\tExit \"{Failed}\"\n");
646}
647
648#endif /* MPW */
649
650/* include for Unix-like environments but not for Dos-like environments */
651#if ! defined (__MSDOS__) && ! defined (OS2) && ! defined (MPW) \
36eb4217 652 && ! (defined (_WIN32) && ! defined (_UWIN))
6599da04 653
6599da04
JM
654extern int execv ();
655extern int execvp ();
656
657int
658pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
659 const char *program;
660 char * const *argv;
661 const char *this_pname;
5ad5a984 662 const char *temp_base ATTRIBUTE_UNUSED;
6599da04
JM
663 char **errmsg_fmt, **errmsg_arg;
664 int flags;
665{
666 int (*func)() = (flags & PEXECUTE_SEARCH ? execvp : execv);
667 int pid;
668 int pdes[2];
669 int input_desc, output_desc;
670 int retries, sleep_interval;
671 /* Pipe waiting from last process, to be used as input for the next one.
672 Value is STDIN_FILE_NO if no pipe is waiting
673 (i.e. the next command is the first of a group). */
674 static int last_pipe_input;
675
676 /* If this is the first process, initialize. */
677 if (flags & PEXECUTE_FIRST)
678 last_pipe_input = STDIN_FILE_NO;
679
680 input_desc = last_pipe_input;
681
682 /* If this isn't the last process, make a pipe for its output,
683 and record it as waiting to be the input to the next process. */
684 if (! (flags & PEXECUTE_LAST))
685 {
686 if (pipe (pdes) < 0)
687 {
688 *errmsg_fmt = "pipe";
689 *errmsg_arg = NULL;
690 return -1;
691 }
692 output_desc = pdes[WRITE_PORT];
693 last_pipe_input = pdes[READ_PORT];
694 }
695 else
696 {
697 /* Last process. */
698 output_desc = STDOUT_FILE_NO;
699 last_pipe_input = STDIN_FILE_NO;
700 }
701
702 /* Fork a subprocess; wait and retry if it fails. */
703 sleep_interval = 1;
704 for (retries = 0; retries < 4; retries++)
705 {
706 pid = vfork ();
707 if (pid >= 0)
708 break;
709 sleep (sleep_interval);
710 sleep_interval *= 2;
711 }
712
713 switch (pid)
714 {
715 case -1:
716 {
c5f7c445 717 *errmsg_fmt = VFORK_STRING;
6599da04
JM
718 *errmsg_arg = NULL;
719 return -1;
720 }
721
722 case 0: /* child */
723 /* Move the input and output pipes into place, if necessary. */
724 if (input_desc != STDIN_FILE_NO)
725 {
726 close (STDIN_FILE_NO);
727 dup (input_desc);
728 close (input_desc);
729 }
730 if (output_desc != STDOUT_FILE_NO)
731 {
732 close (STDOUT_FILE_NO);
733 dup (output_desc);
734 close (output_desc);
735 }
736
737 /* Close the parent's descs that aren't wanted here. */
738 if (last_pipe_input != STDIN_FILE_NO)
739 close (last_pipe_input);
740
741 /* Exec the program. */
742 (*func) (program, argv);
743
744 /* Note: Calling fprintf and exit here doesn't seem right for vfork. */
745 fprintf (stderr, "%s: ", this_pname);
746 fprintf (stderr, install_error_msg, program);
6599da04 747 fprintf (stderr, ": %s\n", xstrerror (errno));
6599da04
JM
748 exit (-1);
749 /* NOTREACHED */
750 return 0;
751
752 default:
753 /* In the parent, after forking.
754 Close the descriptors that we made for this child. */
755 if (input_desc != STDIN_FILE_NO)
756 close (input_desc);
757 if (output_desc != STDOUT_FILE_NO)
758 close (output_desc);
759
760 /* Return child's process number. */
761 return pid;
762 }
763}
764
765int
766pwait (pid, status, flags)
767 int pid;
768 int *status;
5ad5a984 769 int flags ATTRIBUTE_UNUSED;
6599da04
JM
770{
771 /* ??? Here's an opportunity to canonicalize the values in STATUS.
772 Needed? */
773#ifdef VMS
774 pid = waitpid (-1, status, 0);
775#else
776 pid = wait (status);
777#endif
778 return pid;
779}
780
36eb4217 781#endif /* ! __MSDOS__ && ! OS2 && ! MPW && ! (_WIN32 && ! _UWIN) */