1#ifndef lint 2#ifndef NOID |
3static char elsieid[] = "@(#)localtime.c 7.44"; |
4#endif /* !defined NOID */ 5#endif /* !defined lint */ 6 7/* 8** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). 9** POSIX-style TZ environment variable handling from Guy Harris 10** (guy@auspex.com). 11*/ 12 13/*LINTLIBRARY*/ 14 15#include "private.h" 16#include "tzfile.h" 17#include "fcntl.h" 18 |
19/* 20** SunOS 4.1.1 headers lack O_BINARY. 21*/ |
22 23#ifdef O_BINARY 24#define OPEN_MODE (O_RDONLY | O_BINARY) 25#endif /* defined O_BINARY */ 26#ifndef O_BINARY 27#define OPEN_MODE O_RDONLY 28#endif /* !defined O_BINARY */ 29 30#ifndef WILDABBR 31/* 32** Someone might make incorrect use of a time zone abbreviation: 33** 1. They might reference tzname[0] before calling tzset (explicitly |
34** or implicitly). |
35** 2. They might reference tzname[1] before calling tzset (explicitly |
36** or implicitly). |
37** 3. They might reference tzname[1] after setting to a time zone 38** in which Daylight Saving Time is never observed. 39** 4. They might reference tzname[0] after setting to a time zone 40** in which Standard Time is never observed. 41** 5. They might reference tm.TM_ZONE after calling offtime. 42** What's best to do in the above cases is open to debate; 43** for now, we just set things up so that in any of the five cases 44** WILDABBR is used. Another possibility: initialize tzname[0] to the 45** string "tzname[0] used before set", and similarly for the other cases. 46** And another: initialize tzname[0] to "ERA", with an explanation in the 47** manual page of what this "time zone abbreviation" means (doing this so 48** that tzname[0] has the "normal" length of three characters). 49*/ 50#define WILDABBR " " 51#endif /* !defined WILDABBR */ 52 |
53static char wildabbr[] = "WILDABBR"; |
54 |
55static const char gmt[] = "GMT"; 56 |
57struct ttinfo { /* time type information */ 58 long tt_gmtoff; /* GMT offset in seconds */ 59 int tt_isdst; /* used to set tm_isdst */ 60 int tt_abbrind; /* abbreviation list index */ 61 int tt_ttisstd; /* TRUE if transition is std time */ |
62 int tt_ttisgmt; /* TRUE if transition is GMT */ |
63}; 64 65struct lsinfo { /* leap second information */ 66 time_t ls_trans; /* transition time */ 67 long ls_corr; /* correction to apply */ 68}; 69 70#define BIGGEST(a, b) (((a) > (b)) ? (a) : (b)) --- 8 unchanged lines hidden (view full) --- 79struct state { 80 int leapcnt; 81 int timecnt; 82 int typecnt; 83 int charcnt; 84 time_t ats[TZ_MAX_TIMES]; 85 unsigned char types[TZ_MAX_TIMES]; 86 struct ttinfo ttis[TZ_MAX_TYPES]; |
87 char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt), |
88 (2 * (MY_TZNAME_MAX + 1)))]; 89 struct lsinfo lsis[TZ_MAX_LEAPS]; 90}; 91 92struct rule { 93 int r_type; /* type of rule--see below */ 94 int r_day; /* day number of rule */ 95 int r_week; /* week number of rule */ --- 20 unchanged lines hidden (view full) --- 116static void gmtsub P((const time_t * timep, long offset, 117 struct tm * tmp)); 118static void localsub P((const time_t * timep, long offset, 119 struct tm * tmp)); 120static int increment_overflow P((int * number, int delta)); 121static int normalize_overflow P((int * tensptr, int * unitsptr, 122 int base)); 123static void settzname P((void)); |
124static time_t time1 P((struct tm * tmp, 125 void(*funcp) P((const time_t *, 126 long, struct tm *)), |
127 long offset)); |
128static time_t time2 P((struct tm *tmp, 129 void(*funcp) P((const time_t *, 130 long, struct tm*)), |
131 long offset, int * okayp)); 132static void timesub P((const time_t * timep, long offset, 133 const struct state * sp, struct tm * tmp)); 134static int tmcomp P((const struct tm * atmp, 135 const struct tm * btmp)); 136static time_t transtime P((time_t janfirst, int year, 137 const struct rule * rulep, long offset)); 138static int tzload P((const char * name, struct state * sp)); --- 7 unchanged lines hidden (view full) --- 146 147#ifndef ALL_STATE 148static struct state lclmem; 149static struct state gmtmem; 150#define lclptr (&lclmem) 151#define gmtptr (&gmtmem) 152#endif /* State Farm */ 153 |
154#ifndef TZ_STRLEN_MAX 155#define TZ_STRLEN_MAX 255 156#endif /* !defined TZ_STRLEN_MAX */ 157 158static char lcl_TZname[TZ_STRLEN_MAX + 1]; |
159static int lcl_is_set; 160static int gmt_is_set; 161 162char * tzname[2] = { |
163 wildabbr, 164 wildabbr |
165}; 166 |
167/* 168** Section 4.12.3 of X3.159-1989 requires that 169** Except for the strftime function, these functions [asctime, 170** ctime, gmtime, localtime] return values in one of two static 171** objects: a broken-down time structure and an array of char. 172** Thanks to Paul Eggert (eggert@twinsun.com) for noting this. 173*/ 174 175static struct tm tm; 176 |
177#ifdef USG_COMPAT 178time_t timezone = 0; 179int daylight = 0; 180#endif /* defined USG_COMPAT */ 181 182#ifdef ALTZONE 183time_t altzone = 0; 184#endif /* defined ALTZONE */ 185 186static long 187detzcode(codep) 188const char * const codep; 189{ 190 register long result; 191 register int i; 192 |
193 result = (codep[0] & 0x80) ? ~0L : 0L; |
194 for (i = 0; i < 4; ++i) 195 result = (result << 8) | (codep[i] & 0xff); 196 return result; 197} 198 199static void |
200settzname P((void)) |
201{ |
202 register struct state * const sp = lclptr; |
203 register int i; 204 |
205 tzname[0] = wildabbr; 206 tzname[1] = wildabbr; |
207#ifdef USG_COMPAT 208 daylight = 0; 209 timezone = 0; 210#endif /* defined USG_COMPAT */ 211#ifdef ALTZONE 212 altzone = 0; 213#endif /* defined ALTZONE */ 214#ifdef ALL_STATE 215 if (sp == NULL) { |
216 tzname[0] = tzname[1] = gmt; |
217 return; 218 } 219#endif /* defined ALL_STATE */ 220 for (i = 0; i < sp->typecnt; ++i) { 221 register const struct ttinfo * const ttisp = &sp->ttis[i]; 222 223 tzname[ttisp->tt_isdst] = |
224 &sp->chars[ttisp->tt_abbrind]; |
225#ifdef USG_COMPAT 226 if (ttisp->tt_isdst) 227 daylight = 1; 228 if (i == 0 || !ttisp->tt_isdst) 229 timezone = -(ttisp->tt_gmtoff); 230#endif /* defined USG_COMPAT */ 231#ifdef ALTZONE 232 if (i == 0 || ttisp->tt_isdst) --- 4 unchanged lines hidden (view full) --- 237 ** And to get the latest zone names into tzname. . . 238 */ 239 for (i = 0; i < sp->timecnt; ++i) { 240 register const struct ttinfo * const ttisp = 241 &sp->ttis[ 242 sp->types[i]]; 243 244 tzname[ttisp->tt_isdst] = |
245 &sp->chars[ttisp->tt_abbrind]; |
246 } 247} 248 249static int 250tzload(name, sp) 251register const char * name; 252register struct state * const sp; 253{ 254 register const char * p; 255 register int i; 256 register int fid; 257 258 if (name == NULL && (name = TZDEFAULT) == NULL) 259 return -1; 260 { |
261 register int doaccess; 262 /* 263 ** Section 4.9.1 of the C standard says that 264 ** "FILENAME_MAX expands to an integral constant expression 265 ** that is the sie needed for an array of char large enough 266 ** to hold the longest file name string that the implementation 267 ** guarantees can be opened." 268 */ |
269 char fullname[FILENAME_MAX + 1]; 270 271 if (name[0] == ':') 272 ++name; 273 doaccess = name[0] == '/'; 274 if (!doaccess) { 275 if ((p = TZDIR) == NULL) 276 return -1; --- 4 unchanged lines hidden (view full) --- 281 (void) strcat(fullname, name); 282 /* 283 ** Set doaccess if '.' (as in "../") shows up in name. 284 */ 285 if (strchr(name, '.') != NULL) 286 doaccess = TRUE; 287 name = fullname; 288 } |
289 if (doaccess && access(name, R_OK) != 0) |
290 return -1; 291 if ((fid = open(name, OPEN_MODE)) == -1) 292 return -1; 293 } 294 { |
295 struct tzhead * tzhp; 296 char buf[sizeof *sp + sizeof *tzhp]; 297 int ttisstdcnt; 298 int ttisgmtcnt; |
299 300 i = read(fid, buf, sizeof buf); |
301 if (close(fid) != 0) |
302 return -1; |
303 p = buf; 304 p += sizeof tzhp->tzh_reserved; 305 ttisstdcnt = (int) detzcode(p); 306 p += 4; 307 ttisgmtcnt = (int) detzcode(p); 308 p += 4; 309 sp->leapcnt = (int) detzcode(p); 310 p += 4; 311 sp->timecnt = (int) detzcode(p); 312 p += 4; 313 sp->typecnt = (int) detzcode(p); 314 p += 4; 315 sp->charcnt = (int) detzcode(p); 316 p += 4; |
317 if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS || 318 sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES || 319 sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES || 320 sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS || |
321 (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) || 322 (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0)) |
323 return -1; |
324 if (i - (p - buf) < sp->timecnt * 4 + /* ats */ 325 sp->timecnt + /* types */ 326 sp->typecnt * (4 + 2) + /* ttinfos */ 327 sp->charcnt + /* chars */ 328 sp->leapcnt * (4 + 4) + /* lsinfos */ 329 ttisstdcnt + /* ttisstds */ 330 ttisgmtcnt) /* ttisgmts */ |
331 return -1; |
332 for (i = 0; i < sp->timecnt; ++i) { 333 sp->ats[i] = detzcode(p); 334 p += 4; 335 } 336 for (i = 0; i < sp->timecnt; ++i) { 337 sp->types[i] = (unsigned char) *p++; 338 if (sp->types[i] >= sp->typecnt) 339 return -1; --- 32 unchanged lines hidden (view full) --- 372 ttisp->tt_ttisstd = FALSE; 373 else { 374 ttisp->tt_ttisstd = *p++; 375 if (ttisp->tt_ttisstd != TRUE && 376 ttisp->tt_ttisstd != FALSE) 377 return -1; 378 } 379 } |
380 for (i = 0; i < sp->typecnt; ++i) { 381 register struct ttinfo * ttisp; 382 383 ttisp = &sp->ttis[i]; 384 if (ttisgmtcnt == 0) 385 ttisp->tt_ttisgmt = FALSE; 386 else { 387 ttisp->tt_ttisgmt = *p++; 388 if (ttisp->tt_ttisgmt != TRUE && 389 ttisp->tt_ttisgmt != FALSE) 390 return -1; 391 } 392 } |
393 } 394 return 0; 395} 396 397static const int mon_lengths[2][MONSPERYEAR] = { 398 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, 399 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } 400}; --- 62 unchanged lines hidden (view full) --- 463 464static const char * 465getsecs(strp, secsp) 466register const char * strp; 467long * const secsp; 468{ 469 int num; 470 |
471 /* 472 ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like 473 ** "M10.4.6/26", which does not conform to Posix, 474 ** but which specifies the equivalent of 475 ** ``02:00 on the first Sunday on or after 23 Oct''. 476 */ 477 strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1); |
478 if (strp == NULL) 479 return NULL; |
480 *secsp = num * (long) SECSPERHOUR; |
481 if (*strp == ':') { 482 ++strp; 483 strp = getnum(strp, &num, 0, MINSPERHOUR - 1); 484 if (strp == NULL) 485 return NULL; 486 *secsp += num * SECSPERMIN; 487 if (*strp == ':') { 488 ++strp; |
489 /* `SECSPERMIN' allows for leap seconds. */ 490 strp = getnum(strp, &num, 0, SECSPERMIN); |
491 if (strp == NULL) 492 return NULL; 493 *secsp += num; 494 } 495 } 496 return strp; 497} 498 --- 93 unchanged lines hidden (view full) --- 592register const struct rule * const rulep; 593const long offset; 594{ 595 register int leapyear; 596 register time_t value; 597 register int i; 598 int d, m1, yy0, yy1, yy2, dow; 599 |
600 INITIALIZE(value); |
601 leapyear = isleap(year); 602 switch (rulep->r_type) { 603 604 case JULIAN_DAY: 605 /* 606 ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap 607 ** years. 608 ** In non-leap years, or if the day number is 59 or less, just --- 74 unchanged lines hidden (view full) --- 683static int 684tzparse(name, sp, lastditch) 685const char * name; 686register struct state * const sp; 687const int lastditch; 688{ 689 const char * stdname; 690 const char * dstname; |
691 size_t stdlen; 692 size_t dstlen; |
693 long stdoffset; 694 long dstoffset; 695 register time_t * atp; 696 register unsigned char * typep; 697 register char * cp; 698 register int load_result; 699 |
700 INITIALIZE(dstname); |
701 stdname = name; 702 if (lastditch) { 703 stdlen = strlen(name); /* length of standard zone name */ 704 name += stdlen; 705 if (stdlen >= sizeof sp->chars) 706 stdlen = (sizeof sp->chars) - 1; 707 } else { 708 name = getzname(name); --- 70 unchanged lines hidden (view full) --- 779 *typep++ = 0; /* DST begins */ 780 *atp++ = endtime; 781 *typep++ = 1; /* DST ends */ 782 } 783 janfirst += year_lengths[isleap(year)] * 784 SECSPERDAY; 785 } 786 } else { |
787 register long theirstdoffset; 788 register long theirdstoffset; 789 register long theiroffset; 790 register int isdst; |
791 register int i; |
792 register int j; |
793 794 if (*name != '\0') 795 return -1; 796 if (load_result != 0) 797 return -1; 798 /* |
799 ** Initial values of theirstdoffset and theirdstoffset. |
800 */ |
801 theirstdoffset = 0; 802 for (i = 0; i < sp->timecnt; ++i) { 803 j = sp->types[i]; 804 if (!sp->ttis[j].tt_isdst) { 805 theirstdoffset = -sp->ttis[j].tt_gmtoff; 806 break; |
807 } 808 } |
809 theirdstoffset = 0; 810 for (i = 0; i < sp->timecnt; ++i) { 811 j = sp->types[i]; 812 if (sp->ttis[j].tt_isdst) { 813 theirdstoffset = -sp->ttis[j].tt_gmtoff; 814 break; 815 } 816 } |
817 /* |
818 ** Initially we're assumed to be in standard time. |
819 */ |
820 isdst = FALSE; 821 theiroffset = theirstdoffset; |
822 /* |
823 ** Now juggle transition times and types 824 ** tracking offsets as you do. |
825 */ |
826 for (i = 0; i < sp->timecnt; ++i) { |
827 j = sp->types[i]; 828 sp->types[i] = sp->ttis[j].tt_isdst; 829 if (sp->ttis[j].tt_ttisgmt) { 830 /* No adjustment to transition time */ 831 } else { 832 /* 833 ** If summer time is in effect, and the 834 ** transition time was not specified as 835 ** standard time, add the summer time 836 ** offset to the transition time; 837 ** otherwise, add the standard time 838 ** offset to the transition time. 839 */ 840 /* 841 ** Transitions from DST to DDST 842 ** will effectively disappear since 843 ** POSIX provides for only one DST 844 ** offset. 845 */ 846 if (isdst && !sp->ttis[j].tt_ttisstd) { 847 sp->ats[i] += dstoffset - 848 theirdstoffset; 849 } else { 850 sp->ats[i] += stdoffset - 851 theirstdoffset; 852 } 853 } 854 theiroffset = -sp->ttis[j].tt_gmtoff; 855 if (sp->ttis[j].tt_isdst) 856 theirdstoffset = theiroffset; 857 else theirstdoffset = theiroffset; |
858 } |
859 /* 860 ** Finally, fill in ttis. 861 ** ttisstd and ttisgmt need not be handled. 862 */ 863 sp->ttis[0].tt_gmtoff = -stdoffset; 864 sp->ttis[0].tt_isdst = FALSE; 865 sp->ttis[0].tt_abbrind = 0; 866 sp->ttis[1].tt_gmtoff = -dstoffset; 867 sp->ttis[1].tt_isdst = TRUE; 868 sp->ttis[1].tt_abbrind = stdlen + 1; |
869 } 870 } else { 871 dstlen = 0; 872 sp->typecnt = 1; /* only standard time */ 873 sp->timecnt = 0; 874 sp->ttis[0].tt_gmtoff = -stdoffset; 875 sp->ttis[0].tt_isdst = 0; 876 sp->ttis[0].tt_abbrind = 0; --- 13 unchanged lines hidden (view full) --- 890 } 891 return 0; 892} 893 894static void 895gmtload(sp) 896struct state * const sp; 897{ |
898 if (tzload(gmt, sp) != 0) 899 (void) tzparse(gmt, sp, TRUE); |
900} 901 902#ifndef STD_INSPIRED |
903/* 904** A non-static declaration of tzsetwall in a system header file 905** may cause a warning about this upcoming static declaration... 906*/ |
907static 908#endif /* !defined STD_INSPIRED */ 909void |
910tzsetwall P((void)) |
911{ |
912 if (lcl_is_set < 0) 913 return; 914 lcl_is_set = -1; 915 |
916#ifdef ALL_STATE 917 if (lclptr == NULL) { 918 lclptr = (struct state *) malloc(sizeof *lclptr); 919 if (lclptr == NULL) { 920 settzname(); /* all we can do */ 921 return; 922 } 923 } 924#endif /* defined ALL_STATE */ 925 if (tzload((char *) NULL, lclptr) != 0) 926 gmtload(lclptr); 927 settzname(); 928} 929 930void |
931tzset P((void)) |
932{ 933 register const char * name; 934 935 name = getenv("TZ"); 936 if (name == NULL) { 937 tzsetwall(); 938 return; 939 } |
940 941 if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0) 942 return; 943 lcl_is_set = (strlen(name) < sizeof(lcl_TZname)); 944 if (lcl_is_set) 945 (void) strcpy(lcl_TZname, name); 946 |
947#ifdef ALL_STATE 948 if (lclptr == NULL) { 949 lclptr = (struct state *) malloc(sizeof *lclptr); 950 if (lclptr == NULL) { 951 settzname(); /* all we can do */ 952 return; 953 } 954 } 955#endif /* defined ALL_STATE */ 956 if (*name == '\0') { 957 /* 958 ** User wants it fast rather than right. 959 */ 960 lclptr->leapcnt = 0; /* so, we're off a little */ 961 lclptr->timecnt = 0; 962 lclptr->ttis[0].tt_gmtoff = 0; 963 lclptr->ttis[0].tt_abbrind = 0; |
964 (void) strcpy(lclptr->chars, gmt); |
965 } else if (tzload(name, lclptr) != 0) 966 if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) 967 (void) gmtload(lclptr); 968 settzname(); 969} 970 971/* 972** The easy way to behave "as if no library function calls" localtime --- 6 unchanged lines hidden (view full) --- 979 980/*ARGSUSED*/ 981static void 982localsub(timep, offset, tmp) 983const time_t * const timep; 984const long offset; 985struct tm * const tmp; 986{ |
987 register struct state * sp; |
988 register const struct ttinfo * ttisp; 989 register int i; 990 const time_t t = *timep; 991 |
992 sp = lclptr; 993#ifdef ALL_STATE 994 if (sp == NULL) { 995 gmtsub(timep, offset, tmp); 996 return; 997 } 998#endif /* defined ALL_STATE */ 999 if (sp->timecnt == 0 || t < sp->ats[0]) { --- 13 unchanged lines hidden (view full) --- 1013 /* 1014 ** To get (wrong) behavior that's compatible with System V Release 2.0 1015 ** you'd replace the statement below with 1016 ** t += ttisp->tt_gmtoff; 1017 ** timesub(&t, 0L, sp, tmp); 1018 */ 1019 timesub(&t, ttisp->tt_gmtoff, sp, tmp); 1020 tmp->tm_isdst = ttisp->tt_isdst; |
1021 tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind]; |
1022#ifdef TM_ZONE |
1023 tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind]; |
1024#endif /* defined TM_ZONE */ 1025} 1026 1027struct tm * 1028localtime(timep) 1029const time_t * const timep; 1030{ |
1031 tzset(); |
1032 localsub(timep, 0L, &tm); 1033 return &tm; 1034} 1035 1036/* 1037** gmtsub is to gmtime as localsub is to localtime. 1038*/ 1039 --- 14 unchanged lines hidden (view full) --- 1054 timesub(timep, offset, gmtptr, tmp); 1055#ifdef TM_ZONE 1056 /* 1057 ** Could get fancy here and deliver something such as 1058 ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero, 1059 ** but this is no time for a treasure hunt. 1060 */ 1061 if (offset != 0) |
1062 tmp->TM_ZONE = wildabbr; |
1063 else { 1064#ifdef ALL_STATE 1065 if (gmtptr == NULL) |
1066 tmp->TM_ZONE = gmt; |
1067 else tmp->TM_ZONE = gmtptr->chars; 1068#endif /* defined ALL_STATE */ 1069#ifndef ALL_STATE 1070 tmp->TM_ZONE = gmtptr->chars; 1071#endif /* State Farm */ 1072 } 1073#endif /* defined TM_ZONE */ 1074} 1075 1076struct tm * 1077gmtime(timep) 1078const time_t * const timep; 1079{ |
1080 gmtsub(timep, 0L, &tm); 1081 return &tm; 1082} 1083 1084#ifdef STD_INSPIRED 1085 1086struct tm * 1087offtime(timep, offset) 1088const time_t * const timep; 1089const long offset; 1090{ |
1091 gmtsub(timep, offset, &tm); 1092 return &tm; 1093} 1094 1095#endif /* defined STD_INSPIRED */ 1096 1097static void 1098timesub(timep, offset, sp, tmp) --- 45 unchanged lines hidden (view full) --- 1144#ifdef mc68k 1145 if (*timep == 0x80000000) { 1146 /* 1147 ** A 3B1 muffs the division on the most negative number. 1148 */ 1149 days = -24855; 1150 rem = -11648; 1151 } |
1152#endif /* defined mc68k */ |
1153 rem += (offset - corr); 1154 while (rem < 0) { 1155 rem += SECSPERDAY; 1156 --days; 1157 } 1158 while (rem >= SECSPERDAY) { 1159 rem -= SECSPERDAY; 1160 ++days; --- 36 unchanged lines hidden (view full) --- 1197 tmp->TM_GMTOFF = offset; 1198#endif /* defined TM_GMTOFF */ 1199} 1200 1201char * 1202ctime(timep) 1203const time_t * const timep; 1204{ |
1205/* 1206** Section 4.12.3.2 of X3.159-1989 requires that 1207** The ctime funciton converts the calendar time pointed to by timer 1208** to local time in the form of a string. It is equivalent to 1209** asctime(localtime(timer)) 1210*/ |
1211 return asctime(localtime(timep)); 1212} 1213 1214/* 1215** Adapted from code provided by Robert Elz, who writes: 1216** The "best" way to do mktime I think is based on an idea of Bob 1217** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now). 1218** It does a binary search of the time_t space. Since time_t's are --- 9 unchanged lines hidden (view full) --- 1228** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com). 1229*/ 1230 1231static int 1232increment_overflow(number, delta) 1233int * number; 1234int delta; 1235{ |
1236 int number0; |
1237 1238 number0 = *number; 1239 *number += delta; 1240 return (*number < number0) != (delta < 0); 1241} 1242 1243static int 1244normalize_overflow(tensptr, unitsptr, base) --- 24 unchanged lines hidden (view full) --- 1269 (result = (atmp->tm_min - btmp->tm_min)) == 0) 1270 result = atmp->tm_sec - btmp->tm_sec; 1271 return result; 1272} 1273 1274static time_t 1275time2(tmp, funcp, offset, okayp) 1276struct tm * const tmp; |
1277void (* const funcp) P((const time_t*, long, struct tm*)); |
1278const long offset; 1279int * const okayp; 1280{ 1281 register const struct state * sp; 1282 register int dir; 1283 register int bits; 1284 register int i, j ; 1285 register int saved_seconds; --- 128 unchanged lines hidden (view full) --- 1414 (*funcp)(&t, offset, tmp); 1415 *okayp = TRUE; 1416 return t; 1417} 1418 1419static time_t 1420time1(tmp, funcp, offset) 1421struct tm * const tmp; |
1422void (* const funcp) P((const time_t*, long, struct tm*)); |
1423const long offset; 1424{ 1425 register time_t t; 1426 register const struct state * sp; 1427 register int samei, otheri; 1428 int okay; 1429 1430 if (tmp->tm_isdst > 1) --- 46 unchanged lines hidden (view full) --- 1477 } 1478 return WRONG; 1479} 1480 1481time_t 1482mktime(tmp) 1483struct tm * const tmp; 1484{ |
1485 tzset(); |
1486 return time1(tmp, localsub, 0L); 1487} 1488 1489#ifdef STD_INSPIRED 1490 1491time_t 1492timelocal(tmp) 1493struct tm * const tmp; --- 58 unchanged lines hidden (view full) --- 1552static long 1553leapcorr(timep) 1554time_t * timep; 1555{ 1556 register struct state * sp; 1557 register struct lsinfo * lp; 1558 register int i; 1559 |
1560 sp = lclptr; 1561 i = sp->leapcnt; 1562 while (--i >= 0) { 1563 lp = &sp->lsis[i]; 1564 if (*timep >= lp->ls_trans) 1565 return lp->ls_corr; 1566 } 1567 return 0; 1568} 1569 1570time_t 1571time2posix(t) 1572time_t t; 1573{ |
1574 tzset(); |
1575 return t - leapcorr(&t); 1576} 1577 1578time_t 1579posix2time(t) 1580time_t t; 1581{ 1582 time_t x; 1583 time_t y; 1584 |
1585 tzset(); |
1586 /* 1587 ** For a positive leap second hit, the result 1588 ** is not unique. For a negative leap second 1589 ** hit, the corresponding time doesn't exist, 1590 ** so we return an adjacent second. 1591 */ 1592 x = t + leapcorr(&t); 1593 y = x - leapcorr(&x); --- 19 unchanged lines hidden --- |