mips64: time64 for n32 ABI breaks a lot of tests, disable it for now
[uclibc-ng.git] / libc / sysdeps / linux / common / clock_gettime.c
blobb924d860b26ac271ef14ee8e055e125d91aefbc1
1 /*
2 * clock_gettime() for uClibc
4 * Copyright (C) 2003 by Justus Pendleton <uc@ryoohki.net>
5 * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
6 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
8 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
9 */
11 #include <sys/syscall.h>
12 #include <time.h>
14 #ifdef __VDSO_SUPPORT__
15 #include "ldso.h"
16 #endif
18 #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_gettime64)
19 #include "internal/time64_helpers.h"
21 int __libc_clock_gettime(clockid_t clock_id, struct timespec *tp)
23 struct __ts64_struct __ts64;
24 int __ret = INLINE_SYSCALL(clock_gettime64, 2, clock_id, &__ts64);
25 if (tp) {
26 tp->tv_sec = __ts64.tv_sec;
27 tp->tv_nsec = __ts64.tv_nsec;
30 return __ret;
32 #elif defined(__NR_clock_gettime)
33 int __libc_clock_gettime(clockid_t clock_id, struct timespec *tp)
35 return INLINE_SYSCALL(clock_gettime, 2, clock_id, tp);
37 #else
38 # include <sys/time.h>
40 int __libc_clock_gettime(clockid_t clock_id, struct timespec* tp)
42 struct timeval tv;
43 int retval = -1;
45 switch (clock_id) {
46 case CLOCK_REALTIME:
47 /* In Linux, gettimeofday fails only on bad parameter.
48 * We know that here parameter isn't bad.
50 gettimeofday(&tv, NULL);
51 TIMEVAL_TO_TIMESPEC(&tv, tp);
52 retval = 0;
53 break;
55 default:
56 errno = EINVAL;
57 break;
60 return retval;
62 #endif
64 int clock_gettime(clockid_t clock_id, struct timespec *tp)
66 #if defined(__VDSO_SUPPORT__) && defined(ARCH_VDSO_CLOCK_GETTIME)
67 return ARCH_VDSO_CLOCK_GETTIME(clock_id, tp);
68 #else
69 return __libc_clock_gettime(clock_id, tp);
70 #endif