[RFC PATCH 51/52] Y2038: add RPC functions
Paul Eggert
eggert@cs.ucla.edu
Mon Sep 11 07:06:00 GMT 2017
Paul Eggert wrote:
>
> /* time_t is always 'long int' in the GNU C Library. */
> #define TIME_T_MIN LONG_MIN
> #define TIME_T_MAX LONG_MAX
>
> static inline bool
> fits_in_time_t (__time64_t t)
> {
> #if 7 <= __GNUC__
> return !__builtin_add_overflow_p (t, 0, TIME_T_MAX);
> #endif
> return TIME_T_MIN <= t && t <= TIME_T_MAX;
> }
Marc Glisse suggested a simpler solution:
static inline bool
fits_in_time_t (__time64_t t)
{
return t == (time64_t) t;
}
This is documented to work for GCC, something I had forgotten, and it generates
better code for pre-7 GCC. See:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82170#c2
More information about the Libc-alpha
mailing list