source: trunk/third/diffutils/waitpid.c @ 16149

Revision 16149, 1.8 KB checked in by rbasch, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16148, which included commits to RCS files with non-trunk default branches.
Line 
1/* Emulate waitpid on systems that just have wait.
2   Copyright (C) 1994 Free Software Foundation, Inc.
3
4This file is part of GNU DIFF.
5
6GNU DIFF is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU DIFF 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
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU DIFF; see the file COPYING.  If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20#include "system.h"
21
22#define WAITPID_CHILDREN 8
23static pid_t waited_pid[WAITPID_CHILDREN];
24static int waited_status[WAITPID_CHILDREN];
25
26pid_t
27waitpid (pid, stat_loc, options)
28     pid_t pid;
29     int *stat_loc;
30     int options;
31{
32  int i;
33  pid_t p;
34
35  if (!options  &&  (0 < pid || pid == -1))
36    {
37      /* If we have already waited for this child, return it immediately.  */
38      for (i = 0;  i < WAITPID_CHILDREN;  i++)
39        {
40          p = waited_pid[i];
41          if (p  &&  (p == pid  ||  pid == -1))
42            {
43              waited_pid[i] = 0;
44              goto success;
45            }
46        }
47
48      /* The child has not returned yet; wait for it, accumulating status.  */
49      for (i = 0;  i < WAITPID_CHILDREN;  i++)
50        if (! waited_pid[i])
51          {
52            p = wait (&waited_status[i]);
53            if (p < 0)
54              return p;
55            if (p == pid  ||  pid == -1)
56              goto success;
57            waited_pid[i] = p;
58          }
59    }
60
61  /* We cannot emulate this wait call, e.g. because of too many children.  */
62  abort ();
63
64success:
65  if (stat_loc)
66    *stat_loc = waited_status[i];
67  return p;
68}
Note: See TracBrowser for help on using the repository browser.