Introduce time64 support.
[uclibc-ng.git] / libc / sysdeps / linux / common / clock_gettime.c
bloba595bd691fac6b0f55bc07f69d8b5f3ba75739c8
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 #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_gettime64)
15 _syscall2_64(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp)
16 #elif defined(__NR_clock_gettime)
17 _syscall2(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp)
18 #else
19 # include <sys/time.h>
21 int clock_gettime(clockid_t clock_id, struct timespec* tp)
23 struct timeval tv;
24 int retval = -1;
26 switch (clock_id) {
27 case CLOCK_REALTIME:
28 /* In Linux, gettimeofday fails only on bad parameter.
29 * We know that here parameter isn't bad.
31 gettimeofday(&tv, NULL);
32 TIMEVAL_TO_TIMESPEC(&tv, tp);
33 retval = 0;
34 break;
36 default:
37 errno = EINVAL;
38 break;
41 return retval;
43 #endif