mirror of
git://git.sv.gnu.org/findutils.git
synced 2026-01-30 21:28:58 +01:00
Remove "lib/wait.h", since gnulib provides <sys/wait.h>. * lib/Makefile.am (EXTRA_DIST): Remove wait.h, since gnulib provides it. * lib/wait.h: Not needed. * find/pred.c: Include <sys/wait.h> instead of "wait.h". * lib/waitpid.c: Likewise. * xargs/xargs.c: Likewise. Remove unnecessary include guards. * lib/dircallback.c: gnulib provides <locale.h>, so no need for include guards. * locate/locate.c: Likewise. * lib/listfile.c: Likewise. * lib/savedirinfo.c: Likewise with <sys/stat.h> * find/defs.h: gnulib provides <inttypes.h>, so no need for include guards. * lib/nextelem.c: Likewise with <string.h> and <stdlib.h>. * locate/bigram.c: Likewise. * locate/frcode.c: Likewise. * lib/buildcmd.c: Likewise with <locale.h> and <wchar.h> * xargs/xargs.c: Likewise with <locale.h>, <wchar.h> and <stdlib.h> * import-gnulib.config (modules): Import the mbrtowc and whchar modules. * lib/qmark.c (multibyte_qmark_chars): Don't surround with HAVE_MBRTOWC, since we now have a replacement for mbrtowc. Likewise, don't protect inclusion of <string.h> with HAVE_STRING_H. Likewise with <wchar.h>. (multibyte_qmark_chars): Rename to qmark_chars. (qmark_chars): Remove old version (since it is replaced by the function that used to be multibyte_qmark_chars). * lib/printquoted.c: Don't include <wchar.h>, we don't need it. Signed-off-by: James Youngman <jay@gnu.org>
79 lines
1.9 KiB
C
79 lines
1.9 KiB
C
/* Emulate waitpid on systems that just have wait.
|
|
Copyright 1994, 1995, 1998, 1999 Free Software Foundation, Inc.
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include <config.h>
|
|
|
|
|
|
#include <errno.h>
|
|
#ifndef errno
|
|
extern int errno;
|
|
#endif
|
|
|
|
|
|
#if defined _MSC_VER || defined __MINGW32__
|
|
/* Native Woe32 API. */
|
|
#include <process.h>
|
|
#else
|
|
/* Unix API. */
|
|
#include <sys/wait.h>
|
|
#endif
|
|
|
|
#define WAITPID_CHILDREN 8
|
|
static pid_t waited_pid[WAITPID_CHILDREN];
|
|
static int waited_status[WAITPID_CHILDREN];
|
|
|
|
pid_t
|
|
waitpid (pid_t pid, int *stat_loc, int options)
|
|
{
|
|
int i;
|
|
pid_t p;
|
|
|
|
if (!options && (pid == -1 || 0 < pid))
|
|
{
|
|
/* If we have already waited for this child, return it immediately. */
|
|
for (i = 0; i < WAITPID_CHILDREN; i++)
|
|
{
|
|
p = waited_pid[i];
|
|
if (p && (p == pid || pid == -1))
|
|
{
|
|
waited_pid[i] = 0;
|
|
goto success;
|
|
}
|
|
}
|
|
|
|
/* The child has not returned yet; wait for it, accumulating status. */
|
|
for (i = 0; i < WAITPID_CHILDREN; i++)
|
|
if (! waited_pid[i])
|
|
{
|
|
p = wait (&waited_status[i]);
|
|
if (p < 0)
|
|
return p;
|
|
if (p == pid || pid == -1)
|
|
goto success;
|
|
waited_pid[i] = p;
|
|
}
|
|
}
|
|
|
|
/* We cannot emulate this wait call, e.g. because of too many children. */
|
|
errno = EINVAL;
|
|
return -1;
|
|
|
|
success:
|
|
if (stat_loc)
|
|
*stat_loc = waited_status[i];
|
|
return p;
|
|
}
|