This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC PATCH 51/52] Y2038: add RPC functions


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]