Changeset 903
- Timestamp:
- Dec 15, 2003, 6:53:40 AM (22 years ago)
- 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
to1.27
r902 r903 299 299 "__std_globfree" @335 300 300 "__gmt2loc" @336 301 "__ gmtime" @337301 "__std_gmtime_r" @337 302 302 "__hcalloc" @338 303 303 "__heap_walk" @339 … … 321 321 "__lmalloc" @357 322 322 "__loc2gmt" @358 323 "__ localtime" @359323 "__std_localtime_r" @359 324 324 "__lrealloc" @360 325 325 "__makepath" @361 … … 824 824 "_toascii" @860 825 825 "_tolower" @861 826 "__std_asctime_r" @862 827 "__std_ctime_r" @863 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/asctime.c
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r902 r903 14 14 { 15 15 struct _thread *tp = _thread(); 16 #define result (tp->_th_asctime_buf) 16 return asctime_r(t, tp->_th_asctime_buf); 17 } 17 18 19 char *_STD(asctime_r)(const struct tm *t, char *result) 20 { 18 21 memcpy (result+0, wdays+t->tm_wday*3, 3); 19 22 result[3] = ' '; … … 41 44 return result; 42 45 } 46 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/ctime.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.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 */ 3 3 #include "libc-alias.h" 4 4 #include <time.h> 5 5 #include <emx/time.h> 6 6 7 char *_STD(ctime) 7 char *_STD(ctime)(const time_t *t) 8 8 { 9 struct tm tmp, *x;9 struct tm tmp, *pTm; 10 10 11 x = _localtime (&tmp, t); 12 if (x == NULL) 11 pTm = localtime_r(t, &tmp); 12 if (pTm != NULL) 13 return asctime(pTm); 13 14 return NULL; 14 else15 return asctime (x);16 15 } 16 17 char *_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 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/gmtime.c
-
Property cvs2svn:cvs-rev
changed from
1.6
to1.7
r902 r903 7 7 #include <emx/time.h> 8 8 9 /* mkstd.awk: NOUNDERSCORE(gmtime) */ 10 struct tm *_gmtime (struct tm *dst, const time_t *t) 9 struct tm *_STD(gmtime_r)(const time_t *t, struct tm *dst) 11 10 { 12 time_t t0;13 _uldiv_t q;11 int days; 12 int rem; 14 13 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 } 16 23 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; 21 28 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; 24 32 25 /* Find an i such that _year_day[i] <= t0 < _year_day[i+1]. */ 33 { 34 int lo, hi, i; 26 35 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]. */ 42 37 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 } 46 53 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; 56 67 } 57 68 58 struct tm *_STD(gmtime) 69 struct tm *_STD(gmtime)(const time_t *t) 59 70 { 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); 62 73 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/gmtloc.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r902 r903 6 6 #include <emx/time.h> 7 7 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!!!) */ 10 10 #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)) ) 14 16 15 17 struct _dstswitch … … 19 21 }; 20 22 21 static struct _dstswitch _dstsw[2*_YEARS+2] = {{ 0,0}, {TIME_T_MAX, 0}};23 static struct _dstswitch _dstsw[2*_YEARS+2] = {{TIME_T_MIN, 0}, {TIME_T_MAX, 0}}; 22 24 static int _dstsw_count = 2; 23 25 … … 65 67 if (!_tzi.dst) 66 68 { 67 _dstsw[0].time = 0;69 _dstsw[0].time = TIME_T_MIN; 68 70 _dstsw[0].shift = 0; 69 71 _dstsw[1].time = TIME_T_MAX; … … 74 76 75 77 i = 0; 76 for (y = 0; _year_day[y] != USHRT_MAX; ++y)77 { 78 month_table = (_leap_year (y + 19 70)78 for (y = 2; _year_day[y] != SHRT_MAX; ++y) /* 1900, 1901, 1902 underflows second count. */ 79 { 80 month_table = (_leap_year (y + 1900) 79 81 ? _month_day_leap : _month_day_non_leap); 80 82 d_year = _year_day[y]; … … 87 89 t_start += t_year; 88 90 else 89 t_start = TIME_T_MAX;91 t_start = t_year >= 0 ? TIME_T_MAX : TIME_T_MIN; 90 92 91 93 d_end = switch_day (_tzi.em, _tzi.ew, _tzi.ed, ywday, month_table); … … 94 96 t_end += t_year; 95 97 else 96 t_end = TIME_T_MAX;98 t_end = t_year >= 0 ? TIME_T_MAX : TIME_T_MIN; 97 99 98 100 if (d_start < d_end || (d_start == d_end && _tzi.st <= _tzi.et)) … … 102 104 if (i == 0) 103 105 { 104 _dstsw[ i].time = 0;105 _dstsw[ i].shift = 0;106 _dstsw[0].time = TIME_T_MIN; 107 _dstsw[0].shift = 0; 106 108 ++i; 107 109 } … … 119 121 if (i == 0) 120 122 { 121 _dstsw[ i].time = 0;122 _dstsw[ i].shift = _tzi.shift;123 _dstsw[0].time = TIME_T_MIN; 124 _dstsw[0].shift = _tzi.shift; 123 125 ++i; 124 126 } … … 136 138 _dstsw_count = i; 137 139 138 assert (_dstsw_count == sizeof (_dstsw) / sizeof (_dstsw[0]) );140 assert (_dstsw_count == sizeof (_dstsw) / sizeof (_dstsw[0]) - 4); 139 141 } 140 142 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/localtim.c
-
Property cvs2svn:cvs-rev
changed from
1.6
to1.7
r902 r903 6 6 #include <emx/time.h> 7 7 8 struct tm *_STD(localtime) 8 struct tm *_STD(localtime)(const time_t *t) 9 9 { 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); 12 12 } 13 13 14 /* mkstd.awk: NOUNDERSCORE(localtime) */ 15 struct tm *_localtime (struct tm *dst, const time_t *t) 14 struct tm *_STD(localtime_r)(const time_t *t, struct tm *dst) 16 15 { 17 time_t lt;18 int isdst;19 struct tm *p;16 time_t lt; 17 int isdst; 18 struct tm *p; 20 19 21 if (!_tzset_flag) tzset();22 lt = *t;23 isdst = _gmt2loc(<);24 p = _gmtime (dst, <);25 p->tm_isdst = isdst;26 return p;20 if (!_tzset_flag) tzset(); 21 lt = *t; 22 isdst = _gmt2loc(<); 23 p = gmtime_r(<, dst); 24 p->tm_isdst = isdst; 25 return p; 27 26 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/mktime.c
-
Property cvs2svn:cvs-rev
changed from
1.6
to1.7
r902 r903 43 43 return (time_t)-1; 44 44 45 if ( _gmtime (&tmp, &t2) == NULL)45 if (gmtime_r (&t2, &tmp) == NULL) 46 46 return (time_t)-1; 47 47 *t = tmp; -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/strptime.c
-
Property cvs2svn:cvs-rev
changed from
1.5
to1.6
r902 r903 8 8 Parse a time specification in the input string pointed to by buffer 9 9 according to the format string pointed to by format, updating the 10 structure pointed to by t. 10 structure pointed to by t. 11 11 12 12 Whitespace (any number of spaces) in the format string matches whitespace … … 353 353 { 354 354 /* 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; 356 356 if (mask & MASK_WEEKM) 357 357 dow--; … … 378 378 else 379 379 { 380 int absday = _year_day [tm->tm_year - 70] + tm->tm_yday;380 int absday = _year_day [tm->tm_year] + tm->tm_yday; 381 381 /* 1st January 1970 was Thursday (4) */ 382 382 tm->tm_wday = ((4 + absday) % 7); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/time.smak
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r902 r903 1 libc.TSRC += $( wildcard src/lib/time/*.c)1 libc.TSRC += $(filter-out %_gen.c, $(wildcard src/lib/time/*.c)) -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/timetabs.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r902 r903 4 4 #include <emx/time.h> 5 5 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 */ 8 signed short const _year_day[_YEARS+1] = 10 9 { 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 26 27 }; 27 28 … … 30 31 December. */ 31 32 32 unsigned short const _month_day_non_leap[] = 33 unsigned short const _month_day_non_leap[] = 33 34 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, USHRT_MAX}; 34 35 35 unsigned short const _month_day_leap[] = 36 unsigned short const _month_day_leap[] = 36 37 {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, USHRT_MAX}; -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/time/tzset.c
-
Property cvs2svn:cvs-rev
changed from
1.6
to1.7
r902 r903 12 12 int _STD(daylight) = 0; 13 13 long _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};14 char *_STD(tzname)[2] = {"UCT", ""}; 15 16 struct _tzinfo _tzi = {"UCT", "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 17 17 18 18 … … 184 184 p = getenv ("TZ"); 185 185 if (p == NULL || *p == 0) 186 p = " GMT"; /* Our best approximation :-) */186 p = "UCT"; /* Our best approximation :-) */ 187 187 188 188 if (!copy_tzname (ntz.tzname, &p)) … … 227 227 return; 228 228 } 229 } 229 _STD(daylight) = 1; 230 } 231 else 232 _STD(daylight) = 0; 233 230 234 231 235 /* TODO: Make this thread-safe! */ … … 237 241 __ftime (&tb); 238 242 t_loc = tb.time; 239 _STD(daylight) = _loc2gmt (&tb.time, -1); 243 /* _STD(daylight) = _loc2gmt (&tb.time, -1); */ 240 244 _STD(timezone) = _tzi.tz; 241 245 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.