[2/8] Y2038: add function __localtime64

Message ID 20181121002844.14530-3-albert.aribaud@3adev.fr
State Superseded
Headers show
Series
  • Y2038 struct tm related patches
Related show

Commit Message

Albert ARIBAUD (3ADEV) Nov. 21, 2018, 12:28 a.m.
* include/time.h
	(__localtime64): Add.
	* time/localtime.c
	(__localtime64): Add.
	(__localtime): Compile only if __TIMERSIZE != 64.
---
 include/time.h   |  9 ++++++++-
 time/localtime.c | 15 +++++++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)

-- 
2.17.1

Patch

diff --git a/include/time.h b/include/time.h
index 37964f7b76..251a2b0329 100644
--- a/include/time.h
+++ b/include/time.h
@@ -56,9 +56,16 @@  extern time_t __mktime_internal (struct tm *__tp,
 				 struct tm *(*__func) (const time_t *,
 						       struct tm *),
 				 long int *__offset) attribute_hidden;
+
+#if __TIMESIZE == 64
+# define __localtime64 localtime
+#else
+extern struct tm *__localtime64 (const __time64_t *__timer);
+libc_hidden_proto (__localtime64)
+#endif
+
 extern struct tm *__localtime_r (const time_t *__timer,
 				 struct tm *__tp) attribute_hidden;
-
 extern struct tm *__gmtime_r (const time_t *__restrict __timer,
 			      struct tm *__restrict __tp);
 libc_hidden_proto (__gmtime_r)
diff --git a/time/localtime.c b/time/localtime.c
index 92dbfe0f8c..917e0db40a 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -21,7 +21,6 @@ 
 /* The C Standard says that localtime and gmtime return the same pointer.  */
 struct tm _tmbuf;
 
-
 /* Return the `struct tm' representation of *T in local time,
    using *TP to store the result.  */
 struct tm *
@@ -31,11 +30,23 @@  __localtime_r (const time_t *t, struct tm *tp)
 }
 weak_alias (__localtime_r, localtime_r)
 
-
 /* Return the `struct tm' representation of *T in local time.  */
+struct tm *
+__localtime64 (const __time64_t *t)
+{
+  return __tz_convert (*t, 1, &_tmbuf);
+}
+libc_hidden_def (__localtime64)
+
+/* Provide a 32-bit variant if needed */
+
+#if __TIMESIZE != 64
+
 struct tm *
 localtime (const time_t *t)
 {
   return __tz_convert (*t, 1, &_tmbuf);
 }
 libc_hidden_def (localtime)
+
+#endif