NEWS: Add advisories.
[glibc.git] / sysdeps / unix / sysv / linux / time.c
blobf8b0cee41cb73d6657f2b5d77e67563843f6b4ef
1 /* time -- Get number of seconds since Epoch. Linux version.
2 Copyright (C) 2020-2024 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 <https://www.gnu.org/licenses/>. */
19 /* Optimize the function call by setting the PLT directly to vDSO symbol. */
20 #ifdef USE_IFUNC_TIME
21 # include <time.h>
22 # include <sysdep.h>
23 # include <sysdep-vdso.h>
25 #ifdef SHARED
26 # include <dl-vdso.h>
27 # include <libc-vdso.h>
29 static time_t
30 time_syscall (time_t *t)
32 return INLINE_SYSCALL_CALL (time, t);
35 # undef INIT_ARCH
36 # define INIT_ARCH() \
37 void *vdso_time = dl_vdso_vsym (HAVE_TIME_VSYSCALL);
38 libc_ifunc (time,
39 vdso_time ? VDSO_IFUNC_RET (vdso_time)
40 : (void *) time_syscall);
42 # else
43 time_t
44 time (time_t *t)
46 return INLINE_VSYSCALL (time, 1, t);
48 # endif /* !SHARED */
49 #else /* USE_IFUNC_TIME */
50 # include <time.h>
51 # include <time-clockid.h>
52 # include <errno.h>
54 /* Return the time now, and store it in *TIMER if not NULL. */
56 __time64_t
57 __time64 (__time64_t *timer)
59 struct __timespec64 ts;
60 __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts);
62 if (timer != NULL)
63 *timer = ts.tv_sec;
64 return ts.tv_sec;
67 # if __TIMESIZE != 64
68 libc_hidden_def (__time64)
70 time_t
71 __time (time_t *timer)
73 __time64_t t = __time64 (NULL);
75 if (! in_time_t_range (t))
77 __set_errno (EOVERFLOW);
78 return -1;
81 if (timer != NULL)
82 *timer = t;
83 return t;
85 # endif
86 weak_alias (__time, time)
87 #endif