[2/5] Y2038: add function __gmtime64

Message ID 20181217220429.4599-3-albert.aribaud@3adev.fr
State New, archived
Headers

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
	(__gmtime64): Add.
	* time/gmtime.c
	(__gmtime64): Add.
	[__TIMESIZE != 64] (__gmtime): Turn into a wrapper.
---
 include/time.h |  4 ++++
 time/gmtime.c  | 17 +++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
  

Comments

Paul Eggert Dec. 17, 2018, 10:09 p.m. UTC | #1
On 12/17/18 2:04 PM, Albert ARIBAUD (3ADEV) wrote:
> +#if __TIMESIZE == 64
> +# define __gmtime64 gmtime
> +#endif

Why does this look different from the already-installed patch for 
__localtime64, which has the following before the #endif?

+#else
+extern struct tm *__localtime64 (const __time64_t *__timer);
+libc_hidden_proto (__localtime64)

> --- a/time/gmtime.c
> +++ b/time/gmtime.c
> @@ -25,13 +25,26 @@ __gmtime_r (const time_t *t, struct tm *tp)
>   {
>     return __tz_convert (*t, 0, tp);
>   }
> +
>   libc_hidden_def (__gmtime_r)
>   weak_alias (__gmtime_r, gmtime_r)

No need for this whitespace change.
  
Joseph Myers Dec. 17, 2018, 10:19 p.m. UTC | #2
On Mon, 17 Dec 2018, Albert ARIBAUD (3ADEV) wrote:

> +  return __gmtime64 (&t64, 0, &_tmbuf);

In all these patches, the __*64 function that gets called within glibc 
should have libc_hidden_proto / libc_hidden_def used accordingly.  (This 
results in more efficient function calls on 32-bit x86 because the 
compiler knows the call is a direct call within the same shared library 
that does not need to go via the PLT.)
  
Albert ARIBAUD Dec. 18, 2018, 9:13 a.m. UTC | #3
Hi Paul,

On Mon, 17 Dec 2018 14:09:01 -0800, Paul Eggert <eggert@cs.ucla.edu>
wrote :

> On 12/17/18 2:04 PM, Albert ARIBAUD (3ADEV) wrote:
> > +#if __TIMESIZE == 64
> > +# define __gmtime64 gmtime
> > +#endif  
> 
> Why does this look different from the already-installed patch for 
> __localtime64, which has the following before the #endif?
> 
> +#else
> +extern struct tm *__localtime64 (const __time64_t *__timer);
> +libc_hidden_proto (__localtime64)

Overlook, fixed in v2.

> > --- a/time/gmtime.c
> > +++ b/time/gmtime.c
> > @@ -25,13 +25,26 @@ __gmtime_r (const time_t *t, struct tm *tp)
> >   {
> >     return __tz_convert (*t, 0, tp);
> >   }
> > +
> >   libc_hidden_def (__gmtime_r)
> >   weak_alias (__gmtime_r, gmtime_r)  
> 
> No need for this whitespace change.

Ditto.

Thanks for your feedback!

Cordialement,
Albert ARIBAUD
3ADEV
  

Patch

diff --git a/include/time.h b/include/time.h
index 34368295a9..553bf74828 100644
--- a/include/time.h
+++ b/include/time.h
@@ -78,6 +78,10 @@  extern struct tm *__gmtime_r (const time_t *__restrict __timer,
 			      struct tm *__restrict __tp);
 libc_hidden_proto (__gmtime_r)
 
+#if __TIMESIZE == 64
+# define __gmtime64 gmtime
+#endif
+
 /* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
diff --git a/time/gmtime.c b/time/gmtime.c
index bda09bc021..67fdc89296 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -25,13 +25,26 @@  __gmtime_r (const time_t *t, struct tm *tp)
 {
   return __tz_convert (*t, 0, tp);
 }
+
 libc_hidden_def (__gmtime_r)
 weak_alias (__gmtime_r, gmtime_r)
 
+/* Return the `struct tm' representation of *T in UTC.  */
+struct tm *
+__gmtime64 (const __time64_t *t)
+{
+  return __tz_convert (*t, 0, &_tmbuf);
+}
+
+/* Provide a 32-bit variant if needed */
+
+#if __TIMESIZE != 64
 
-/* Return the `struct tm' representation of *T in UTC.	*/
 struct tm *
 gmtime (const time_t *t)
 {
-  return __tz_convert (*t, 0, &_tmbuf);
+  __time64_t t64 = *t;
+  return __gmtime64 (&t64, 0, &_tmbuf);
 }
+
+#endif