1218912Slstewart/*
2218912Slstewart * Copyright (c) 2000 Ben Lindstrom.  All rights reserved.
3218912Slstewart *
4218912Slstewart * Redistribution and use in source and binary forms, with or without
5218912Slstewart * modification, are permitted provided that the following conditions
6218912Slstewart * are met:
7220560Slstewart * 1. Redistributions of source code must retain the above copyright
8220560Slstewart *    notice, this list of conditions and the following disclaimer.
9218912Slstewart * 2. Redistributions in binary form must reproduce the above copyright
10218912Slstewart *    notice, this list of conditions and the following disclaimer in the
11218912Slstewart *    documentation and/or other materials provided with the distribution.
12218912Slstewart *
13218912Slstewart * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14218912Slstewart * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15218912Slstewart * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16218912Slstewart * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17218912Slstewart * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18218912Slstewart * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19218912Slstewart * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20218912Slstewart * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21218912Slstewart * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22218912Slstewart * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23218912Slstewart */
24218912Slstewart
25218912Slstewart#include "includes.h"
26218912Slstewart
27218912Slstewart#ifndef HAVE_WAITPID
28218912Slstewart#include <errno.h>
29218912Slstewart#include <sys/wait.h>
30218912Slstewart#include "bsd-waitpid.h"
31218912Slstewart
32218912Slstewartpid_t
33225583Slstewartwaitpid(int pid, int *stat_loc, int options)
34218912Slstewart{
35218912Slstewart	union wait statusp;
36218912Slstewart	pid_t wait_pid;
37218912Slstewart
38218912Slstewart	if (pid <= 0) {
39218912Slstewart		if (pid != -1) {
40218912Slstewart			errno = EINVAL;
41218912Slstewart			return (-1);
42218912Slstewart		}
43218912Slstewart		/* wait4() wants pid=0 for indiscriminate wait. */
44218912Slstewart		pid = 0;
45218912Slstewart	}
46218912Slstewart        wait_pid = wait4(pid, &statusp, options, NULL);
47218912Slstewart	if (stat_loc)
48218912Slstewart        	*stat_loc = (int) statusp.w_status;
49218912Slstewart
50218912Slstewart        return (wait_pid);
51218912Slstewart}
52218912Slstewart
53218912Slstewart#endif /* !HAVE_WAITPID */
54218912Slstewart