xref: /llvm-project/libc/src/time/linux/clock_gettime.cpp (revision e6cf5d2863b77895ae7183952514bedd9e8dde16)
1123bf084SMikhail R. Gadelha //===---------- Linux implementation of the POSIX clock_gettime function --===//
2123bf084SMikhail R. Gadelha //
3123bf084SMikhail R. Gadelha // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4123bf084SMikhail R. Gadelha // See https://llvm.org/LICENSE.txt for license information.
5123bf084SMikhail R. Gadelha // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6123bf084SMikhail R. Gadelha //
7123bf084SMikhail R. Gadelha //===----------------------------------------------------------------------===//
8123bf084SMikhail R. Gadelha 
9123bf084SMikhail R. Gadelha #include "src/time/clock_gettime.h"
10123bf084SMikhail R. Gadelha #include "src/__support/common.h"
115ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
12*e6cf5d28SSchrodinger ZHU Yifan #include "src/__support/time/clock_gettime.h"
13123bf084SMikhail R. Gadelha #include "src/errno/libc_errno.h"
14123bf084SMikhail R. Gadelha 
155ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
16123bf084SMikhail R. Gadelha 
17123bf084SMikhail R. Gadelha // TODO(michaelrj): Move this into time/linux with the other syscalls.
18123bf084SMikhail R. Gadelha LLVM_LIBC_FUNCTION(int, clock_gettime,
19123bf084SMikhail R. Gadelha                    (clockid_t clockid, struct timespec *ts)) {
20d8e73752SSchrodinger ZHU Yifan   auto result = internal::clock_gettime(clockid, ts);
21123bf084SMikhail R. Gadelha 
22123bf084SMikhail R. Gadelha   // A negative return value indicates an error with the magnitude of the
23123bf084SMikhail R. Gadelha   // value being the error code.
24123bf084SMikhail R. Gadelha   if (!result.has_value()) {
25123bf084SMikhail R. Gadelha     libc_errno = result.error();
26123bf084SMikhail R. Gadelha     return -1;
27123bf084SMikhail R. Gadelha   }
28123bf084SMikhail R. Gadelha   return 0;
29123bf084SMikhail R. Gadelha }
30123bf084SMikhail R. Gadelha 
315ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
32