Changeset 903


Ignore:
Timestamp:
Dec 15, 2003, 6:53:40 AM (22 years ago)
Author:
bird
Message:

#625: TZ fixing. Negative time offsets.

Location:
trunk/src/emx/src/lib
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.26 to 1.27
    r902 r903  
    299299    "__std_globfree" @335
    300300    "__gmt2loc" @336
    301     "__gmtime" @337
     301    "__std_gmtime_r" @337
    302302    "__hcalloc" @338
    303303    "__heap_walk" @339
     
    321321    "__lmalloc" @357
    322322    "__loc2gmt" @358
    323     "__localtime" @359
     323    "__std_localtime_r" @359
    324324    "__lrealloc" @360
    325325    "__makepath" @361
     
    824824    "_toascii" @860
    825825    "_tolower" @861
     826    "__std_asctime_r" @862
     827    "__std_ctime_r" @863
  • trunk/src/emx/src/lib/time/asctime.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r902 r903  
    1414{
    1515  struct _thread *tp = _thread();
    16 #define result (tp->_th_asctime_buf)
     16  return asctime_r(t, tp->_th_asctime_buf);
     17}
    1718
     19char *_STD(asctime_r)(const struct tm *t, char *result)
     20{
    1821  memcpy (result+0, wdays+t->tm_wday*3, 3);
    1922  result[3] = ' ';
     
    4144  return result;
    4245}
     46
  • trunk/src/emx/src/lib/time/ctime.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r902 r903  
    1 /* ctime.c (emx+gcc) -- Copyright (c) 1990-1999 by Eberhard Mattes */
    2 
     1/* ctime.c (emx+gcc) -- Copyright (c) 1990-1999 by Eberhard Mattes
     2                     -- Copyright (c) 2003 by Knut Stange Osmundsen */
    33#include "libc-alias.h"
    44#include <time.h>
    55#include <emx/time.h>
    66
    7 char *_STD(ctime) (const time_t *t)
     7char *_STD(ctime)(const time_t *t)
    88{
    9   struct tm tmp, *x;
     9    struct tm tmp, *pTm;
    1010
    11   x = _localtime (&tmp, t);
    12   if (x == NULL)
     11    pTm = localtime_r(t, &tmp);
     12    if (pTm != NULL)
     13        return asctime(pTm);
    1314    return NULL;
    14   else
    15     return asctime (x);
    1615}
     16
     17char *_STD(ctime_r)(const time_t * t, char *buf)
     18{
     19    struct tm tmp, *pTm;
     20    pTm = localtime_r(t, &tmp);
     21    if (pTm != NULL)
     22        return asctime_r(pTm, buf);
     23    return NULL;
     24}
  • trunk/src/emx/src/lib/time/gmtime.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r902 r903  
    77#include <emx/time.h>
    88
    9 /* mkstd.awk: NOUNDERSCORE(gmtime) */
    10 struct tm *_gmtime (struct tm *dst, const time_t *t)
     9struct tm *_STD(gmtime_r)(const time_t *t, struct tm *dst)
    1110{
    12   time_t t0;
    13   _uldiv_t q;
     11    int days;
     12    int rem;
    1413
    15   t0 = *t;
     14    /* calc days relative to Epoch. */
     15    rem = *t;
     16    days = rem / (60*60*24);
     17    rem %= (60*60*24);
     18    while (rem < 0)
     19    {
     20        rem += (60*60*24);
     21        --days;
     22    }
    1623
    17   q = _uldiv (t0, 60); dst->tm_sec = q.rem; t0 = q.quot;
    18   q = _uldiv (t0, 60); dst->tm_min = q.rem; t0 = q.quot;
    19   q = _uldiv (t0, 24); dst->tm_hour = q.rem; t0 = q.quot;
    20   dst->tm_wday = (t0+4) % 7;  /* 01-Jan-1970 was Thursday, ie, 4 */
     24    dst->tm_hour= rem / (60*60);
     25    rem %= (60*60);
     26    dst->tm_min = rem / 60;
     27    dst->tm_sec = rem % 60;
    2128
    22   {
    23     int lo, hi, i;
     29    dst->tm_wday = (days + 4) % 7;    /* 01-Jan-1970 was Thursday, i.e. 4 */
     30    if (dst->tm_wday < 0)
     31        dst->tm_wday += 7;
    2432
    25     /* Find an i such that _year_day[i] <= t0 < _year_day[i+1]. */
     33    {
     34        int lo, hi, i;
    2635
    27     lo = 0; hi = _YEARS - 1;
    28     for (;;)
    29       {
    30         i = (lo + hi) / 2;
    31         if (_year_day[i] > (int)t0)
    32           hi = i - 1;
    33         else if (_year_day[i+1] <= (int)t0)
    34           lo = i + 1;
    35         else
    36           break;
    37       }
    38     dst->tm_year = i + 70;
    39     t0 -= _year_day[i];
    40     dst->tm_yday = t0;
    41   }
     36        /* Find an i such that _year_day[i] <= days < _year_day[i+1]. */
    4237
    43   {
    44     int i;
    45     const unsigned short *p;
     38        lo = 0; hi = _YEARS - 1;
     39        for (;;)
     40        {
     41            i = (lo + hi) / 2;
     42            if (_year_day[i] > days)
     43                hi = i - 1;
     44            else if (_year_day[i+1] <= days)
     45                lo = i + 1;
     46            else
     47                break;
     48        }
     49        dst->tm_year = i;
     50        days -= _year_day[i];
     51        dst->tm_yday = days;
     52    }
    4653
    47     p = (_leap_year (dst->tm_year + 1900)
    48          ? _month_day_leap : _month_day_non_leap);
    49     for (i = 0; (int)t0 >= p[i+1]; ++i)
    50       ;
    51     dst->tm_mon = i;
    52     dst->tm_mday = t0 - p[i] + 1;
    53   }
    54   dst->tm_isdst = -1;
    55   return dst;
     54    {
     55        int i;
     56        const unsigned short *p;
     57
     58        p = (_leap_year (dst->tm_year + 1900)
     59             ? _month_day_leap : _month_day_non_leap);
     60        for (i = 0; (int)days >= p[i+1]; ++i)
     61            ;
     62        dst->tm_mon = i;
     63        dst->tm_mday = days - p[i] + 1;
     64    }
     65    dst->tm_isdst = -1;
     66    return dst;
    5667}
    5768
    58 struct tm *_STD(gmtime) (const time_t *t)
     69struct tm *_STD(gmtime)(const time_t *t)
    5970{
    60   struct _thread *tp = _thread ();
    61   return _gmtime (&tp->_th_gmtime_buf, t);
     71    struct _thread *tp = _thread ();
     72    return gmtime_r (t, &tp->_th_gmtime_buf);
    6273}
  • trunk/src/emx/src/lib/time/gmtloc.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r902 r903  
    66#include <emx/time.h>
    77
    8 /* Return true iff adding A to T does not overflow time_t. */
    9 
     8/* Return true iff adding A to T does not overflow or underflow time_t.
     9   (Correct but not fast!!!) */
    1010#define ADD_OK(t,a) \
    11     ((a) < 0 ? (t) >= (time_t)(-(a)) \
    12    : (a) > 0 ? (t) <= TIME_T_MAX - (a) \
    13    : 1)
     11    ( (t) == 0 || (a) == 0 \
     12     || ((a) > 0 && (t) > 0 && (a) + (t) > (a)) \
     13     || ((a) > 0 && (t) < 0 && (a) + (t) < (a)) \
     14     || ((a) < 0 && (t) < 0 && (a) + (t) < (a)) \
     15     || ((a) < 0 && (t) > 0 && (a) + (t) > (a)) )
    1416
    1517struct _dstswitch
     
    1921};
    2022
    21 static struct _dstswitch _dstsw[2*_YEARS+2] = {{0,0}, {TIME_T_MAX, 0}};
     23static struct _dstswitch _dstsw[2*_YEARS+2] = {{TIME_T_MIN, 0}, {TIME_T_MAX, 0}};
    2224static int _dstsw_count = 2;
    2325
     
    6567  if (!_tzi.dst)
    6668    {
    67       _dstsw[0].time = 0;
     69      _dstsw[0].time = TIME_T_MIN;
    6870      _dstsw[0].shift = 0;
    6971      _dstsw[1].time = TIME_T_MAX;
     
    7476
    7577  i = 0;
    76   for (y = 0; _year_day[y] != USHRT_MAX; ++y)
    77     {
    78       month_table = (_leap_year (y + 1970)
     78  for (y = 2; _year_day[y] != SHRT_MAX; ++y) /* 1900, 1901, 1902 underflows second count. */
     79    {
     80      month_table = (_leap_year (y + 1900)
    7981                     ? _month_day_leap : _month_day_non_leap);
    8082      d_year = _year_day[y];
     
    8789        t_start += t_year;
    8890      else
    89         t_start = TIME_T_MAX;
     91        t_start = t_year >= 0 ? TIME_T_MAX : TIME_T_MIN;
    9092
    9193      d_end = switch_day (_tzi.em, _tzi.ew, _tzi.ed, ywday, month_table);
     
    9496        t_end += t_year;
    9597      else
    96         t_end = TIME_T_MAX;
     98        t_end = t_year >= 0 ? TIME_T_MAX : TIME_T_MIN;
    9799
    98100      if (d_start < d_end || (d_start == d_end && _tzi.st <= _tzi.et))
     
    102104          if (i == 0)
    103105            {
    104               _dstsw[i].time = 0;
    105               _dstsw[i].shift = 0;
     106              _dstsw[0].time = TIME_T_MIN;
     107              _dstsw[0].shift = 0;
    106108              ++i;
    107109            }
     
    119121          if (i == 0)
    120122            {
    121               _dstsw[i].time = 0;
    122               _dstsw[i].shift = _tzi.shift;
     123              _dstsw[0].time = TIME_T_MIN;
     124              _dstsw[0].shift = _tzi.shift;
    123125              ++i;
    124126            }
     
    136138  _dstsw_count = i;
    137139
    138   assert (_dstsw_count == sizeof (_dstsw) / sizeof (_dstsw[0]));
     140  assert (_dstsw_count == sizeof (_dstsw) / sizeof (_dstsw[0]) - 4);
    139141}
    140142
  • trunk/src/emx/src/lib/time/localtim.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r902 r903  
    66#include <emx/time.h>
    77
    8 struct tm *_STD(localtime) (const time_t *t)
     8struct tm *_STD(localtime)(const time_t *t)
    99{
    10   struct _thread *tp = _thread ();
    11   return _localtime (&tp->_th_gmtime_buf, t);
     10    struct _thread *tp = _thread();
     11    return localtime_r(t, &tp->_th_gmtime_buf);
    1212}
    1313
    14 /* mkstd.awk: NOUNDERSCORE(localtime) */
    15 struct tm *_localtime (struct tm *dst, const time_t *t)
     14struct tm *_STD(localtime_r)(const time_t *t, struct tm *dst)
    1615{
    17   time_t lt;
    18   int isdst;
    19   struct tm *p;
     16    time_t lt;
     17    int isdst;
     18    struct tm *p;
    2019
    21   if (!_tzset_flag) tzset ();
    22   lt = *t;
    23   isdst = _gmt2loc (&lt);
    24   p = _gmtime (dst, &lt);
    25   p->tm_isdst = isdst;
    26   return p;
     20    if (!_tzset_flag) tzset();
     21    lt = *t;
     22    isdst = _gmt2loc(&lt);
     23    p = gmtime_r(&lt, dst);
     24    p->tm_isdst = isdst;
     25    return p;
    2726}
  • trunk/src/emx/src/lib/time/mktime.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r902 r903  
    4343    return (time_t)-1;
    4444
    45   if (_gmtime (&tmp, &t2) == NULL)
     45  if (gmtime_r (&t2, &tmp) == NULL)
    4646    return (time_t)-1;
    4747  *t = tmp;
  • trunk/src/emx/src/lib/time/strptime.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r902 r903  
    88    Parse a time specification in the input string pointed to by buffer
    99    according to the format string pointed to by format, updating the
    10     structure pointed to by t. 
     10    structure pointed to by t.
    1111
    1212    Whitespace (any number of spaces) in the format string matches whitespace
     
    353353    {
    354354      /* Compute day of the year given week number and weekday */
    355       int dow = (4 + _year_day [tm->tm_year - 70]) % 7;
     355      int dow = (4 + _year_day [tm->tm_year]) % 7;
    356356      if (mask & MASK_WEEKM)
    357357        dow--;
     
    378378    else
    379379    {
    380       int absday = _year_day [tm->tm_year - 70] + tm->tm_yday;
     380      int absday = _year_day [tm->tm_year] + tm->tm_yday;
    381381      /* 1st January 1970 was Thursday (4) */
    382382      tm->tm_wday = ((4 + absday) % 7);
  • trunk/src/emx/src/lib/time/time.smak

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r902 r903  
    1 libc.TSRC += $(wildcard src/lib/time/*.c)
     1libc.TSRC += $(filter-out %_gen.c, $(wildcard src/lib/time/*.c))
  • trunk/src/emx/src/lib/time/timetabs.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r902 r903  
    44#include <emx/time.h>
    55
    6 /* Day number, relative to 01-Jan-1970, of 01-Jan for the years 1970
    7    through 2106 */
    8 
    9 unsigned short const _year_day[_YEARS+1] =
     6/* Day number, relative to 01-Jan-1970, of 01-Jan for the years 1900
     7   through 2059 */
     8signed short const _year_day[_YEARS+1] =
    109{
    11   0, 365, 730, 1096, 1461, 1826, 2191, 2557, 2922, 3287, 3652, 4018,
    12   4383, 4748, 5113, 5479, 5844, 6209, 6574, 6940, 7305, 7670, 8035,
    13   8401, 8766, 9131, 9496, 9862, 10227, 10592, 10957, 11323, 11688,
    14   12053, 12418, 12784, 13149, 13514, 13879, 14245, 14610, 14975,
    15   15340, 15706, 16071, 16436, 16801, 17167, 17532, 17897, 18262,
    16   18628, 18993, 19358, 19723, 20089, 20454, 20819, 21184, 21550,
    17   21915, 22280, 22645, 23011, 23376, 23741, 24106, 24472, 24837,
    18   25202, 25567, 25933, 26298, 26663, 27028, 27394, 27759, 28124,
    19   28489, 28855, 29220, 29585, 29950, 30316, 30681, 31046, 31411,
    20   31777, 32142, 32507, 32872, 33238, 33603, 33968, 34333, 34699,
    21   35064, 35429, 35794, 36160, 36525, 36890, 37255, 37621, 37986,
    22   38351, 38716, 39082, 39447, 39812, 40177, 40543, 40908, 41273,
    23   41638, 42004, 42369, 42734, 43099, 43465, 43830, 44195, 44560,
    24   44926, 45291, 45656, 46021, 46387, 46752, 47117, 47482, 47847,
    25   48212, 48577, 48942, 49308, 49673, USHRT_MAX
     10   -25567,-25202,-24837,-24472,-24107,-23741,-23376,-23011,-22646,-22280,  /* 1900 - 1909 */
     11   -21915,-21550,-21185,-20819,-20454,-20089,-19724,-19358,-18993,-18628,  /* 1910 - 1919 */
     12   -18263,-17897,-17532,-17167,-16802,-16436,-16071,-15706,-15341,-14975,  /* 1920 - 1929 */
     13   -14610,-14245,-13880,-13514,-13149,-12784,-12419,-12053,-11688,-11323,  /* 1930 - 1939 */
     14   -10958,-10592,-10227, -9862, -9497, -9131, -8766, -8401, -8036, -7670,  /* 1940 - 1949 */
     15    -7305, -6940, -6575, -6209, -5844, -5479, -5114, -4748, -4383, -4018,  /* 1950 - 1959 */
     16    -3653, -3287, -2922, -2557, -2192, -1826, -1461, -1096,  -731,  -365,  /* 1960 - 1969 */
     17        0,   365,   730,  1096,  1461,  1826,  2191,  2557,  2922,  3287,  /* 1970 - 1979 */
     18     3652,  4018,  4383,  4748,  5113,  5479,  5844,  6209,  6574,  6940,  /* 1980 - 1989 */
     19     7305,  7670,  8035,  8401,  8766,  9131,  9496,  9862, 10227, 10592,  /* 1990 - 1999 */
     20    10957, 11323, 11688, 12053, 12418, 12784, 13149, 13514, 13879, 14245,  /* 2000 - 2009 */
     21    14610, 14975, 15340, 15706, 16071, 16436, 16801, 17167, 17532, 17897,  /* 2010 - 2019 */
     22    18262, 18628, 18993, 19358, 19723, 20089, 20454, 20819, 21184, 21550,  /* 2020 - 2029 */
     23    21915, 22280, 22645, 23011, 23376, 23741, 24106, 24472, 24837, 25202,  /* 2030 - 2039 */
     24    25567, 25933, 26298, 26663, 27028, 27394, 27759, 28124, 28489, 28855,  /* 2040 - 2049 */
     25    29220, 29585, 29950, 30316, 30681, 31046, 31411, 31777, 32142, 32507,  /* 2050 - 2059 */
     26    SHRT_MAX
    2627};
    2728
     
    3031   December. */
    3132
    32 unsigned short const _month_day_non_leap[] = 
     33unsigned short const _month_day_non_leap[] =
    3334  {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, USHRT_MAX};
    3435
    35 unsigned short const _month_day_leap[] = 
     36unsigned short const _month_day_leap[] =
    3637  {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, USHRT_MAX};
  • trunk/src/emx/src/lib/time/tzset.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r902 r903  
    1212int _STD(daylight) = 0;
    1313long _STD(timezone) = 0;
    14 char *_STD(tzname)[2] = {"GMT", ""};
    15 
    16 struct _tzinfo _tzi = {"GMT", "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
     14char *_STD(tzname)[2] = {"UCT", ""};
     15
     16struct _tzinfo _tzi = {"UCT", "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    1717
    1818
     
    184184  p = getenv ("TZ");
    185185  if (p == NULL || *p == 0)
    186     p = "GMT";                  /* Our best approximation :-) */
     186    p = "UCT";                  /* Our best approximation :-) */
    187187
    188188  if (!copy_tzname (ntz.tzname, &p))
     
    227227          return;
    228228        }
    229     }
     229      _STD(daylight) = 1;
     230    }
     231  else
     232    _STD(daylight) = 0;
     233
    230234
    231235  /* TODO: Make this thread-safe! */
     
    237241  __ftime (&tb);
    238242  t_loc = tb.time;
    239   _STD(daylight) = _loc2gmt (&tb.time, -1);
     243/*  _STD(daylight) = _loc2gmt (&tb.time, -1); */
    240244  _STD(timezone) = _tzi.tz;
    241245
Note: See TracChangeset for help on using the changeset viewer.