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"
15 #include <sys/syscall.h> // For syscall numbers.
18 namespace __llvm_libc
{
20 LLVM_LIBC_FUNCTION(time_t, time
, (time_t * tp
)) {
21 // TODO: Use the Linux VDSO to fetch the time and avoid the syscall.
23 long ret_val
= __llvm_libc::syscall_impl(SYS_clock_gettime
, CLOCK_REALTIME
,
24 reinterpret_cast<long>(&ts
));
26 libc_errno
= -ret_val
;
31 *tp
= time_t(ts
.tv_sec
);
32 return time_t(ts
.tv_sec
);
35 } // namespace __llvm_libc