1 //===- Linux implementation of the POSIX clock_gettime function -*- 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_TIME_LINUX_CLOCKGETTIMEIMPL_H
10 #define LLVM_LIBC_SRC_TIME_LINUX_CLOCKGETTIMEIMPL_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"
17 #include <stdint.h> // For int64_t.
18 #include <sys/syscall.h> // For syscall numbers.
21 namespace LIBC_NAMESPACE
{
24 LIBC_INLINE ErrorOr
<int> clock_gettimeimpl(clockid_t clockid
,
25 struct timespec
*ts
) {
27 int ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_clock_gettime
,
28 static_cast<long>(clockid
),
29 reinterpret_cast<long>(ts
));
30 #elif defined(SYS_clock_gettime64)
32 sizeof(time_t) == sizeof(int64_t),
33 "SYS_clock_gettime64 requires struct timespec with 64-bit members.");
34 int ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_clock_gettime64
,
35 static_cast<long>(clockid
),
36 reinterpret_cast<long>(ts
));
38 #error "SYS_clock_gettime and SYS_clock_gettime64 syscalls not available."
45 } // namespace internal
46 } // namespace LIBC_NAMESPACE
48 #endif // LLVM_LIBC_SRC_TIME_LINUX_CLOCKGETTIMEIMPL_H