-/* Copyright (C) 2005-2019 Free Software Foundation, Inc.
+/* System specific time definitions. Generic Version.
+ Copyright 2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <stddef.h>
-#include <time.h>
-
-#include <sysdep.h>
-
-#ifdef __NR_time
-
-time_t
-time (time_t *t)
-{
- INTERNAL_SYSCALL_DECL (err);
- time_t res = INTERNAL_SYSCALL (time, err, 1, NULL);
- /* There cannot be any error. */
- if (t != NULL)
- *t = res;
- return res;
-}
-libc_hidden_def (time)
-
-#else
-
-# include <sysdeps/posix/time.c>
-
-#endif
+/* Timer used on clock_gettime for time implementation. */
+#define TIME_CLOCK_GETTIME_CLOCKID CLOCK_REALTIME
#else
-#include <sysdeps/posix/time.c>
+#include <time/time.c>
#endif /* !SHARED */
-/* Copyright (C) 1991-2019 Free Software Foundation, Inc.
+/* System specific time definitions. Generic Version.
+ Copyright 2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <stddef.h> /* For NULL. */
-#include <time.h>
-#include <sys/time.h>
-
-
-/* Return the current time as a `time_t' and also put it in *T if T is
- not NULL. Time is represented as seconds from Jan 1 00:00:00 1970. */
-time_t
-time (time_t *t)
-{
- struct timeval tv;
- time_t result;
-
- if (__gettimeofday (&tv, (struct timezone *) NULL))
- result = (time_t) -1;
- else
- result = (time_t) tv.tv_sec;
-
- if (t != NULL)
- *t = result;
- return result;
-}
-libc_hidden_def (time)
+/* Timer used on clock_gettime for time implementation. For Linux
+ it uses the coarse version which returns the time at the last tick
+ and mimic what time as syscall should return. */
+#define TIME_CLOCK_GETTIME_CLOCKID CLOCK_REALTIME_COARSE
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
#include <time.h>
+#include <time-clockid.h>
/* Return the time now, and store it in *TIMER if not NULL. */
time_t
time (time_t *timer)
{
- __set_errno (ENOSYS);
+ struct timespec ts;
+ __clock_gettime (TIME_CLOCK_GETTIME_CLOCKID, &ts);
- if (timer != NULL)
- *timer = (time_t) -1;
- return (time_t) -1;
+ if (timer)
+ *timer = ts.tv_sec;
+ return ts.tv_sec;
}
libc_hidden_def (time)
-
-stub_warning (time)