compat_wait4.c revision 1.4
11.4Schristos/*	$NetBSD: compat_wait4.c,v 1.4 2024/01/20 14:52:46 christos Exp $	*/
21.2Schristos
31.2Schristos/*-
41.2Schristos * Copyright (c) 2008 The NetBSD Foundation, Inc.
51.2Schristos * All rights reserved.
61.2Schristos *
71.2Schristos * This code is derived from software contributed to The NetBSD Foundation
81.2Schristos * by Christos Zoulas.
91.2Schristos *
101.2Schristos * Redistribution and use in source and binary forms, with or without
111.2Schristos * modification, are permitted provided that the following conditions
121.2Schristos * are met:
131.2Schristos * 1. Redistributions of source code must retain the above copyright
141.2Schristos *    notice, this list of conditions and the following disclaimer.
151.2Schristos * 2. Redistributions in binary form must reproduce the above copyright
161.2Schristos *    notice, this list of conditions and the following disclaimer in the
171.2Schristos *    documentation and/or other materials provided with the distribution.
181.2Schristos *
191.2Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.2Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.2Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.2Schristos * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.2Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.2Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.2Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.2Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.2Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.2Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.2Schristos * POSSIBILITY OF SUCH DAMAGE.
301.2Schristos */
311.2Schristos
321.2Schristos#include <sys/cdefs.h>
331.2Schristos#if defined(LIBC_SCCS) && !defined(lint)
341.4Schristos__RCSID("$NetBSD: compat_wait4.c,v 1.4 2024/01/20 14:52:46 christos Exp $");
351.2Schristos#endif /* LIBC_SCCS and not lint */
361.2Schristos
371.2Schristos#define __LIBC12_SOURCE__
381.2Schristos
391.2Schristos#include "namespace.h"
401.2Schristos#include <sys/types.h>
411.2Schristos#include <sys/wait.h>
421.4Schristos#include <sys/resource.h>
431.2Schristos#include <compat/sys/wait.h>
441.2Schristos#include <compat/sys/resource.h>
451.2Schristos
461.2Schristos__warn_references(wait3,
471.2Schristos    "warning: reference to compatibility wait3(); include <sys/wait.h> to generate correct reference")
481.2Schristos__warn_references(wait4,
491.2Schristos    "warning: reference to compatibility wait4(); include <sys/wait.h> to generate correct reference")
501.2Schristos
511.2Schristos#ifdef __weak_alias
521.2Schristos__weak_alias(wait4, _wait4)
531.2Schristos__weak_alias(_sys_wait4, _wait4)
541.2Schristos__weak_alias(wait3, _wait3)
551.2Schristos#endif
561.2Schristos
571.2Schristos/*
581.2Schristos * libc12 compatible wait4 routine.
591.2Schristos */
601.3Sjustinpid_t
611.2Schristoswait3(int *status, int options, struct rusage50 *ru50)
621.2Schristos{
631.2Schristos	struct rusage ru;
641.3Sjustin	pid_t rv;
651.2Schristos
661.2Schristos	if ((rv = __wait350(status, options, ru50 ? &ru : NULL)) == -1)
671.2Schristos		return rv;
681.2Schristos	if (ru50)
691.4Schristos		rusage_to_rusage50(&ru, ru50);
701.2Schristos	return rv;
711.2Schristos}
721.2Schristos
731.3Sjustinpid_t
741.2Schristoswait4(pid_t wpid, int *status, int options, struct rusage50 *ru50)
751.2Schristos{
761.2Schristos	struct rusage ru;
771.3Sjustin	pid_t rv;
781.2Schristos
791.2Schristos	if ((rv = __wait450(wpid, status, options, ru50 ? &ru : NULL)) == -1)
801.2Schristos		return rv;
811.2Schristos	if (ru50)
821.4Schristos		rusage_to_rusage50(&ru, ru50);
831.2Schristos	return rv;
841.2Schristos}
85