[PATCH] Change time_t to 64-bit by default

Sebastian Huber sebastian.huber@embedded-brains.de
Thu Sep 7 13:10:00 GMT 2017


On 07/09/17 14:34, Corinna Vinschen wrote:

> On Sep  7 09:20, Sebastian Huber wrote:
>> In order to avoid the year 2038 problem, define time_t to a signed
>> integer with at least 64-bits.  The type for time_t can be forced to
>> long with the --enable-newlib-long-time_t configure option or with the
>> _USE_LONG_TIME_T system configuration define.
>>
>> Signed-off-by: Sebastian Huber<sebastian.huber@embedded-brains.de>
>> ---
>>   newlib/README                         |  6 ++++++
>>   newlib/configure                      | 26 ++++++++++++++++++++++++--
>>   newlib/configure.in                   | 15 +++++++++++++++
>>   newlib/libc/include/sys/_types.h      |  6 +++++-
>>   newlib/libc/include/sys/config.h      |  6 ++++++
>>   newlib/newlib.hin                     |  3 +++
>>   winsup/cygwin/include/cygwin/config.h |  1 +
>>   7 files changed, 60 insertions(+), 3 deletions(-)
> Your patch is fine, but aren't we missing a preliminary patch to the
> time functions as discussed in
> https://sourceware.org/ml/newlib/2017/msg00772.html  first?

If I compare

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libc/time/gmtime_r.c;h=81c7c94b1f9fe54f83c677e15c2ef6cc81509445;hb=HEAD

with

https://svnweb.freebsd.org/base/head/contrib/tzcode/stdtime/localtime.c?view=markup

or

https://android.googlesource.com/platform/bionic/+/master/libc/tzcode/localtime.c

I wonder if the Newlib version is correct in general. At least support 
for leap seconds seems to be missing.

The casts in Newlib gmtime_r() look pretty useless. I will send a patch 
with:

diff --git a/newlib/libc/time/gmtime_r.c b/newlib/libc/time/gmtime_r.c
index 81c7c94b1..6475df3ba 100644
--- a/newlib/libc/time/gmtime_r.c
+++ b/newlib/libc/time/gmtime_r.c
@@ -56,8 +56,8 @@ _DEFUN (gmtime_r, (tim_p, res),
    unsigned erayear, yearday, month, day;
    unsigned long eraday;

-  days = ((long)lcltime) / SECSPERDAY + EPOCH_ADJUSTMENT_DAYS;
-  rem = ((long)lcltime) % SECSPERDAY;
+  days = lcltime / SECSPERDAY + EPOCH_ADJUSTMENT_DAYS;
+  rem = lcltime % SECSPERDAY;
    if (rem < 0)
      {
        rem += SECSPERDAY;

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the Newlib mailing list