Fix prototypes for preadv pwritev.
[uclibc-ng.git] / librt / clock_gettime.c
blobe65d39d442d6be595f80794c661145499659c48c
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/>. */
19 #include <errno.h>
20 #include <sysdep.h>
21 #include <time.h>
22 #include <sys/time.h>
23 #include "kernel-posix-cpu-timers.h"
26 #define SYSCALL_GETTIME \
27 retval = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp); \
28 break
30 /* The REALTIME and MONOTONIC clock are definitely supported in the kernel. */
31 #define SYSDEP_GETTIME \
32 SYSDEP_GETTIME_CPUTIME \
33 case CLOCK_REALTIME: \
34 case CLOCK_MONOTONIC: \
35 SYSCALL_GETTIME
37 /* We handled the REALTIME clock here. */
38 #define HANDLED_REALTIME 1
39 #define HANDLED_CPUTIME 1
41 #define SYSDEP_GETTIME_CPU SYSCALL_GETTIME
42 #define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */
44 static inline int
45 realtime_gettime (struct timespec *tp)
47 struct timeval tv;
48 int retval = gettimeofday (&tv, NULL);
49 if (retval == 0)
50 /* Convert into `timespec'. */
51 TIMEVAL_TO_TIMESPEC (&tv, tp);
52 return retval;
55 /* Get current value of CLOCK and store it in TP. */
56 int
57 clock_gettime (clockid_t clock_id, struct timespec *tp)
59 int retval = -1;
60 #ifndef HANDLED_REALTIME
61 struct timeval tv;
62 #endif
64 switch (clock_id)
66 #ifdef SYSDEP_GETTIME
67 SYSDEP_GETTIME;
68 #endif
70 #ifndef HANDLED_REALTIME
71 case CLOCK_REALTIME:
72 retval = gettimeofday (&tv, NULL);
73 if (retval == 0)
74 TIMEVAL_TO_TIMESPEC (&tv, tp);
75 break;
76 #endif
78 default:
79 #ifdef SYSDEP_GETTIME_CPU
80 SYSDEP_GETTIME_CPU;
81 #endif
82 __set_errno (EINVAL);
83 break;
86 return retval;