diff mbox

[5/5] Y2038: add function __ctime64_r

Message ID 20181217220429.4599-6-albert.aribaud@3adev.fr
State New
Headers show

Commit Message

Albert ARIBAUD Dec. 17, 2018, 10:04 p.m. UTC
Tested with 'make check' on x86_64-linux-gnu and i686-linux.gnu.

	* include/time.h
	(__ctime64_r): Add.
	* time/ctime_r.c
	(__ctime64_r): Add.
	[__TIMESIZE != 64] (__ctime_r): Turn into a wrapper.
---
 include/time.h |  7 +++++++
 time/ctime_r.c | 17 +++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/include/time.h b/include/time.h
index dce17b1a71..5aa00cb7fa 100644
--- a/include/time.h
+++ b/include/time.h
@@ -63,6 +63,13 @@  extern time_t __mktime_internal (struct tm *__tp,
 extern char *__ctime64 (const __time64_t *__timer) __THROW;
 #endif
 
+#if __TIMESIZE == 64
+# define __ctime64_r ctime_r
+#else
+extern char *__ctime64_r (const __time64_t *__restrict __timer,
+		          char *__restrict __buf) __THROW;
+#endif
+
 #if __TIMESIZE == 64
 # define __localtime64 localtime
 #else
diff --git a/time/ctime_r.c b/time/ctime_r.c
index c111146d76..0041fbf312 100644
--- a/time/ctime_r.c
+++ b/time/ctime_r.c
@@ -22,8 +22,21 @@ 
 /* Return a string as returned by asctime which is the representation
    of *T in that form.  Reentrant version.  */
 char *
-ctime_r (const time_t *t, char *buf)
+__ctime64_r (const __time64_t *t, char *buf)
 {
   struct tm tm;
-  return __asctime_r (__localtime_r (t, &tm), buf);
+  return __asctime_r (__localtime64_r (t, &tm), buf);
 }
+
+/* Provide a 32-bit variant if needed */
+
+#if __TIMESIZE != 64
+
+char *
+ctime_r (const time_t *t, char *buf)
+{
+  __time64_t t64 = *t;
+  return __ctime64_r (&t64, buf);
+}
+
+#endif