1 //===-- Implementation of timespec_get for Linux --------------------------===//
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 #include "src/time/timespec_get.h"
10 #include "hdr/time_macros.h"
11 #include "src/__support/common.h"
12 #include "src/__support/macros/config.h"
13 #include "src/__support/time/linux/clock_gettime.h"
14 #include "src/errno/libc_errno.h"
16 namespace LIBC_NAMESPACE_DECL
{
18 LLVM_LIBC_FUNCTION(int, timespec_get
, (struct timespec
* ts
, int base
)) {
22 clockid
= CLOCK_REALTIME
;
25 clockid
= CLOCK_MONOTONIC
;
28 clockid
= CLOCK_PROCESS_CPUTIME_ID
;
30 case TIME_THREAD_ACTIVE
:
31 clockid
= CLOCK_THREAD_CPUTIME_ID
;
37 auto result
= internal::clock_gettime(clockid
, ts
);
38 if (!result
.has_value()) {
39 libc_errno
= result
.error();
45 } // namespace LIBC_NAMESPACE_DECL