1 /* clock_gettime -- Get current time from a POSIX clockid_t. Linux version.
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
23 #include "kernel-posix-cpu-timers.h"
25 #if defined(__UCLIBC_USE_TIME64__)
26 #include "internal/time64_helpers.h"
29 #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_gettime64)
30 #define SYSCALL_GETTIME \
32 struct __ts64_struct __ts64; \
33 retval = INLINE_SYSCALL (clock_gettime64, 2, clock_id, &__ts64); \
35 tp->tv_sec = __ts64.tv_sec; \
36 tp->tv_nsec = __ts64.tv_nsec; \
41 #define SYSCALL_GETTIME \
42 retval = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp); \
46 /* The REALTIME and MONOTONIC clock are definitely supported in the kernel. */
47 #define SYSDEP_GETTIME \
48 SYSDEP_GETTIME_CPUTIME \
49 case CLOCK_REALTIME: \
50 case CLOCK_MONOTONIC: \
53 /* We handled the REALTIME clock here. */
54 #define HANDLED_REALTIME 1
55 #define HANDLED_CPUTIME 1
57 #define SYSDEP_GETTIME_CPU SYSCALL_GETTIME
58 #define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
61 realtime_gettime (struct timespec
*tp
)
64 int retval
= gettimeofday (&tv
, NULL
);
66 /* Convert into `timespec'. */
67 TIMEVAL_TO_TIMESPEC (&tv
, tp
);
71 /* Get current value of CLOCK and store it in TP. */
73 clock_gettime (clockid_t clock_id
, struct timespec
*tp
)
76 #ifndef HANDLED_REALTIME
86 #ifndef HANDLED_REALTIME
88 retval
= gettimeofday (&tv
, NULL
);
90 TIMEVAL_TO_TIMESPEC (&tv
, tp
);
95 #ifdef SYSDEP_GETTIME_CPU