]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/clock_gettime.c
Finish move of clock_* functions to libc. [BZ #24959]
[thirdparty/glibc.git] / sysdeps / unix / clock_gettime.c
1 /* clock_gettime -- Get the current time from a POSIX clockid_t. Unix version.
2 Copyright (C) 1999-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 #include <errno.h>
20 #include <time.h>
21 #include <sys/time.h>
22 #include <shlib-compat.h>
23
24 /* Get current value of CLOCK and store it in TP. */
25 int
26 __clock_gettime (clockid_t clock_id, struct timespec *tp)
27 {
28 int retval = -1;
29
30 switch (clock_id)
31 {
32 case CLOCK_REALTIME:
33 {
34 struct timeval tv;
35 retval = __gettimeofday (&tv, NULL);
36 if (retval == 0)
37 TIMEVAL_TO_TIMESPEC (&tv, tp);
38 }
39 break;
40
41 default:
42 __set_errno (EINVAL);
43 break;
44 }
45
46 return retval;
47 }
48 libc_hidden_def (__clock_gettime)
49
50 versioned_symbol (libc, __clock_gettime, clock_gettime, GLIBC_2_17);
51 /* clock_gettime moved to libc in version 2.17;
52 old binaries may expect the symbol version it had in librt. */
53 #if SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_17)
54 strong_alias (__clock_gettime, __clock_gettime_2);
55 compat_symbol (libc, __clock_gettime_2, clock_gettime, GLIBC_2_2);
56 #endif