]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/clock_gettime.c
Finish move of clock_* functions to libc. [BZ #24959]
[thirdparty/glibc.git] / sysdeps / unix / clock_gettime.c
CommitLineData
2f4f3bd4 1/* clock_gettime -- Get the current time from a POSIX clockid_t. Unix version.
04277e02 2 Copyright (C) 1999-2019 Free Software Foundation, Inc.
13fa3676
UD
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
41bdb6e2
AJ
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.
13fa3676
UD
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
41bdb6e2 13 Lesser General Public License for more details.
13fa3676 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
13fa3676
UD
18
19#include <errno.h>
8be918b7 20#include <time.h>
13fa3676 21#include <sys/time.h>
7b5af2d8 22#include <shlib-compat.h>
2f4f3bd4 23
13fa3676
UD
24/* Get current value of CLOCK and store it in TP. */
25int
89fb6835 26__clock_gettime (clockid_t clock_id, struct timespec *tp)
13fa3676 27{
4a199526 28 int retval = -1;
13fa3676
UD
29
30 switch (clock_id)
31 {
32 case CLOCK_REALTIME:
701666b7
UD
33 {
34 struct timeval tv;
fcafcd16 35 retval = __gettimeofday (&tv, NULL);
701666b7
UD
36 if (retval == 0)
37 TIMEVAL_TO_TIMESPEC (&tv, tp);
38 }
13fa3676
UD
39 break;
40
4165d44d 41 default:
38cc11da 42 __set_errno (EINVAL);
2f4f3bd4 43 break;
13fa3676
UD
44 }
45
46 return retval;
47}
89fb6835 48libc_hidden_def (__clock_gettime)
7b5af2d8
ZW
49
50versioned_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)
54strong_alias (__clock_gettime, __clock_gettime_2);
55compat_symbol (libc, __clock_gettime_2, clock_gettime, GLIBC_2_2);
56#endif