asctime/ctime: Check for too low input time, fixes one msvcrt time winetest
[reactos.git] / reactos / lib / sdk / crt / time / ctime.c
1
2 // fix djdir
3
4 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
5 /* This file has been modified by DJ Delorie. These modifications are
6 ** Copyright (C) 1995 DJ Delorie, 24 Kirsten Ave, Rochester NH,
7 ** 03867-2954, USA.
8 */
9
10 /*
11 * Copyright (c) 1987, 1989 Regents of the University of California.
12 * All rights reserved.
13 *
14 * This code is derived from software contributed to Berkeley by
15 * Arthur David Olson of the National Cancer Institute.
16 *
17 * Redistribution and use in source and binary forms are permitted provided
18 * that: (1) source distributions retain this entire copyright notice and
19 * comment, and (2) distributions including binaries display the following
20 * acknowledgement: ``This product includes software developed by the
21 * University of California, Berkeley and its contributors'' in the
22 * documentation or other materials provided with the distribution and in
23 * all advertising materials mentioning features or use of this software.
24 * Neither the name of the University nor the names of its contributors may
25 * be used to endorse or promote products derived from this software without
26 * specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
28 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
29 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 */
31
32 /*
33 ** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu).
34 ** POSIX-style TZ environment variable handling from Guy Harris
35 ** (guy@auspex.com).
36 */
37
38 #include <precomp.h>
39
40 #include "tzfile.h"
41 #include "posixrul.h"
42
43 #ifdef __cplusplus
44 #define CPP_CONST const
45 #else
46 #define CPP_CONST
47 #endif
48
49 #undef P
50 #define P(s) s
51 #define alloc_size_t size_t
52 #define qsort_size_t size_t
53 #define fread_size_t size_t
54 #define fwrite_size_t size_t
55
56 #define ACCESS_MODE O_RDONLY|O_BINARY
57 #define OPEN_MODE O_RDONLY|O_BINARY
58
59 /*
60 ** Someone might make incorrect use of a time zone abbreviation:
61 ** 1. They might reference tzname[0] before calling tzset (explicitly
62 ** or implicitly).
63 ** 2. They might reference tzname[1] before calling tzset (explicitly
64 ** or implicitly).
65 ** 3. They might reference tzname[1] after setting to a time zone
66 ** in which Daylight Saving Time is never observed.
67 ** 4. They might reference tzname[0] after setting to a time zone
68 ** in which Standard Time is never observed.
69 ** 5. They might reference tm.TM_ZONE after calling offtime.
70 ** What's best to do in the above cases is open to debate;
71 ** for now, we just set things up so that in any of the five cases
72 ** WILDABBR is used. Another possibility: initialize tzname[0] to the
73 ** string "tzname[0] used before set", and similarly for the other cases.
74 ** And another: initialize tzname[0] to "ERA", with an explanation in the
75 ** manual page of what this "time zone abbreviation" means (doing this so
76 ** that tzname[0] has the "normal" length of three characters).
77 */
78
79 void _set_daylight_export(int);
80 void _set_timezone_export(int);
81
82
83 /* buffers must hold 64 characters! */
84 static char TZ_NAME[64] = "PST";
85 static char TZ_DST_NAME[64] = "PDT";
86
87 #ifndef TRUE
88 #define TRUE 1
89 #define FALSE 0
90 #endif /* !defined TRUE */
91
92 static const char GMT[] = "GMT";
93
94 struct ttinfo { /* time type information */
95 long tt_gmtoff; /* GMT offset in seconds */
96 int tt_isdst; /* used to set tm_isdst */
97 int tt_abbrind; /* abbreviation list index */
98 int tt_ttisstd; /* TRUE if transition is std time */
99 };
100
101 struct lsinfo { /* leap second information */
102 time_t ls_trans; /* transition time */
103 long ls_corr; /* correction to apply */
104 };
105
106 struct state {
107 int leapcnt;
108 int timecnt;
109 int typecnt;
110 int charcnt;
111 time_t ats[TZ_MAX_TIMES];
112 unsigned char types[TZ_MAX_TIMES];
113 struct ttinfo ttis[TZ_MAX_TYPES];
114 char chars[(TZ_MAX_CHARS + 1 > sizeof GMT) ? TZ_MAX_CHARS + 1 : sizeof GMT];
115 struct lsinfo lsis[TZ_MAX_LEAPS];
116 };
117
118 struct rule {
119 int r_type; /* type of rule--see below */
120 int r_day; /* day number of rule */
121 int r_week; /* week number of rule */
122 int r_mon; /* month number of rule */
123 long r_time; /* transition time of rule */
124 };
125
126 #define JULIAN_DAY 0 /* Jn - Julian day */
127 #define DAY_OF_YEAR 1 /* n - day of year */
128 #define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
129
130 /*
131 ** Prototypes for static functions.
132 */
133 #if 0
134 static long detzcode P((const char * codep));
135 static const char * getzname P((const char * strp));
136 static const char * getnum P((const char * strp, int * nump, int min, int max));
137 static const char * getsecs P((const char * strp, long * secsp));
138 static const char * getoffset P((const char * strp, long * offsetp));
139 static const char * getrule P((const char * strp, struct rule * rulep));
140 static void gmtload P((struct state * sp));
141 static void gmtsub P((const time_t * timep, long offset, struct tm * tmp));
142 static void localsub P((const time_t * timep, long offset, struct tm * tmp));
143 static void normalize P((int * tensptr, int * unitsptr, int base));
144 static void settzname P((void));
145 static time_t time1 P((struct tm * tmp, void (* funcp)(const time_t * CPP_CONST, const long, struct tm * CPP_CONST), long offset));
146 static time_t time2 P((struct tm *tmp, void (* funcp)(const time_t * CPP_CONST, const long, struct tm * CPP_CONST), long offset, int * okayp));
147 static void timesub P((const time_t * timep, long offset, const struct state * sp, struct tm * tmp));
148 static int tmcomp P((const struct tm * atmp, const struct tm * btmp));
149 static time_t transtime P((time_t janfirst, int year, const struct rule * rulep, long offset));
150 static int tzload P((const char * name, struct state * sp));
151 static int tzparse P((const char * name, struct state * sp, int lastditch));
152 static void tzsetwall(void);
153
154 #else
155
156 static const char * getnum(const char * strp, int * CPP_CONST nump, const int min, const int max);
157 static void timesub(const time_t * CPP_CONST timep, const long offset, const struct state * CPP_CONST sp, struct tm * CPP_CONST tmp);
158 static time_t transtime(const time_t janfirst, const int year, const struct rule * CPP_CONST rulep, const long offset);
159 static void tzsetwall(void);
160
161 #endif
162
163 #ifdef ALL_STATE
164 static struct state *lclptr;
165 static struct state *gmtptr;
166 #endif /* defined ALL_STATE */
167
168 #ifndef ALL_STATE
169 static struct state lclmem;
170 static struct state gmtmem;
171 #define lclptr (&lclmem)
172 #define gmtptr (&gmtmem)
173 #endif /* State Farm */
174
175 static int lcl_is_set;
176 static int gmt_is_set;
177
178 char * _tzname[2] = {
179 TZ_NAME,
180 TZ_DST_NAME,
181 };
182
183 static long
184 detzcode(const char * CPP_CONST codep)
185 {
186 long result;
187 int i;
188
189 result = 0;
190 for (i = 0; i < 4; ++i)
191 result = (result << 8) | (codep[i] & 0xff);
192 return result;
193 }
194
195 static void
196 settzname(void)
197 {
198 const struct state * CPP_CONST sp = lclptr;
199 int i;
200
201 _tzname[0] = TZ_NAME;
202 _tzname[1] = TZ_DST_NAME;
203 #ifdef ALL_STATE
204 if (sp == NULL)
205 {
206 _tzname[0] = _tzname[1] = GMT;
207 return;
208 }
209 #endif /* defined ALL_STATE */
210 for (i = 0; i < sp->typecnt; ++i)
211 {
212 register const struct ttinfo * CPP_CONST ttisp = &sp->ttis[i];
213
214 _tzname[ttisp->tt_isdst] =
215 (char *)&sp->chars[ttisp->tt_abbrind];
216 #if 0
217 if (ttisp->tt_isdst) {
218 //_daylight = 1;
219 _set_daylight_export(1);
220 }
221 if (i == 0 || !ttisp->tt_isdst) {
222 //_timezone_dll = -(ttisp->tt_gmtoff);
223 _set_timezone_export(-(ttisp->tt_gmtoff));
224 }
225 if (i == 0 || ttisp->tt_isdst) {
226 _altzone = -(ttisp->tt_gmtoff);
227 }
228 #endif
229 }
230 /*
231 ** And to get the latest zone names into tzname. . .
232 */
233 for (i = 0; i < sp->timecnt; ++i)
234 {
235 const struct ttinfo * CPP_CONST ttisp = &sp->ttis[sp->types[i]];
236
237 _tzname[ttisp->tt_isdst] = (char *)&sp->chars[ttisp->tt_abbrind];
238 }
239 }
240
241 static char* tzdir(void)
242 {
243 static char dir[80]={0}, *cp;
244 if (dir[0] == 0)
245 {
246 if ((cp = getenv("TZDIR")))
247 {
248 strcpy(dir, cp);
249 }
250 else if ((cp = getenv("DJDIR")))
251 {
252 strcpy(dir, cp);
253 strcat(dir, "/zoneinfo");
254 }
255 else
256 strcpy(dir, "./");
257 }
258 return dir;
259 }
260
261 static int tzload(const char* name, struct state* CPP_CONST sp)
262 {
263 const char * p;
264 int i;
265 int fid;
266 char fullname[FILENAME_MAX + 1];
267 const struct tzhead * tzhp;
268 char buf[sizeof *sp + sizeof *tzhp];
269 int ttisstdcnt;
270
271 if (name == NULL && (name = TZDEFAULT) == NULL)
272 return -1;
273
274 if (name[0] == ':')
275 ++name;
276 if (name[0] != '/')
277 {
278 if ((p = tzdir()) == NULL)
279 return -1;
280 if ((strlen(p) + strlen(name) + 1) >= sizeof fullname)
281 return -1;
282 strcpy(fullname, p);
283 strcat(fullname, "/");
284 strcat(fullname, name);
285 name = fullname;
286 }
287
288 if ((fid = _open(name, OPEN_MODE)) == -1)
289 {
290 const char *base = strrchr(name, '/');
291 if (base)
292 base++;
293 else
294 base = name;
295 if (strcmp(base, "posixrules"))
296 return -1;
297
298 /* We've got a built-in copy of posixrules just in case */
299 memcpy(buf, _posixrules_data, sizeof(_posixrules_data));
300 i = sizeof(_posixrules_data);
301 }
302 else
303 {
304 i = _read(fid, buf, sizeof buf);
305 if (_close(fid) != 0 || i < (int)sizeof *tzhp)
306 return -1;
307 }
308
309 tzhp = (struct tzhead *) buf;
310 ttisstdcnt = (int) detzcode(tzhp->tzh_ttisstdcnt);
311 sp->leapcnt = (int) detzcode(tzhp->tzh_leapcnt);
312 sp->timecnt = (int) detzcode(tzhp->tzh_timecnt);
313 sp->typecnt = (int) detzcode(tzhp->tzh_typecnt);
314 sp->charcnt = (int) detzcode(tzhp->tzh_charcnt);
315 if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||
316 sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||
317 sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||
318 sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS ||
319 (ttisstdcnt != sp->typecnt && ttisstdcnt != 0))
320 return -1;
321 if (i < (int)sizeof *tzhp +
322 sp->timecnt * (4 + (int)sizeof (char)) +
323 sp->typecnt * (4 + 2 * (int)sizeof (char)) +
324 sp->charcnt * (int)sizeof (char) +
325 sp->leapcnt * 2 * 4 +
326 ttisstdcnt * (int)sizeof (char))
327 return -1;
328 p = buf + sizeof *tzhp;
329 for (i = 0; i < sp->timecnt; ++i)
330 {
331 sp->ats[i] = detzcode(p);
332 p += 4;
333 }
334 for (i = 0; i < sp->timecnt; ++i)
335 {
336 sp->types[i] = (unsigned char) *p++;
337 if (sp->types[i] >= sp->typecnt)
338 return -1;
339 }
340 for (i = 0; i < sp->typecnt; ++i)
341 {
342 struct ttinfo * ttisp;
343
344 ttisp = &sp->ttis[i];
345 ttisp->tt_gmtoff = detzcode(p);
346 p += 4;
347 ttisp->tt_isdst = (unsigned char) *p++;
348 if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
349 return -1;
350 ttisp->tt_abbrind = (unsigned char) *p++;
351 if (ttisp->tt_abbrind < 0 ||
352 ttisp->tt_abbrind > sp->charcnt)
353 return -1;
354 }
355 for (i = 0; i < sp->charcnt; ++i)
356 sp->chars[i] = *p++;
357 sp->chars[i] = '\0'; /* ensure '\0' at end */
358 for (i = 0; i < sp->leapcnt; ++i)
359 {
360 struct lsinfo * lsisp;
361
362 lsisp = &sp->lsis[i];
363 lsisp->ls_trans = detzcode(p);
364 p += 4;
365 lsisp->ls_corr = detzcode(p);
366 p += 4;
367 }
368 for (i = 0; i < sp->typecnt; ++i)
369 {
370 struct ttinfo * ttisp;
371
372 ttisp = &sp->ttis[i];
373 if (ttisstdcnt == 0)
374 ttisp->tt_ttisstd = FALSE;
375 else
376 {
377 ttisp->tt_ttisstd = *p++;
378 if (ttisp->tt_ttisstd != TRUE &&
379 ttisp->tt_ttisstd != FALSE)
380 return -1;
381 }
382 }
383 return 0;
384 }
385
386 static const int mon_lengths[2][MONSPERYEAR] = {
387 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
388 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
389 };
390
391 static const int year_lengths[2] = {
392 DAYSPERNYEAR, DAYSPERLYEAR
393 };
394
395 /*
396 ** Given a pointer into a time zone string, scan until a character that is not
397 ** a valid character in a zone name is found. Return a pointer to that
398 ** character.
399 */
400
401 static const char*
402 getzname(const char* strp)
403 {
404 char c;
405
406 while ((c = *strp) != '\0' && !isdigit(c) && c != ',' && c != '-' &&
407 c != '+')
408 ++strp;
409 return strp;
410 }
411
412 /*
413 ** Given a pointer into a time zone string, extract a number from that string.
414 ** Check that the number is within a specified range; if it is not, return
415 ** NULL.
416 ** Otherwise, return a pointer to the first character not part of the number.
417 */
418
419 static const char*
420 getnum(const char* strp, int* CPP_CONST nump, const int min, const int max)
421 {
422 char c;
423 int num;
424
425 if (strp == NULL || !isdigit(*strp))
426 return NULL;
427 num = 0;
428 while ((c = *strp) != '\0' && isdigit(c))
429 {
430 num = num * 10 + (c - '0');
431 if (num > max)
432 return NULL;
433 ++strp;
434 }
435 if (num < min)
436 return NULL;
437 *nump = num;
438 return strp;
439 }
440
441 /*
442 ** Given a pointer into a time zone string, extract a number of seconds,
443 ** in hh[:mm[:ss]] form, from the string.
444 ** If any error occurs, return NULL.
445 ** Otherwise, return a pointer to the first character not part of the number
446 ** of seconds.
447 */
448
449 static const char *
450 getsecs(const char *strp, long * CPP_CONST secsp)
451 {
452 int num;
453
454 strp = getnum(strp, &num, 0, HOURSPERDAY);
455 if (strp == NULL)
456 return NULL;
457 *secsp = num * SECSPERHOUR;
458 if (*strp == ':')
459 {
460 ++strp;
461 strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
462 if (strp == NULL)
463 return NULL;
464 *secsp += num * SECSPERMIN;
465 if (*strp == ':')
466 {
467 ++strp;
468 strp = getnum(strp, &num, 0, SECSPERMIN - 1);
469 if (strp == NULL)
470 return NULL;
471 *secsp += num;
472 }
473 }
474 return strp;
475 }
476
477 /*
478 ** Given a pointer into a time zone string, extract an offset, in
479 ** [+-]hh[:mm[:ss]] form, from the string.
480 ** If any error occurs, return NULL.
481 ** Otherwise, return a pointer to the first character not part of the time.
482 */
483
484 static const char *
485 getoffset(const char *strp, long * CPP_CONST offsetp)
486 {
487 int neg;
488
489 if (*strp == '-')
490 {
491 neg = 1;
492 ++strp;
493 }
494 else if (isdigit(*strp) || *strp++ == '+')
495 neg = 0;
496 else
497 return NULL; /* illegal offset */
498 strp = getsecs(strp, offsetp);
499 if (strp == NULL)
500 return NULL; /* illegal time */
501 if (neg)
502 *offsetp = -*offsetp;
503 return strp;
504 }
505
506 /*
507 ** Given a pointer into a time zone string, extract a rule in the form
508 ** date[/time]. See POSIX section 8 for the format of "date" and "time".
509 ** If a valid rule is not found, return NULL.
510 ** Otherwise, return a pointer to the first character not part of the rule.
511 */
512
513 static const char *
514 getrule(const char *strp, struct rule * CPP_CONST rulep)
515 {
516 if (*strp == 'J')
517 {
518 /*
519 ** Julian day.
520 */
521 rulep->r_type = JULIAN_DAY;
522 ++strp;
523 strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
524 }
525 else if (*strp == 'M')
526 {
527 /*
528 ** Month, week, day.
529 */
530 rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
531 ++strp;
532 strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
533 if (strp == NULL)
534 return NULL;
535 if (*strp++ != '.')
536 return NULL;
537 strp = getnum(strp, &rulep->r_week, 1, 5);
538 if (strp == NULL)
539 return NULL;
540 if (*strp++ != '.')
541 return NULL;
542 strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
543 }
544 else if (isdigit(*strp))
545 {
546 /*
547 ** Day of year.
548 */
549 rulep->r_type = DAY_OF_YEAR;
550 strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
551 }
552 else
553 return NULL; /* invalid format */
554 if (strp == NULL)
555 return NULL;
556 if (*strp == '/')
557 {
558 /*
559 ** Time specified.
560 */
561 ++strp;
562 strp = getsecs(strp, &rulep->r_time);
563 }
564 else
565 rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
566 return strp;
567 }
568
569 /*
570 ** Given the Epoch-relative time of January 1, 00:00:00 GMT, in a year, the
571 ** year, a rule, and the offset from GMT at the time that rule takes effect,
572 ** calculate the Epoch-relative time that rule takes effect.
573 */
574
575 static time_t
576 transtime(const time_t janfirst, const int year, const struct rule * CPP_CONST rulep, const long offset)
577 {
578 int leapyear;
579 time_t value=0;
580 int i;
581 int d, m1, yy0, yy1, yy2, dow;
582
583 leapyear = isleap(year);
584 switch (rulep->r_type)
585 {
586
587 case JULIAN_DAY:
588 /*
589 ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
590 ** years.
591 ** In non-leap years, or if the day number is 59 or less, just
592 ** add SECSPERDAY times the day number-1 to the time of
593 ** January 1, midnight, to get the day.
594 */
595 value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
596 if (leapyear && rulep->r_day >= 60)
597 value += SECSPERDAY;
598 break;
599
600 case DAY_OF_YEAR:
601 /*
602 ** n - day of year.
603 ** Just add SECSPERDAY times the day number to the time of
604 ** January 1, midnight, to get the day.
605 */
606 value = janfirst + rulep->r_day * SECSPERDAY;
607 break;
608
609 case MONTH_NTH_DAY_OF_WEEK:
610 /*
611 ** Mm.n.d - nth "dth day" of month m.
612 */
613 value = janfirst;
614 for (i = 0; i < rulep->r_mon - 1; ++i)
615 value += mon_lengths[leapyear][i] * SECSPERDAY;
616
617 /*
618 ** Use Zeller's Congruence to get day-of-week of first day of
619 ** month.
620 */
621 m1 = (rulep->r_mon + 9) % 12 + 1;
622 yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
623 yy1 = yy0 / 100;
624 yy2 = yy0 % 100;
625 dow = ((26 * m1 - 2) / 10 +
626 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
627 if (dow < 0)
628 dow += DAYSPERWEEK;
629
630 /*
631 ** "dow" is the day-of-week of the first day of the month. Get
632 ** the day-of-month (zero-origin) of the first "dow" day of the
633 ** month.
634 */
635 d = rulep->r_day - dow;
636 if (d < 0)
637 d += DAYSPERWEEK;
638 for (i = 1; i < rulep->r_week; ++i)
639 {
640 if (d + DAYSPERWEEK >=
641 mon_lengths[leapyear][rulep->r_mon - 1])
642 break;
643 d += DAYSPERWEEK;
644 }
645
646 /*
647 ** "d" is the day-of-month (zero-origin) of the day we want.
648 */
649 value += d * SECSPERDAY;
650 break;
651 }
652
653 /*
654 ** "value" is the Epoch-relative time of 00:00:00 GMT on the day in
655 ** question. To get the Epoch-relative time of the specified local
656 ** time on that day, add the transition time and the current offset
657 ** from GMT.
658 */
659 return value + rulep->r_time + offset;
660 }
661
662 /*
663 ** Given a POSIX section 8-style TZ string, fill in the rule tables as
664 ** appropriate.
665 */
666
667 static int
668 tzparse(const char *name, struct state * CPP_CONST sp, const int lastditch)
669 {
670 const char * stdname;
671 const char * dstname=0;
672 int stdlen;
673 int dstlen;
674 long stdoffset;
675 long dstoffset;
676 time_t * atp;
677 unsigned char * typep;
678 char * cp;
679 int load_result;
680
681 stdname = name;
682 if (lastditch)
683 {
684 stdlen = strlen(name); /* length of standard zone name */
685 name += stdlen;
686 if (stdlen >= (int)sizeof sp->chars)
687 stdlen = (int)(sizeof sp->chars) - 1;
688 }
689 else
690 {
691 name = getzname(name);
692 stdlen = name - stdname;
693 if (stdlen < 3)
694 return -1;
695 }
696 if (*name == '\0')
697 return -1;
698 else
699 {
700 name = getoffset(name, &stdoffset);
701 if (name == NULL)
702 return -1;
703 }
704 load_result = tzload(TZDEFRULES, sp);
705 if (load_result != 0)
706 sp->leapcnt = 0; /* so, we're off a little */
707 if (*name != '\0')
708 {
709 dstname = name;
710 name = getzname(name);
711 dstlen = name - dstname; /* length of DST zone name */
712 if (dstlen < 3)
713 return -1;
714 if (*name != '\0' && *name != ',' && *name != ';')
715 {
716 name = getoffset(name, &dstoffset);
717 if (name == NULL)
718 return -1;
719 }
720 else
721 dstoffset = stdoffset - SECSPERHOUR;
722 if (*name == ',' || *name == ';')
723 {
724 struct rule start;
725 struct rule end;
726 int year;
727 time_t janfirst;
728 time_t starttime;
729 time_t endtime;
730
731 ++name;
732 if ((name = getrule(name, &start)) == NULL)
733 return -1;
734 if (*name++ != ',')
735 return -1;
736 if ((name = getrule(name, &end)) == NULL)
737 return -1;
738 if (*name != '\0')
739 return -1;
740 sp->typecnt = 2; /* standard time and DST */
741 /*
742 ** Two transitions per year, from EPOCH_YEAR to 2037.
743 */
744 sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);
745 if (sp->timecnt > TZ_MAX_TIMES)
746 return -1;
747 sp->ttis[0].tt_gmtoff = -dstoffset;
748 sp->ttis[0].tt_isdst = 1;
749 sp->ttis[0].tt_abbrind = stdlen + 1;
750 sp->ttis[1].tt_gmtoff = -stdoffset;
751 sp->ttis[1].tt_isdst = 0;
752 sp->ttis[1].tt_abbrind = 0;
753 atp = sp->ats;
754 typep = sp->types;
755 janfirst = 0;
756 for (year = EPOCH_YEAR; year <= 2037; ++year)
757 {
758 starttime = transtime(janfirst, year, &start,
759 stdoffset);
760 endtime = transtime(janfirst, year, &end,
761 dstoffset);
762 if (starttime > endtime)
763 {
764 *atp++ = endtime;
765 *typep++ = 1; /* DST ends */
766 *atp++ = starttime;
767 *typep++ = 0; /* DST begins */
768 }
769 else
770 {
771 *atp++ = starttime;
772 *typep++ = 0; /* DST begins */
773 *atp++ = endtime;
774 *typep++ = 1; /* DST ends */
775 }
776 janfirst +=
777 year_lengths[isleap(year)] * SECSPERDAY;
778 }
779 }
780 else
781 {
782 int sawstd;
783 int sawdst;
784 long stdfix;
785 long dstfix;
786 long oldfix;
787 int isdst;
788 int i;
789
790 if (*name != '\0')
791 return -1;
792 if (load_result != 0)
793 return -1;
794 /*
795 ** Compute the difference between the real and
796 ** prototype standard and summer time offsets
797 ** from GMT, and put the real standard and summer
798 ** time offsets into the rules in place of the
799 ** prototype offsets.
800 */
801 sawstd = FALSE;
802 sawdst = FALSE;
803 stdfix = 0;
804 dstfix = 0;
805 for (i = 0; i < sp->typecnt; ++i)
806 {
807 if (sp->ttis[i].tt_isdst)
808 {
809 oldfix = dstfix;
810 dstfix =
811 sp->ttis[i].tt_gmtoff + dstoffset;
812 if (sawdst && (oldfix != dstfix))
813 return -1;
814 sp->ttis[i].tt_gmtoff = -dstoffset;
815 sp->ttis[i].tt_abbrind = stdlen + 1;
816 sawdst = TRUE;
817 }
818 else
819 {
820 oldfix = stdfix;
821 stdfix =
822 sp->ttis[i].tt_gmtoff + stdoffset;
823 if (sawstd && (oldfix != stdfix))
824 return -1;
825 sp->ttis[i].tt_gmtoff = -stdoffset;
826 sp->ttis[i].tt_abbrind = 0;
827 sawstd = TRUE;
828 }
829 }
830 /*
831 ** Make sure we have both standard and summer time.
832 */
833 if (!sawdst || !sawstd)
834 return -1;
835 /*
836 ** Now correct the transition times by shifting
837 ** them by the difference between the real and
838 ** prototype offsets. Note that this difference
839 ** can be different in standard and summer time;
840 ** the prototype probably has a 1-hour difference
841 ** between standard and summer time, but a different
842 ** difference can be specified in TZ.
843 */
844 isdst = FALSE; /* we start in standard time */
845 for (i = 0; i < sp->timecnt; ++i)
846 {
847 const struct ttinfo * ttisp;
848
849 /*
850 ** If summer time is in effect, and the
851 ** transition time was not specified as
852 ** standard time, add the summer time
853 ** offset to the transition time;
854 ** otherwise, add the standard time offset
855 ** to the transition time.
856 */
857 ttisp = &sp->ttis[sp->types[i]];
858 sp->ats[i] +=
859 (isdst && !ttisp->tt_ttisstd) ?
860 dstfix : stdfix;
861 isdst = ttisp->tt_isdst;
862 }
863 }
864 }
865 else
866 {
867 dstlen = 0;
868 sp->typecnt = 1; /* only standard time */
869 sp->timecnt = 0;
870 sp->ttis[0].tt_gmtoff = -stdoffset;
871 sp->ttis[0].tt_isdst = 0;
872 sp->ttis[0].tt_abbrind = 0;
873 }
874 sp->charcnt = stdlen + 1;
875 if (dstlen != 0)
876 sp->charcnt += dstlen + 1;
877 if (sp->charcnt > (int)sizeof sp->chars)
878 return -1;
879 cp = sp->chars;
880 (void) strncpy(cp, stdname, stdlen);
881 cp += stdlen;
882 *cp++ = '\0';
883 if (dstlen != 0)
884 {
885 (void) strncpy(cp, dstname, dstlen);
886 *(cp + dstlen) = '\0';
887 }
888 return 0;
889 }
890
891 static void
892 gmtload(struct state * CPP_CONST sp)
893 {
894 if (tzload(GMT, sp) != 0)
895 (void) tzparse(GMT, sp, TRUE);
896 }
897
898 /*
899 * @implemented
900 */
901 void
902 _tzset(void)
903 {
904 const char * name;
905
906 name = getenv("TZ");
907 if (name == NULL)
908 {
909 tzsetwall();
910 return;
911 }
912 lcl_is_set = TRUE;
913 #ifdef ALL_STATE
914 if (lclptr == NULL)
915 {
916 lclptr = (struct state *) malloc(sizeof *lclptr);
917 if (lclptr == NULL)
918 {
919 settzname(); /* all we can do */
920 return;
921 }
922 }
923 #endif /* defined ALL_STATE */
924 if (*name == '\0')
925 {
926 /*
927 ** User wants it fast rather than right.
928 */
929 lclptr->leapcnt = 0; /* so, we're off a little */
930 lclptr->timecnt = 0;
931 lclptr->ttis[0].tt_gmtoff = 0;
932 lclptr->ttis[0].tt_abbrind = 0;
933 (void) strcpy(lclptr->chars, GMT);
934 }
935 else if (tzload(name, lclptr) != 0)
936 if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
937 gmtload(lclptr);
938 settzname();
939 }
940
941 void
942 tzsetwall(void)
943 {
944 lcl_is_set = TRUE;
945 #ifdef ALL_STATE
946 if (lclptr == NULL)
947 {
948 lclptr = (struct state *) malloc(sizeof *lclptr);
949 if (lclptr == NULL)
950 {
951 settzname(); /* all we can do */
952 return;
953 }
954 }
955 #endif /* defined ALL_STATE */
956 if (tzload((char *) NULL, lclptr) != 0)
957 gmtload(lclptr);
958 settzname();
959 }
960
961 /*
962 ** The easy way to behave "as if no library function calls" localtime
963 ** is to not call it--so we drop its guts into "localsub", which can be
964 ** freely called. (And no, the PANS doesn't require the above behavior--
965 ** but it *is* desirable.)
966 **
967 ** The unused offset argument is for the benefit of mktime variants.
968 */
969
970 /*ARGSUSED*/
971 static void
972 localsub(const time_t * CPP_CONST timep, const long offset, struct tm * CPP_CONST tmp)
973 {
974 const struct state * sp;
975 const struct ttinfo * ttisp;
976 int i;
977 const time_t t = *timep;
978
979 if (!lcl_is_set)
980 _tzset();
981 sp = lclptr;
982 #ifdef ALL_STATE
983 if (sp == NULL)
984 {
985 gmtsub(timep, offset, tmp);
986 return;
987 }
988 #endif /* defined ALL_STATE */
989 if (sp->timecnt == 0 || t < sp->ats[0])
990 {
991 i = 0;
992 while (sp->ttis[i].tt_isdst)
993 if (++i >= sp->typecnt)
994 {
995 i = 0;
996 break;
997 }
998 }
999 else
1000 {
1001 for (i = 1; i < sp->timecnt; ++i)
1002 if (t < sp->ats[i])
1003 break;
1004 i = sp->types[i - 1];
1005 }
1006 ttisp = &sp->ttis[i];
1007 /*
1008 ** To get (wrong) behavior that's compatible with System V Release 2.0
1009 ** you'd replace the statement below with
1010 ** t += ttisp->tt_gmtoff;
1011 ** timesub(&t, 0L, sp, tmp);
1012 */
1013 timesub(&t, ttisp->tt_gmtoff, sp, tmp);
1014 tmp->tm_isdst = ttisp->tt_isdst;
1015 _tzname[tmp->tm_isdst] = (char *)&sp->chars[ttisp->tt_abbrind];
1016 #if 0
1017 /* tm_zone doesnt exist in windows msvcrt -Gunnar */
1018 tmp->tm_zone = (char *)&sp->chars[ttisp->tt_abbrind];
1019 #endif
1020 }
1021
1022 /*
1023 * @implemented
1024 */
1025 struct tm *
1026 localtime(const time_t * CPP_CONST timep)
1027 {
1028 static struct tm tm;
1029
1030 localsub(timep, 0L, &tm);
1031 return &tm;
1032 }
1033
1034 /*
1035 ** gmtsub is to gmtime as localsub is to localtime.
1036 */
1037
1038 static void
1039 gmtsub(const time_t * CPP_CONST timep, const long offset, struct tm * CPP_CONST tmp)
1040 {
1041 if (!gmt_is_set)
1042 {
1043 gmt_is_set = TRUE;
1044 #ifdef ALL_STATE
1045 gmtptr = (struct state *) malloc(sizeof *gmtptr);
1046 if (gmtptr != NULL)
1047 #endif /* defined ALL_STATE */
1048 gmtload(gmtptr);
1049 }
1050 timesub(timep, offset, gmtptr, tmp);
1051 /*
1052 ** Could get fancy here and deliver something such as
1053 ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero,
1054 ** but this is no time for a treasure hunt.
1055 */
1056 #if 0
1057 /* tm_zone doesnt exist in windows msvcrt -Gunnar */
1058 if (offset != 0)
1059 tmp->tm_zone = TZ_NAME;
1060 else
1061 {
1062 #ifdef ALL_STATE
1063 if (gmtptr == NULL)
1064 tmp->TM_ZONE = GMT;
1065 else
1066 tmp->TM_ZONE = gmtptr->chars;
1067 #endif /* defined ALL_STATE */
1068 #ifndef ALL_STATE
1069 tmp->tm_zone = gmtptr->chars;
1070 #endif /* State Farm */
1071 }
1072 #endif /* if 0 */
1073 }
1074
1075 /*
1076 * @implemented
1077 */
1078 struct tm *
1079 gmtime(const time_t * CPP_CONST timep)
1080 {
1081 static struct tm tm;
1082
1083 gmtsub(timep, 0L, &tm);
1084 return &tm;
1085 }
1086
1087 static void
1088 timesub(const time_t * CPP_CONST timep, const long offset, const struct state * CPP_CONST sp, struct tm * CPP_CONST tmp)
1089 {
1090 const struct lsinfo * lp;
1091 long days;
1092 long rem;
1093 int y;
1094 int yleap;
1095 const int * ip;
1096 long corr;
1097 int hit;
1098 int i;
1099
1100 corr = 0;
1101 hit = FALSE;
1102 #ifdef ALL_STATE
1103 i = (sp == NULL) ? 0 : sp->leapcnt;
1104 #endif /* defined ALL_STATE */
1105 #ifndef ALL_STATE
1106 i = sp->leapcnt;
1107 #endif /* State Farm */
1108 while (--i >= 0)
1109 {
1110 lp = &sp->lsis[i];
1111 if (*timep >= lp->ls_trans)
1112 {
1113 if (*timep == lp->ls_trans)
1114 hit = ((i == 0 && lp->ls_corr > 0) ||
1115 lp->ls_corr > sp->lsis[i - 1].ls_corr);
1116 corr = lp->ls_corr;
1117 break;
1118 }
1119 }
1120 days = *timep / SECSPERDAY;
1121 rem = *timep % SECSPERDAY;
1122 #ifdef mc68k
1123 if (*timep == 0x80000000)
1124 {
1125 /*
1126 ** A 3B1 muffs the division on the most negative number.
1127 */
1128 days = -24855;
1129 rem = -11648;
1130 }
1131 #endif /* mc68k */
1132 rem += (offset - corr);
1133 while (rem < 0)
1134 {
1135 rem += SECSPERDAY;
1136 --days;
1137 }
1138 while (rem >= SECSPERDAY)
1139 {
1140 rem -= SECSPERDAY;
1141 ++days;
1142 }
1143 tmp->tm_hour = (int) (rem / SECSPERHOUR);
1144 rem = rem % SECSPERHOUR;
1145 tmp->tm_min = (int) (rem / SECSPERMIN);
1146 tmp->tm_sec = (int) (rem % SECSPERMIN);
1147 if (hit)
1148 /*
1149 ** A positive leap second requires a special
1150 ** representation. This uses "... ??:59:60".
1151 */
1152 ++(tmp->tm_sec);
1153 tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
1154 if (tmp->tm_wday < 0)
1155 tmp->tm_wday += DAYSPERWEEK;
1156 y = EPOCH_YEAR;
1157 if (days >= 0)
1158 for ( ; ; )
1159 {
1160 yleap = isleap(y);
1161 if (days < (long) year_lengths[yleap])
1162 break;
1163 ++y;
1164 days = days - (long) year_lengths[yleap];
1165 }
1166 else
1167 do {
1168 --y;
1169 yleap = isleap(y);
1170 days = days + (long) year_lengths[yleap];
1171 } while (days < 0);
1172 tmp->tm_year = y - TM_YEAR_BASE;
1173 tmp->tm_yday = (int) days;
1174 ip = mon_lengths[yleap];
1175 for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon))
1176 days = days - (long) ip[tmp->tm_mon];
1177 tmp->tm_mday = (int) (days + 1);
1178 tmp->tm_isdst = 0;
1179 #if 0
1180 /* tm_gmtoff doesnt exist in windows msvcrt -Gunnar */
1181 tmp->tm_gmtoff = offset;
1182 #endif
1183 }
1184
1185 /*
1186 ** A la X3J11
1187 */
1188
1189 /*
1190 * @implemented
1191 */
1192 char *
1193 asctime(const struct tm *timeptr)
1194 {
1195 static const char wday_name[DAYSPERWEEK][3] = {
1196 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
1197 };
1198 static const char mon_name[MONSPERYEAR][3] = {
1199 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1200 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
1201 };
1202 static char result[26];
1203 char* res = result;
1204
1205 /* Check for invalid input time */
1206 if (timeptr->tm_year <= 69)
1207 {
1208 res = NULL;
1209 }
1210 else
1211 {
1212 sprintf(res, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
1213 wday_name[timeptr->tm_wday],
1214 mon_name[timeptr->tm_mon],
1215 timeptr->tm_mday, timeptr->tm_hour,
1216 timeptr->tm_min, timeptr->tm_sec,
1217 TM_YEAR_BASE + timeptr->tm_year);
1218 }
1219 return res;
1220 }
1221
1222 /*
1223 * @implemented
1224 */
1225 char *
1226 ctime(const time_t * CPP_CONST timep)
1227 {
1228 return asctime(localtime(timep));
1229 }
1230
1231 /*
1232 ** Adapted from code provided by Robert Elz, who writes:
1233 ** The "best" way to do mktime I think is based on an idea of Bob
1234 ** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now).
1235 ** It does a binary search of the time_t space. Since time_t's are
1236 ** just 32 bits, its a max of 32 iterations (even at 64 bits it
1237 ** would still be very reasonable).
1238 */
1239
1240 #ifndef WRONG
1241 #define WRONG (-1)
1242 #endif /* !defined WRONG */
1243
1244 static void
1245 normalize(int * CPP_CONST tensptr, int * CPP_CONST unitsptr, const int base)
1246 {
1247 if (*unitsptr >= base)
1248 {
1249 *tensptr += *unitsptr / base;
1250 *unitsptr %= base;
1251 }
1252 else if (*unitsptr < 0)
1253 {
1254 --*tensptr;
1255 *unitsptr += base;
1256 if (*unitsptr < 0)
1257 {
1258 *tensptr -= 1 + (-*unitsptr) / base;
1259 *unitsptr = base - (-*unitsptr) % base;
1260 }
1261 }
1262 }
1263
1264 static int
1265 tmcomp(const struct tm * CPP_CONST atmp, const struct tm * CPP_CONST btmp)
1266 {
1267 int result;
1268
1269 if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
1270 (result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
1271 (result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
1272 (result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
1273 (result = (atmp->tm_min - btmp->tm_min)) == 0)
1274 result = atmp->tm_sec - btmp->tm_sec;
1275 return result;
1276 }
1277
1278 static time_t
1279 time2(struct tm *tmp, void (*const funcp)(const time_t * CPP_CONST, const long, struct tm *), const long offset, int * CPP_CONST okayp)
1280 {
1281 const struct state * sp;
1282 int dir;
1283 int bits;
1284 int i, j ;
1285 int saved_seconds;
1286 time_t newt;
1287 time_t t;
1288
1289 /* GCC complaints that it may be used uninitialized */
1290 struct tm yourtm, mytm = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1291
1292 *okayp = FALSE;
1293 yourtm = *tmp;
1294 if (yourtm.tm_sec >= SECSPERMIN + 2 || yourtm.tm_sec < 0)
1295 normalize(&yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN);
1296 normalize(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR);
1297 normalize(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY);
1298 normalize(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR);
1299 while (yourtm.tm_mday <= 0)
1300 {
1301 --yourtm.tm_year;
1302 yourtm.tm_mday +=
1303 year_lengths[isleap(yourtm.tm_year + TM_YEAR_BASE)];
1304 }
1305 for ( ; ; )
1306 {
1307 i = mon_lengths[isleap(yourtm.tm_year +
1308 TM_YEAR_BASE)][yourtm.tm_mon];
1309 if (yourtm.tm_mday <= i)
1310 break;
1311 yourtm.tm_mday -= i;
1312 if (++yourtm.tm_mon >= MONSPERYEAR)
1313 {
1314 yourtm.tm_mon = 0;
1315 ++yourtm.tm_year;
1316 }
1317 }
1318 saved_seconds = yourtm.tm_sec;
1319 yourtm.tm_sec = 0;
1320 /*
1321 ** Calculate the number of magnitude bits in a time_t
1322 ** (this works regardless of whether time_t is
1323 ** signed or unsigned, though lint complains if unsigned).
1324 */
1325 for (bits = 0, t = 1; t > 0; ++bits, t <<= 1)
1326 ;
1327 /*
1328 ** If time_t is signed, then 0 is the median value,
1329 ** if time_t is unsigned, then 1 << bits is median.
1330 */
1331 #ifdef _MSVCRT_LIB_
1332 t = (time_t) ((1 << bits) - 1);
1333 #else // TODO: FIXME: review which is correct
1334 t = (time_t) 1 << bits;
1335 #endif /*_MSVCRT_LIB_*/
1336
1337 for ( ; ; )
1338 {
1339 (*funcp)(&t, offset, &mytm);
1340 dir = tmcomp(&mytm, &yourtm);
1341 if (dir != 0)
1342 {
1343 if (bits-- < 0)
1344 return WRONG;
1345 if (bits < 0)
1346 --t;
1347 else if (dir > 0)
1348 t -= (time_t) 1 << bits;
1349 else t += (time_t) 1 << bits;
1350 continue;
1351 }
1352 if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
1353 break;
1354 /*
1355 ** Right time, wrong type.
1356 ** Hunt for right time, right type.
1357 ** It's okay to guess wrong since the guess
1358 ** gets checked.
1359 */
1360 sp = (const struct state *)
1361 ((funcp == localsub) ? lclptr : gmtptr);
1362 #ifdef ALL_STATE
1363 if (sp == NULL)
1364 return WRONG;
1365 #endif /* defined ALL_STATE */
1366 for (i = 0; i < sp->typecnt; ++i)
1367 {
1368 if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
1369 continue;
1370 for (j = 0; j < sp->typecnt; ++j)
1371 {
1372 if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
1373 continue;
1374 newt = t + sp->ttis[j].tt_gmtoff -
1375 sp->ttis[i].tt_gmtoff;
1376 (*funcp)(&newt, offset, &mytm);
1377 if (tmcomp(&mytm, &yourtm) != 0)
1378 continue;
1379 if (mytm.tm_isdst != yourtm.tm_isdst)
1380 continue;
1381 /*
1382 ** We have a match.
1383 */
1384 t = newt;
1385 goto label;
1386 }
1387 }
1388 return WRONG;
1389 }
1390 label:
1391 t += saved_seconds;
1392 (*funcp)(&t, offset, tmp);
1393 *okayp = TRUE;
1394 return t;
1395 }
1396
1397 static time_t
1398 time1(struct tm * CPP_CONST tmp, void (*const funcp)(const time_t * CPP_CONST, const long, struct tm *), const long offset)
1399 {
1400 time_t t;
1401 const struct state * sp;
1402 int samei, otheri;
1403 int okay;
1404
1405 if (tmp->tm_isdst > 1)
1406 tmp->tm_isdst = 1;
1407 t = time2(tmp, funcp, offset, &okay);
1408 if (okay || tmp->tm_isdst < 0)
1409 return t;
1410 /*
1411 ** We're supposed to assume that somebody took a time of one type
1412 ** and did some math on it that yielded a "struct tm" that's bad.
1413 ** We try to divine the type they started from and adjust to the
1414 ** type they need.
1415 */
1416 sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr);
1417 #ifdef ALL_STATE
1418 if (sp == NULL)
1419 return WRONG;
1420 #endif /* defined ALL_STATE */
1421 for (samei = 0; samei < sp->typecnt; ++samei)
1422 {
1423 if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
1424 continue;
1425 for (otheri = 0; otheri < sp->typecnt; ++otheri)
1426 {
1427 if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
1428 continue;
1429 tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
1430 sp->ttis[samei].tt_gmtoff;
1431 tmp->tm_isdst = !tmp->tm_isdst;
1432 t = time2(tmp, funcp, offset, &okay);
1433 if (okay)
1434 return t;
1435 tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
1436 sp->ttis[samei].tt_gmtoff;
1437 tmp->tm_isdst = !tmp->tm_isdst;
1438 }
1439 }
1440 return WRONG;
1441 }
1442
1443 /*
1444 * @implemented
1445 */
1446 time_t
1447 mktime(struct tm * tmp)
1448 {
1449 return time1(tmp, localsub, 0L);
1450 }
1451
1452 /*
1453 * @implemented
1454 */
1455 char **
1456 __p__tzname(void)
1457 {
1458 return _tzname;
1459 }
1460
1461 /*********************************************************************
1462 * _dstbias (MSVCRT.@)
1463 */
1464 long _dstbias = 0;
1465
1466 /*********************************************************************
1467 * __p_dstbias (MSVCRT.@)
1468 */
1469 long * __p__dstbias(void)
1470 {
1471 return &_dstbias;
1472 }