1 /* Emulate waitpid on systems that just have wait.
2 Copyright 1994, 1995, 1998, 1999, 2010, 2011 Free Software
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.
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.
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/>.
19 /* config.h must always be included first. */
26 /* TODO: replace this with gnulib's waitpid. */
27 #if defined _MSC_VER || defined __MINGW32__
28 /* Native Woe32 API. */
35 #define WAITPID_CHILDREN 8
36 static pid_t waited_pid[WAITPID_CHILDREN];
37 static int waited_status[WAITPID_CHILDREN];
40 waitpid (pid_t pid, int *stat_loc, int options)
45 if (!options && (pid == -1 || 0 < pid))
47 /* If we have already waited for this child, return it immediately. */
48 for (i = 0; i < WAITPID_CHILDREN; i++)
51 if (p && (p == pid || pid == -1))
58 /* The child has not returned yet; wait for it, accumulating status. */
59 for (i = 0; i < WAITPID_CHILDREN; i++)
62 p = wait (&waited_status[i]);
65 if (p == pid || pid == -1)
71 /* We cannot emulate this wait call, e.g. because of too many children. */
77 *stat_loc = waited_status[i];