1//===-- Implementation file for getitimer ---------------------------------===//
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/sys/time/getitimer.h"
10#include "hdr/types/struct_itimerval.h"
11#include "src/__support/OSUtil/syscall.h"
12#include "src/__support/common.h"
13#include "src/__support/libc_errno.h"
14#include <sys/syscall.h>
15
16namespace LIBC_NAMESPACE_DECL {
17
18LLVM_LIBC_FUNCTION(int, getitimer, (int which, struct itimerval *curr_value)) {
19 long ret = 0;
20 if constexpr (sizeof(time_t) > sizeof(long)) {
21 // There is no SYS_getitimer_time64 call, so we can't use time_t directly.
22 long curr_value32[4];
23 ret =
24 LIBC_NAMESPACE::syscall_impl<long>(SYS_getitimer, which, curr_value32);
25 if (!ret) {
26 curr_value->it_interval.tv_sec = curr_value32[0];
27 curr_value->it_interval.tv_usec = curr_value32[1];
28 curr_value->it_value.tv_sec = curr_value32[2];
29 curr_value->it_value.tv_usec = curr_value32[3];
30 }
31 } else {
32 ret = LIBC_NAMESPACE::syscall_impl<long>(SYS_getitimer, which, curr_value);
33 }
34
35 // On failure, return -1 and set errno.
36 if (ret < 0) {
37 libc_errno = static_cast<int>(-ret);
38 return -1;
39 }
40 return 0;
41}
42
43} // namespace LIBC_NAMESPACE_DECL
44

source code of libc/src/sys/time/linux/getitimer.cpp