xref: /openbsd-src/gnu/usr.bin/cvs/vms/waitpid.c (revision 43c1707e6f6829177cb1974ee6615ce6c1307689)
150bf276cStholo /* Emulate waitpid on systems that just have wait.
250bf276cStholo    Copyright (C) 1994 Free Software Foundation, Inc.
350bf276cStholo 
450bf276cStholo This file is part of GNU DIFF.
550bf276cStholo 
650bf276cStholo GNU DIFF is free software; you can redistribute it and/or modify
750bf276cStholo it under the terms of the GNU General Public License as published by
850bf276cStholo the Free Software Foundation; either version 2, or (at your option)
950bf276cStholo any later version.
1050bf276cStholo 
1150bf276cStholo GNU DIFF is distributed in the hope that it will be useful,
1250bf276cStholo but WITHOUT ANY WARRANTY; without even the implied warranty of
1350bf276cStholo MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14461cc63eStholo GNU General Public License for more details.  */
1550bf276cStholo 
16*43c1707eStholo #ifndef __VMS_VER
17*43c1707eStholo #define __VMS_VER 0
18*43c1707eStholo #endif
19*43c1707eStholo #ifndef __DECC_VER
20*43c1707eStholo #define __DECC_VER 0
21*43c1707eStholo #endif
22*43c1707eStholo 
23*43c1707eStholo #if __VMS_VER < 70200000 || __DECC_VER < 50700000
24*43c1707eStholo 
2550bf276cStholo #include "vms.h"
2650bf276cStholo 
2750bf276cStholo #define WAITPID_CHILDREN 8
2850bf276cStholo static pid_t waited_pid[WAITPID_CHILDREN];
2950bf276cStholo static int waited_status[WAITPID_CHILDREN];
3050bf276cStholo 
3150bf276cStholo pid_t
waitpid(pid,stat_loc,options)3250bf276cStholo waitpid (pid, stat_loc, options)
3350bf276cStholo      pid_t pid;
3450bf276cStholo      int *stat_loc;
3550bf276cStholo      int options;
3650bf276cStholo {
3750bf276cStholo   int i;
3850bf276cStholo   pid_t p;
3950bf276cStholo 
4050bf276cStholo   if (!options  &&  (0 < pid || pid == -1))
4150bf276cStholo     {
4250bf276cStholo       /* If we have already waited for this child, return it immediately.  */
4350bf276cStholo       for (i = 0;  i < WAITPID_CHILDREN;  i++)
4450bf276cStholo 	{
4550bf276cStholo 	  p = waited_pid[i];
4650bf276cStholo 	  if (p  &&  (p == pid  ||  pid == -1))
4750bf276cStholo 	    {
4850bf276cStholo 	      waited_pid[i] = 0;
4950bf276cStholo 	      goto success;
5050bf276cStholo 	    }
5150bf276cStholo 	}
5250bf276cStholo 
5350bf276cStholo       /* The child has not returned yet; wait for it, accumulating status.  */
5450bf276cStholo       for (i = 0;  i < WAITPID_CHILDREN;  i++)
5550bf276cStholo 	if (! waited_pid[i])
5650bf276cStholo 	  {
5750bf276cStholo 	    p = wait (&waited_status[i]);
5850bf276cStholo 	    if (p < 0)
5950bf276cStholo 	      return p;
6050bf276cStholo 	    if (p == pid  ||  pid == -1)
6150bf276cStholo 	      goto success;
6250bf276cStholo 	    waited_pid[i] = p;
6350bf276cStholo 	  }
6450bf276cStholo     }
6550bf276cStholo 
6650bf276cStholo   /* We cannot emulate this wait call, e.g. because of too many children.  */
6750bf276cStholo   abort ();
6850bf276cStholo 
6950bf276cStholo success:
7050bf276cStholo   if (stat_loc)
7150bf276cStholo     *stat_loc = waited_status[i];
7250bf276cStholo   return p;
7350bf276cStholo }
74*43c1707eStholo 
75*43c1707eStholo #else  /*  __VMS_VER >= 70200000 && __DECC_VER >= 50700000  */
76*43c1707eStholo #pragma message disable EMPTYFILE
77*43c1707eStholo #endif  /*  __VMS_VER >= 70200000 && __DECC_VER >= 50700000  */
78