1 //===-- String to integer conversion utils ----------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SYS_WAIT_WAIT4IMPL_H
10 #define LLVM_LIBC_SRC_SYS_WAIT_WAIT4IMPL_H
12 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
13 #include "src/__support/common.h"
14 #include "src/__support/error_or.h"
15 #include "src/errno/libc_errno.h"
18 #include <sys/syscall.h> // For syscall numbers.
21 namespace LIBC_NAMESPACE
{
24 // The implementation of wait here is very minimal. We will add more
25 // functionality and standard compliance in future.
27 LIBC_INLINE ErrorOr
<pid_t
> wait4impl(pid_t pid
, int *wait_status
, int options
,
28 struct rusage
*usage
) {
30 pid
= LIBC_NAMESPACE::syscall_impl
<pid_t
>(SYS_wait4
, pid
, wait_status
,
32 #elif defined(SYS_waitid)
36 } else if (pid
< -1) {
39 } else if (pid
== 0) {
46 pid
= LIBC_NAMESPACE::syscall_impl
<pid_t
>(SYS_waitid
, idtype
, pid
, &info
,
52 switch (info
.si_code
) {
54 *wait_status
= W_EXITCODE(info
.si_status
, 0);
57 *wait_status
= info
.si_status
| WCOREFLAG
;
60 *wait_status
= info
.si_status
;
64 *wait_status
= W_STOPCODE(info
.si_status
);
67 *wait_status
= __W_CONTINUED
;
75 #error "wait4 and waitid syscalls not available."
82 } // namespace internal
83 } // namespace LIBC_NAMESPACE
85 #endif // LLVM_LIBC_SRC_SYS_WAIT_WAIT4IMPL_H