1 //===-- Linux implementation of the time function -------------------------===//
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/time_func.h"
11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12 #include "src/__support/common.h"
13 #include "src/errno/libc_errno.h"
14 #include "src/time/linux/clockGetTimeImpl.h"
16 #include <sys/syscall.h> // For syscall numbers.
19 namespace LIBC_NAMESPACE
{
21 LLVM_LIBC_FUNCTION(time_t, time
, (time_t * tp
)) {
22 // TODO: Use the Linux VDSO to fetch the time and avoid the syscall.
24 auto result
= internal::clock_gettimeimpl(CLOCK_REALTIME
, &ts
);
25 if (!result
.has_value()) {
26 libc_errno
= result
.error();
31 *tp
= time_t(ts
.tv_sec
);
32 return time_t(ts
.tv_sec
);
35 } // namespace LIBC_NAMESPACE