xref: /freebsd/crypto/openssh/openbsd-compat/bsd-waitpid.h (revision 19261079b74319502c6ffa1249920079f0f69a72)
183d2307dSDag-Erling Smørgrav /*
2d95e11bfSDag-Erling Smørgrav  * Copyright (c) 2000 Ben Lindstrom.  All rights reserved.
3d95e11bfSDag-Erling Smørgrav  *
483d2307dSDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
583d2307dSDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
683d2307dSDag-Erling Smørgrav  * are met:
783d2307dSDag-Erling Smørgrav  * 1. Redistributions of source code must retain the above copyright
883d2307dSDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer.
983d2307dSDag-Erling Smørgrav  * 2. Redistributions in binary form must reproduce the above copyright
1083d2307dSDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer in the
1183d2307dSDag-Erling Smørgrav  *    documentation and/or other materials provided with the distribution.
1283d2307dSDag-Erling Smørgrav  *
1383d2307dSDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1483d2307dSDag-Erling Smørgrav  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1583d2307dSDag-Erling Smørgrav  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1683d2307dSDag-Erling Smørgrav  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1783d2307dSDag-Erling Smørgrav  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1883d2307dSDag-Erling Smørgrav  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1983d2307dSDag-Erling Smørgrav  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2083d2307dSDag-Erling Smørgrav  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2183d2307dSDag-Erling Smørgrav  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2283d2307dSDag-Erling Smørgrav  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2383d2307dSDag-Erling Smørgrav  *
2483d2307dSDag-Erling Smørgrav  */
2583d2307dSDag-Erling Smørgrav 
2683d2307dSDag-Erling Smørgrav #ifndef _BSD_WAITPID_H
2783d2307dSDag-Erling Smørgrav #define _BSD_WAITPID_H
2883d2307dSDag-Erling Smørgrav 
2983d2307dSDag-Erling Smørgrav #ifndef HAVE_WAITPID
30*190cef3dSDag-Erling Smørgrav /* Clean out any potential issues */
3183d2307dSDag-Erling Smørgrav #undef WIFEXITED
3283d2307dSDag-Erling Smørgrav #undef WIFSTOPPED
3383d2307dSDag-Erling Smørgrav #undef WIFSIGNALED
3483d2307dSDag-Erling Smørgrav 
3583d2307dSDag-Erling Smørgrav /* Define required functions to mimic a POSIX look and feel */
3683d2307dSDag-Erling Smørgrav #define _W_INT(w)	(*(int*)&(w))	/* convert union wait to int */
3783d2307dSDag-Erling Smørgrav #define WIFEXITED(w)	(!((_W_INT(w)) & 0377))
3883d2307dSDag-Erling Smørgrav #define WIFSTOPPED(w)	((_W_INT(w)) & 0100)
3983d2307dSDag-Erling Smørgrav #define WIFSIGNALED(w)	(!WIFEXITED(w) && !WIFSTOPPED(w))
4083d2307dSDag-Erling Smørgrav #define WEXITSTATUS(w)	(int)(WIFEXITED(w) ? ((_W_INT(w) >> 8) & 0377) : -1)
4183d2307dSDag-Erling Smørgrav #define WTERMSIG(w)	(int)(WIFSIGNALED(w) ? (_W_INT(w) & 0177) : -1)
4283d2307dSDag-Erling Smørgrav #define WCOREFLAG	0x80
4383d2307dSDag-Erling Smørgrav #define WCOREDUMP(w)	((_W_INT(w)) & WCOREFLAG)
4483d2307dSDag-Erling Smørgrav 
4583d2307dSDag-Erling Smørgrav /* Prototype */
46d95e11bfSDag-Erling Smørgrav pid_t waitpid(int, int *, int);
4783d2307dSDag-Erling Smørgrav 
4883d2307dSDag-Erling Smørgrav #endif /* !HAVE_WAITPID */
4983d2307dSDag-Erling Smørgrav #endif /* _BSD_WAITPID_H */
50