198937Sdes/*
2124208Sdes * Copyright (c) 2000 Ben Lindstrom.  All rights reserved.
3124208Sdes *
498937Sdes * Redistribution and use in source and binary forms, with or without
598937Sdes * modification, are permitted provided that the following conditions
698937Sdes * are met:
798937Sdes * 1. Redistributions of source code must retain the above copyright
898937Sdes *    notice, this list of conditions and the following disclaimer.
998937Sdes * 2. Redistributions in binary form must reproduce the above copyright
1098937Sdes *    notice, this list of conditions and the following disclaimer in the
1198937Sdes *    documentation and/or other materials provided with the distribution.
1298937Sdes *
1398937Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1498937Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1598937Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1698937Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1798937Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1898937Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1998937Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2098937Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2198937Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2298937Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2398937Sdes */
2498937Sdes
2598937Sdes#include "includes.h"
2698937Sdes
27323134Sdes#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;
41124208Sdes			return (-1);
4298937Sdes		}
43124208Sdes		/* wait4() wants pid=0 for indiscriminate wait. */
44124208Sdes		pid = 0;
4598937Sdes	}
46323134Sdes	wait_pid = wait4(pid, &statusp, options, NULL);
4798937Sdes	if (stat_loc)
48323134Sdes		*stat_loc = (int) statusp.w_status;
4998937Sdes
50323134Sdes	return (wait_pid);
5198937Sdes}
5298937Sdes
5398937Sdes#endif /* !HAVE_WAITPID */
54