[C++20] Destroying delete can cause a type to be noexcept when deleting (#118687)
[llvm-project.git] / libc / src / time / linux / nanosleep.cpp
blob7a856376ffb200fcf6ccd06dce5612c437b47d58
1 //===-- Linux implementation of nanosleep function ------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/time/nanosleep.h"
10 #include "hdr/time_macros.h"
11 #include "src/__support/OSUtil/syscall.h" // For syscall functions.
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 #include "src/errno/libc_errno.h"
16 #include <stdint.h> // For int64_t.
17 #include <sys/syscall.h> // For syscall numbers.
19 namespace LIBC_NAMESPACE_DECL {
21 LLVM_LIBC_FUNCTION(int, nanosleep,
22 (const struct timespec *req, struct timespec *rem)) {
23 #if SYS_nanosleep
24 int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_nanosleep, req, rem);
25 #elif defined(SYS_clock_nanosleep_time64)
26 static_assert(
27 sizeof(time_t) == sizeof(int64_t),
28 "SYS_clock_gettime64 requires struct timespec with 64-bit members.");
29 int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_clock_nanosleep_time64,
30 CLOCK_REALTIME, 0, req, rem);
31 #else
32 #error "SYS_nanosleep and SYS_clock_nanosleep_time64 syscalls not available."
33 #endif
35 if (ret < 0) {
36 libc_errno = -ret;
37 return -1;
39 return ret;
42 } // namespace LIBC_NAMESPACE_DECL