bsd-waitpid.c revision 98937
198937Sdes/*
298937Sdes * Redistribution and use in source and binary forms, with or without
398937Sdes * modification, are permitted provided that the following conditions
498937Sdes * are met:
598937Sdes * 1. Redistributions of source code must retain the above copyright
698937Sdes *    notice, this list of conditions and the following disclaimer.
798937Sdes * 2. Redistributions in binary form must reproduce the above copyright
898937Sdes *    notice, this list of conditions and the following disclaimer in the
998937Sdes *    documentation and/or other materials provided with the distribution.
1098937Sdes *
1198937Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1298937Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1398937Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1498937Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1598937Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1698937Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1798937Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1898937Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1998937Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2098937Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2198937Sdes */
2298937Sdes
2398937Sdes#include "includes.h"
2498937Sdes
2598937SdesRCSID("$Id: bsd-waitpid.c,v 1.3 2001/03/26 05:35:34 mouring Exp $");
2698937Sdes
2798937Sdes#ifndef HAVE_WAITPID
2898937Sdes#include <errno.h>
2998937Sdes#include <sys/wait.h>
3098937Sdes#include "bsd-waitpid.h"
3198937Sdes
3298937Sdespid_t
3398937Sdeswaitpid(int pid, int *stat_loc, int options)
3498937Sdes{
3598937Sdes	union wait statusp;
3698937Sdes	pid_t wait_pid;
3798937Sdes
3898937Sdes	if (pid <= 0) {
3998937Sdes		if (pid != -1) {
4098937Sdes			errno = EINVAL;
4198937Sdes			return -1;
4298937Sdes		}
4398937Sdes		pid = 0;   /* wait4() wants pid=0 for indiscriminate wait. */
4498937Sdes	}
4598937Sdes        wait_pid = wait4(pid, &statusp, options, NULL);
4698937Sdes	if (stat_loc)
4798937Sdes        	*stat_loc = (int) statusp.w_status;
4898937Sdes
4998937Sdes        return wait_pid;
5098937Sdes}
5198937Sdes
5298937Sdes#endif /* !HAVE_WAITPID */
53