1 //===---------- Linux implementation of the POSIX clock_gettime function --===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/time/clock_gettime.h" 10 #include "src/__support/common.h" 11 #include "src/__support/time/linux/clock_gettime.h" 12 #include "src/errno/libc_errno.h" 13 14 namespace LIBC_NAMESPACE { 15 16 // TODO(michaelrj): Move this into time/linux with the other syscalls. 17 LLVM_LIBC_FUNCTION(int, clock_gettime, 18 (clockid_t clockid, struct timespec *ts)) { 19 auto result = internal::clock_gettime(clockid, ts); 20 21 // A negative return value indicates an error with the magnitude of the 22 // value being the error code. 23 if (!result.has_value()) { 24 libc_errno = result.error(); 25 return -1; 26 } 27 return 0; 28 } 29 30 } // namespace LIBC_NAMESPACE 31