1 --- localtime.c.orig 2007-05-23 18:18:18.000000000 -0700
2 +++ localtime.c 2007-05-23 18:20:52.000000000 -0700
12 +//#define NOTIFY_TZ_DEBUG
13 +//#define NOTIFY_TZ_DEBUG_FILE "/var/log/localtime.debug"
14 +//#define NOTIFY_TZ_LOG "/var/log/localtime.log"
15 +/* force ALL_STATE if NOTIFY_TZ is set */
18 +#endif /* ALL_STATE */
19 +#include <mach/mach_init.h>
22 +#endif /* NOTIFY_TZ */
24 #include "un-namespace.h"
28 #define _MUTEX_LOCK(x) if (__isthreaded) _pthread_mutex_lock(x)
29 #define _MUTEX_UNLOCK(x) if (__isthreaded) _pthread_mutex_unlock(x)
30 +extern int __pthread_tsd_first;
33 ** SunOS 4.1.1 headers lack O_BINARY.
35 #define DAY_OF_YEAR 1 /* n - day of year */
36 #define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
45 +#define NOTIFY_TZ_NAME "com.apple.system.timezone"
46 +#endif /* NOTIFY_TZ */
49 ** Prototypes for static functions.
51 +#define localsub _st_localsub
52 +#define time1 _st_time1
53 +#define tzset_basic _st_tzset_basic
56 +struct tm * localsub(const time_t * timep, long offset,
58 +#else /* !__LP64__ */
59 +void localsub(const time_t * timep, long offset,
61 +#endif /* __LP64__ */
63 +time_t time1(struct tm * tmp,
65 + struct tm *(*funcp) (const time_t *,
67 +#else /* !__LP64__ */
68 + void(*funcp) (const time_t *,
70 +#endif /* __LP64__ */
74 +void tzset_basic(void);
76 +#define lcl_mutex _st_lcl_mutex
78 +#if !BUILDING_VARIANT
79 static long detzcode(const char * codep);
80 -static const char * getzname(const char * strp);
81 +static const char * getzname(const char * strp, char **name, size_t *len);
82 static const char * getnum(const char * strp, int * nump, int min,
84 static const char * getsecs(const char * strp, long * secsp);
85 static const char * getoffset(const char * strp, long * offsetp);
86 static const char * getrule(const char * strp, struct rule * rulep);
87 static void gmtload(struct state * sp);
88 -static void gmtsub(const time_t * timep, long offset,
90 +static struct tm * gmtsub(const time_t * timep, long offset,
92 -static void localsub(const time_t * timep, long offset,
93 +#else /* !__LP64__ */
94 +static void gmtsub(const time_t * timep, long offset,
96 +#endif /* __LP64__ */
97 static int increment_overflow(int * number, int delta);
98 static int normalize_overflow(int * tensptr, int * unitsptr,
101 +static void notify_check_tz(notify_tz_t *p);
102 +static void notify_register_tz(char *file, notify_tz_t *p);
103 +#endif /* NOTIFY_TZ */
104 static void settzname(void);
105 -static time_t time1(struct tm * tmp,
106 - void(*funcp) (const time_t *,
107 - long, struct tm *),
109 static time_t time2(struct tm *tmp,
111 + struct tm *(*funcp) (const time_t *,
113 +#else /* !__LP64__ */
114 void(*funcp) (const time_t *,
116 - long offset, int * okayp);
117 +#endif /* __LP64__ */
118 + long offset, int * okayp, int unix03);
119 static time_t time2sub(struct tm *tmp,
121 + struct tm *(*funcp) (const time_t *,
123 +#else /* !__LP64__ */
124 void(*funcp) (const time_t *,
126 - long offset, int * okayp, int do_norm_secs);
127 +#endif /* __LP64__ */
128 + long offset, int * okayp, int do_norm_secs,
131 +static struct tm * timesub(const time_t * timep, long offset,
132 + const struct state * sp, struct tm * tmp);
133 +#else /* !__LP64__ */
134 static void timesub(const time_t * timep, long offset,
135 const struct state * sp, struct tm * tmp);
136 +#endif /* __LP64__ */
137 static int tmcomp(const struct tm * atmp,
138 const struct tm * btmp);
139 static time_t transtime(time_t janfirst, int year,
140 @@ -194,10 +265,15 @@
141 #endif /* !defined TZ_STRLEN_MAX */
143 static char lcl_TZname[TZ_STRLEN_MAX + 1];
145 +#define lcl_is_set (lcl_notify.is_set)
146 +#define gmt_is_set (gmt_notify.is_set)
147 +#else /* ! NOTIFY_TZ */
148 static int lcl_is_set;
149 static int gmt_is_set;
150 -static pthread_mutex_t lcl_mutex = PTHREAD_MUTEX_INITIALIZER;
151 -static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER;
152 +#endif /* NOTIFY_TZ */
153 +__private_extern__ pthread_mutex_t lcl_mutex = PTHREAD_MUTEX_INITIALIZER;
154 +static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER;
158 @@ -214,15 +290,62 @@
165 -time_t timezone = 0;
167 +__private_extern__ void _st_set_timezone(long);
168 #endif /* defined USG_COMPAT */
172 +__private_extern__ long __darwin_altzone = 0;
173 +#define altzone __darwin_altzone
174 #endif /* defined ALTZONE */
177 +#ifdef NOTIFY_TZ_DEBUG
178 +#ifdef NOTIFY_TZ_DEBUG_FILE
179 +#define NOTIFY_TZ_PRINTF(fmt, args...) \
181 + FILE *_notify_tz_fp_; \
182 + if((_notify_tz_fp_ = fopen(NOTIFY_TZ_DEBUG_FILE, "a")) != NULL) { \
183 + fprintf(_notify_tz_fp_, "%d: " fmt, getpid(), ## args); \
184 + fclose(_notify_tz_fp_); \
187 +#else /* ! NOTIFY_TZ_DEBUG_FILE */
188 +#define NOTIFY_TZ_PRINTF(args...) fprintf(stdout, ## args)
189 +#endif /* NOTIFY_TZ_DEBUG_FILE */
190 +#endif /* NOTIFY_TZ_DEBUG */
191 +#ifdef NOTIFY_TZ_LOG
192 +#define NOTIFY_LOG(fmt, args...) \
194 + FILE *_notify_log_fp_; \
195 + if((_notify_log_fp_ = fopen(NOTIFY_TZ_LOG, "a")) != NULL) { \
196 + fprintf(_notify_log_fp_, "%d: " fmt, getpid(), ## args); \
197 + fclose(_notify_log_fp_); \
200 +#endif /* NOTIFY_TZ_LOG */
201 +/*--------------------------------------------------------------------
202 + * __notify_78945668_info__ is a global variable (defined in Libnotify)
203 + * that can be used to disable the notify mechanism. Set to a negative
204 + * value to disable. It can then be set back to zero to re-enable.
205 + *-------------------------------------------------------------------- */
206 +extern int __notify_78945668_info__;
208 +/*--------------------------------------------------------------------
209 + * fullname is used to pass the actual path of the timezone file to the
210 + * notify routines. If it is a nil string, that means no timezone file
212 + *-------------------------------------------------------------------- */
213 +static char * fullname = NULL;
215 +static notify_tz_t gmt_notify = {-1, 0, 0};
216 +static notify_tz_t lcl_notify = {-1, 0, 0};
217 +static char notify_tz_name[] = NOTIFY_TZ_NAME;
218 +#endif /* NOTIFY_TZ */
222 const char * const codep;
223 @@ -246,14 +369,14 @@
224 tzname[1] = wildabbr;
228 + _st_set_timezone(0);
229 #endif /* defined USG_COMPAT */
232 #endif /* defined ALTZONE */
235 - tzname[0] = tzname[1] = gmt;
236 + tzname[0] = tzname[1] = (char *)gmt;
239 #endif /* defined ALL_STATE */
243 if (i == 0 || !ttisp->tt_isdst)
244 - timezone = -(ttisp->tt_gmtoff);
245 + _st_set_timezone(-(ttisp->tt_gmtoff));
246 #endif /* defined USG_COMPAT */
248 if (i == 0 || ttisp->tt_isdst)
249 @@ -286,6 +409,119 @@
255 +notify_check_tz(notify_tz_t *p)
257 + unsigned int nstat;
260 + if (__notify_78945668_info__ < 0) {
261 +#ifdef NOTIFY_TZ_DEBUG
262 + if(!p->notify_was_off) NOTIFY_TZ_PRINTF("notify_check_tz: setting %s_notify->notify_was_off\n", (p == &lcl_notify ? "lcl" : "gmt"));
263 +#endif /* NOTIFY_TZ_DEBUG */
264 + p->notify_was_off = 1;
267 + /* force rereading the timezone file if notify was off */
268 + if (p->notify_was_off) {
269 +#ifdef NOTIFY_TZ_DEBUG
270 + NOTIFY_TZ_PRINTF("notify_check_tz: saw %s_notify->notify_was_off\n", (p == &lcl_notify ? "lcl" : "gmt"));
271 +#endif /* NOTIFY_TZ_DEBUG */
273 + p->notify_was_off = 0;
278 + nstat = notify_check(p->token, &ncheck);
279 + if (nstat || ncheck) {
281 +#ifdef NOTIFY_TZ_DEBUG
282 + NOTIFY_TZ_PRINTF("notify_check_tz: %s changed\n", (p == &lcl_notify) ? "lcl" : "gmt");
283 +#endif /* NOTIFY_TZ_DEBUG */
285 +#ifdef NOTIFY_TZ_DEBUG
286 + NOTIFY_TZ_PRINTF("notify_check_tz: %s unchanged\n", (p == &lcl_notify) ? "lcl" : "gmt");
287 +#endif /* NOTIFY_TZ_DEBUG */
290 +extern uint32_t notify_monitor_file(int token, char *path, int flags);
293 +notify_register_tz(char *file, notify_tz_t *p)
296 + unsigned int nstat;
299 + if (__notify_78945668_info__ < 0)
301 + /*----------------------------------------------------------------
302 + * Since we don't record the last time zone filename, just cancel
303 + * (which should remove the file monitor) and setup from scratch
304 + *----------------------------------------------------------------*/
306 + notify_cancel(p->token);
307 + if (!file || *file == 0) {
308 + /* no time zone file to monitor */
312 + /*----------------------------------------------------------------
313 + * Just use com.apple.system.timezone if the path is /etc/localtime.
314 + * Otherwise use com.apple.system.timezone.<fullpath>
315 + *----------------------------------------------------------------*/
316 + if (TZDEFAULT && strcmp(file, TZDEFAULT) == 0)
317 + name = notify_tz_name;
319 + name = alloca(sizeof(notify_tz_name) + strlen(file) + 1);
320 + if (name == NULL) {
324 + strcpy(name, notify_tz_name);
326 + strcat(name, file);
328 +#ifdef NOTIFY_TZ_DEBUG
329 + NOTIFY_TZ_PRINTF("notify_register_tz: file=%s name=%s\n", file, name);
330 +#endif /* NOTIFY_TZ_DEBUG */
331 + nstat = notify_register_check(name, &p->token);
335 +#ifdef NOTIFY_TZ_DEBUG
336 + NOTIFY_TZ_PRINTF("***notify_register_tz: notify_register_check failed: %u\n", nstat);
337 +#endif /* NOTIFY_TZ_DEBUG */
338 +#ifdef NOTIFY_TZ_LOG
339 + NOTIFY_LOG("notify_register_check(%s) failed: %u\n", name, nstat);
340 +#endif /* NOTIFY_TZ_LOG */
343 + /* don't need to request monitoring /etc/localtime */
344 + if (name != notify_tz_name) {
345 +#ifdef NOTIFY_TZ_DEBUG
346 + NOTIFY_TZ_PRINTF("notify_register_tz: monitor %s\n", file);
347 +#endif /* NOTIFY_TZ_DEBUG */
348 + nstat = notify_monitor_file(p->token, file, 0);
350 + notify_cancel(p->token);
353 +#ifdef NOTIFY_TZ_DEBUG
354 + NOTIFY_TZ_PRINTF("***notify_register_tz: notify_monitor_file failed: %u\n", nstat);
355 +#endif /* NOTIFY_TZ_DEBUG */
356 +#ifdef NOTIFY_TZ_LOG
357 + NOTIFY_LOG("notify_monitor_file(%s) failed: %u\n", file, nstat);
358 +#endif /* NOTIFY_TZ_LOG */
362 + notify_check(p->token, &ncheck); /* this always returns true */
364 +#endif /* NOTIFY_TZ */
373 +#ifdef NOTIFY_TZ_DEBUG
374 + NOTIFY_TZ_PRINTF("tzload: name=%s\n", name);
375 +#endif /* NOTIFY_TZ_DEBUG */
376 /* XXX The following is from OpenBSD, and I'm not sure it is correct */
377 if (name != NULL && issetugid() != 0)
378 if ((name[0] == ':' && name[1] == '/') ||
380 ** to hold the longest file name string that the implementation
381 ** guarantees can be opened."
385 + fullname = malloc(FILENAME_MAX + 1);
389 +#else /* ! NOTIFY_TZ */
390 char fullname[FILENAME_MAX + 1];
391 +#endif /* NOTIFY_TZ */
397 if ((p = TZDIR) == NULL)
400 + if ((strlen(p) + 1 + strlen(name) + 1) >= (FILENAME_MAX + 1))
401 +#else /* ! NOTIFY_TZ */
402 if ((strlen(p) + 1 + strlen(name) + 1) >= sizeof fullname)
403 +#endif /* NOTIFY_TZ */
405 (void) strcpy(fullname, p);
406 (void) strcat(fullname, "/");
413 + strcpy(fullname, name);
414 +#endif /* NOTIFY_TZ */
415 if (doaccess && access(name, R_OK) != 0)
417 if ((fid = _open(name, OPEN_MODE)) == -1)
422 +#ifdef NOTIFY_TZ_DEBUG
423 + NOTIFY_TZ_PRINTF("tzload: reading %s\n", name);
424 +#endif /* NOTIFY_TZ_DEBUG */
425 i = _read(fid, u.buf, sizeof u.buf);
426 if (_close(fid) != 0)
428 @@ -456,14 +714,24 @@
433 +getzname(strp, name, len)
441 + if (*strp == '<' && (ket = strchr(strp, '>')) != NULL) {
442 + *name = (char *)(strp + 1);
443 + *len = ket - strp - 1;
446 + *name = (char *)strp;
447 while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&
450 + *len = strp - *name;
454 @@ -743,16 +1011,15 @@
461 stdlen = strlen(name); /* length of standard zone name */
463 if (stdlen >= sizeof sp->chars)
464 stdlen = (sizeof sp->chars) - 1;
467 - name = getzname(name);
468 - stdlen = name - stdname;
469 + name = getzname(name, (char **)&stdname, &stdlen);
473 @@ -764,12 +1031,14 @@
476 load_result = tzload(TZDEFRULES, sp);
478 + *fullname = 0; /* mark fullname as invalid */
479 +#endif /* NOTIFY_TZ */
480 if (load_result != 0)
481 sp->leapcnt = 0; /* so, we're off a little */
484 - name = getzname(name);
485 - dstlen = name - dstname; /* length of DST zone name */
486 + name = getzname(name, (char **)&dstname, &dstlen);
489 if (*name != '\0' && *name != ',' && *name != ';') {
490 @@ -951,8 +1220,19 @@
492 tzsetwall_basic(void)
495 + notify_check_tz(&lcl_notify);
496 +#endif /* NOTIFY_TZ */
497 +#ifdef NOTIFY_TZ_DEBUG
498 + if (lcl_is_set < 0) {
499 + NOTIFY_TZ_PRINTF("tzsetwall_basic lcl_is_set < 0\n");
502 + NOTIFY_TZ_PRINTF("tzsetwall_basic not set\n");
503 +#else /* ! NOTIFY_TZ_DEBUG */
506 +#endif /* NOTIFY_TZ_DEBUG */
510 @@ -966,18 +1246,24 @@
511 #endif /* defined ALL_STATE */
512 if (tzload((char *) NULL, lclptr) != 0)
515 + notify_register_tz(fullname, &lcl_notify);
516 +#endif /* NOTIFY_TZ */
523 +#ifdef NOTIFY_TZ_DEBUG
524 + NOTIFY_TZ_PRINTF("tzsetwall called\n");
525 +#endif /* NOTIFY_TZ_DEBUG */
526 _MUTEX_LOCK(&lcl_mutex);
528 _MUTEX_UNLOCK(&lcl_mutex);
532 +__private_extern__ void
536 @@ -988,8 +1274,18 @@
541 + notify_check_tz(&lcl_notify);
542 +#endif /* NOTIFY_TZ */
543 +#ifdef NOTIFY_TZ_DEBUG
544 + if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0) {
545 + NOTIFY_TZ_PRINTF("tzset_basic matched %s\n", lcl_TZname);
548 +#else /* ! NOTIFY_TZ_DEBUG */
549 if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
551 +#endif /* NOTIFY_TZ_DEBUG */
552 lcl_is_set = strlen(name) < sizeof lcl_TZname;
554 (void) strcpy(lcl_TZname, name);
555 @@ -1014,15 +1310,25 @@
556 lclptr->ttis[0].tt_gmtoff = 0;
557 lclptr->ttis[0].tt_abbrind = 0;
558 (void) strcpy(lclptr->chars, gmt);
562 +#endif /* NOTIFY_TZ */
563 } else if (tzload(name, lclptr) != 0)
564 if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
565 (void) gmtload(lclptr);
567 + notify_register_tz(fullname, &lcl_notify);
568 +#endif /* NOTIFY_TZ */
575 +#ifdef NOTIFY_TZ_DEBUG
576 + NOTIFY_TZ_PRINTF("tzset called TZ=%s\n", getenv("TZ"));
577 +#endif /* NOTIFY_TZ_DEBUG */
578 _MUTEX_LOCK(&lcl_mutex);
580 _MUTEX_UNLOCK(&lcl_mutex);
581 @@ -1038,7 +1344,11 @@
587 +__private_extern__ struct tm *
588 +#else /* !__LP64__ */
589 +__private_extern__ void
590 +#endif /* __LP64__ */
591 localsub(timep, offset, tmp)
592 const time_t * const timep;
594 @@ -1049,11 +1359,18 @@
596 const time_t t = *timep;
598 +#ifdef NOTIFY_TZ_DEBUG
599 + NOTIFY_TZ_PRINTF("localsub called\n");
600 +#endif /* NOTIFY_TZ_DEBUG */
605 + return gmtsub(timep, offset, tmp);
606 +#else /* !__LP64__ */
607 gmtsub(timep, offset, tmp);
609 +#endif /* __LP64__ */
611 #endif /* defined ALL_STATE */
612 if (sp->timecnt == 0 || t < sp->ats[0]) {
613 @@ -1076,12 +1393,20 @@
614 ** t += ttisp->tt_gmtoff;
615 ** timesub(&t, 0L, sp, tmp);
618 + if (timesub(&t, ttisp->tt_gmtoff, sp, tmp) == NULL)
620 +#else /* !__LP64__ */
621 timesub(&t, ttisp->tt_gmtoff, sp, tmp);
622 +#endif /* __LP64__ */
623 tmp->tm_isdst = ttisp->tt_isdst;
624 tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
626 tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
627 #endif /* defined TM_ZONE */
630 +#endif /* __LP64__ */
634 @@ -1094,8 +1419,9 @@
636 if (__isthreaded != 0) {
637 _pthread_mutex_lock(&localtime_mutex);
638 - if (localtime_key < 0) {
639 - if (_pthread_key_create(&localtime_key, free) < 0) {
640 + if (localtime_key == (pthread_key_t)-1) {
641 + localtime_key = __pthread_tsd_first + 2;
642 + if (pthread_key_init_np(localtime_key, free) < 0) {
643 _pthread_mutex_unlock(&localtime_mutex);
646 @@ -1110,13 +1436,21 @@
648 _pthread_mutex_lock(&lcl_mutex);
651 + p_tm = localsub(timep, 0L, p_tm);
652 +#else /* !__LP64__ */
653 localsub(timep, 0L, p_tm);
654 +#endif /* __LP64__ */
655 _pthread_mutex_unlock(&lcl_mutex);
660 + return localsub(timep, 0L, &tm);
661 +#else /* !__LP64__ */
662 localsub(timep, 0L, &tm);
664 +#endif /* __LP64__ */
668 @@ -1125,13 +1459,15 @@
672 -localtime_r(timep, tm)
673 -const time_t * const timep;
675 +localtime_r(const time_t * const __restrict timep, struct tm * __restrict tm)
677 _MUTEX_LOCK(&lcl_mutex);
680 + tm = localsub(timep, 0L, tm);
681 +#else /* !__LP64__ */
682 localsub(timep, 0L, tm);
683 +#endif /* __LP64__ */
684 _MUTEX_UNLOCK(&lcl_mutex);
687 @@ -1140,23 +1476,48 @@
688 ** gmtsub is to gmtime as localsub is to localtime.
693 +#else /* !__LP64__ */
695 +#endif /* __LP64__ */
696 gmtsub(timep, offset, tmp)
697 const time_t * const timep;
699 struct tm * const tmp;
701 +#ifdef NOTIFY_TZ_DEBUG
702 + NOTIFY_TZ_PRINTF("gmtsub called\n");
703 +#endif /* NOTIFY_TZ_DEBUG */
704 _MUTEX_LOCK(&gmt_mutex);
706 + notify_check_tz(&gmt_notify);
707 +#endif /* NOTIFY_TZ */
711 - gmtptr = (struct state *) malloc(sizeof *gmtptr);
713 + if (gmtptr == NULL)
714 +#endif /* NOTIFY_TZ */
715 + gmtptr = (struct state *) malloc(sizeof *gmtptr);
719 +#endif /* NOTIFY_TZ */
720 #endif /* defined ALL_STATE */
723 + notify_register_tz(fullname, &gmt_notify);
725 +#endif /* NOTIFY_TZ */
727 _MUTEX_UNLOCK(&gmt_mutex);
729 + if(timesub(timep, offset, gmtptr, tmp) == NULL)
731 +#else /* !__LP64__ */
732 timesub(timep, offset, gmtptr, tmp);
733 +#endif /* __LP64__ */
736 ** Could get fancy here and deliver something such as
737 @@ -1168,7 +1529,7 @@
741 - tmp->TM_ZONE = gmt;
742 + tmp->TM_ZONE = (char *)gmt;
743 else tmp->TM_ZONE = gmtptr->chars;
744 #endif /* defined ALL_STATE */
746 @@ -1176,6 +1537,9 @@
747 #endif /* State Farm */
749 #endif /* defined TM_ZONE */
752 +#endif /* __LP64__ */
756 @@ -1186,10 +1550,12 @@
757 static pthread_key_t gmtime_key = -1;
761 if (__isthreaded != 0) {
762 _pthread_mutex_lock(&gmtime_mutex);
763 - if (gmtime_key < 0) {
764 - if (_pthread_key_create(&gmtime_key, free) < 0) {
765 + if (gmtime_key == (pthread_key_t)-1) {
766 + gmtime_key = __pthread_tsd_first + 3;
767 + if (pthread_key_init_np(gmtime_key, free) < 0) {
768 _pthread_mutex_unlock(&gmtime_mutex);
771 @@ -1206,12 +1572,20 @@
773 _pthread_setspecific(gmtime_key, p_tm);
776 + return gmtsub(timep, 0L, p_tm);
777 +#else /* !__LP64__ */
778 gmtsub(timep, 0L, p_tm);
780 +#endif /* __LP64__ */
784 + return gmtsub(timep, 0L, &tm);
785 +#else /* !__LP64__ */
786 gmtsub(timep, 0L, &tm);
788 +#endif /* __LP64__ */
792 @@ -1224,8 +1598,13 @@
793 const time_t * const timep;
798 + return gmtsub(timep, 0L, tm);
799 +#else /* !__LP64__ */
800 gmtsub(timep, 0L, tm);
802 +#endif /* __LP64__ */
806 @@ -1235,13 +1614,21 @@
807 const time_t * const timep;
811 + return gmtsub(timep, offset, &tm);
812 +#else /* !__LP64__ */
813 gmtsub(timep, offset, &tm);
815 +#endif /* __LP64__ */
818 #endif /* defined STD_INSPIRED */
822 +#else /* !__LP64__ */
824 +#endif /* __LP64__ */
825 timesub(timep, offset, sp, tmp)
826 const time_t * const timep;
828 @@ -1330,7 +1717,16 @@
829 LEAPS_THRU_END_OF(y - 1);
834 + if (y < INT_MIN || y > INT_MAX) {
839 +#else /* !__LP64__ */
840 tmp->tm_year = y - TM_YEAR_BASE;
841 +#endif /* __LP64__ */
842 tmp->tm_yday = (int) days;
843 ip = mon_lengths[yleap];
844 for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon))
845 @@ -1340,6 +1736,9 @@
847 tmp->TM_GMTOFF = offset;
848 #endif /* defined TM_GMTOFF */
851 +#endif /* __LP64__ */
855 @@ -1427,12 +1826,17 @@
859 -time2sub(tmp, funcp, offset, okayp, do_norm_secs)
860 +time2sub(tmp, funcp, offset, okayp, do_norm_secs, unix03)
861 struct tm * const tmp;
863 +struct tm *(* const funcp)(const time_t*, long, struct tm*);
864 +#else /* !__LP64__ */
865 void (* const funcp)(const time_t*, long, struct tm*);
866 +#endif /* __LP64__ */
869 const int do_norm_secs;
872 const struct state * sp;
874 @@ -1442,6 +1846,9 @@
877 struct tm yourtm, mytm;
880 +#endif /* __LP64__ */
884 @@ -1460,33 +1867,64 @@
885 ** Turn yourtm.tm_year into an actual year number for now.
886 ** It is converted back to an offset from TM_YEAR_BASE later.
889 + year = (long)yourtm.tm_year + TM_YEAR_BASE;
890 +#else /* !__LP64__ */
891 if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE))
893 +#endif /* __LP64__ */
894 while (yourtm.tm_mday <= 0) {
897 + il = year + (1 < yourtm.tm_mon);
898 + yourtm.tm_mday += year_lengths[isleap(il)];
899 +#else /* !__LP64__ */
900 if (increment_overflow(&yourtm.tm_year, -1))
902 i = yourtm.tm_year + (1 < yourtm.tm_mon);
903 yourtm.tm_mday += year_lengths[isleap(i)];
904 +#endif /* __LP64__ */
906 while (yourtm.tm_mday > DAYSPERLYEAR) {
908 + il = year + (1 < yourtm.tm_mon);
909 + yourtm.tm_mday -= year_lengths[isleap(il)];
911 +#else /* !__LP64__ */
912 i = yourtm.tm_year + (1 < yourtm.tm_mon);
913 yourtm.tm_mday -= year_lengths[isleap(i)];
914 if (increment_overflow(&yourtm.tm_year, 1))
916 +#endif /* __LP64__ */
920 + i = mon_lengths[isleap(year)][yourtm.tm_mon];
921 +#else /* !__LP64__ */
922 i = mon_lengths[isleap(yourtm.tm_year)][yourtm.tm_mon];
923 +#endif /* __LP64__ */
924 if (yourtm.tm_mday <= i)
927 if (++yourtm.tm_mon >= MONSPERYEAR) {
931 +#else /* !__LP64__ */
932 if (increment_overflow(&yourtm.tm_year, 1))
934 +#endif /* __LP64__ */
938 + year -= TM_YEAR_BASE;
939 + if (year > INT_MAX || year < INT_MIN)
941 + yourtm.tm_year = year;
942 +#else /* !__LP64__ */
943 if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE))
945 +#endif /* __LP64__ */
946 /* Don't go below 1900 for POLA */
947 if (yourtm.tm_year < 0)
949 @@ -1527,8 +1965,19 @@
951 t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits);
954 + if ((*funcp)(&t, offset, &mytm) == NULL) {
955 + /* we overflowed, so t is too big */
959 +#else /* !__LP64__ */
960 (*funcp)(&t, offset, &mytm);
961 +#endif /* __LP64__ */
962 dir = tmcomp(&mytm, &yourtm);
965 +#endif /* __LP64__ */
969 @@ -1539,6 +1988,9 @@
970 else t += ((time_t) 1) << bits;
973 + sp = (funcp == localsub) ? lclptr : gmtptr;
974 + if (unix03 && sp->typecnt == 1 && yourtm.tm_isdst > 0)
975 + yourtm.tm_isdst = 0; /* alternative time does not apply */
976 if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
979 @@ -1547,7 +1999,6 @@
980 ** It's okay to guess wrong since the guess
983 - sp = (funcp == localsub) ? lclptr : gmtptr;
987 @@ -1560,7 +2011,12 @@
989 newt = t + sp->ttis[j].tt_gmtoff -
990 sp->ttis[i].tt_gmtoff;
992 + if ((*funcp)(&newt, offset, &mytm) == NULL)
994 +#else /* !__LP64__ */
995 (*funcp)(&newt, offset, &mytm);
996 +#endif /* __LP64__ */
997 if (tmcomp(&mytm, &yourtm) != 0)
999 if (mytm.tm_isdst != yourtm.tm_isdst)
1000 @@ -1579,17 +2035,27 @@
1001 if ((newt < t) != (saved_seconds < 0))
1005 + if ((*funcp)(&t, offset, tmp) == NULL)
1007 +#else /* !__LP64__ */
1008 (*funcp)(&t, offset, tmp);
1009 +#endif /* __LP64__ */
1015 -time2(tmp, funcp, offset, okayp)
1016 +time2(tmp, funcp, offset, okayp, unix03)
1017 struct tm * const tmp;
1019 +struct tm *(* const funcp)(const time_t*, long, struct tm*);
1020 +#else /* !__LP64__ */
1021 void (* const funcp)(const time_t*, long, struct tm*);
1022 +#endif /* __LP64__ */
1029 @@ -1598,15 +2064,20 @@
1030 ** (in case tm_sec contains a value associated with a leap second).
1031 ** If that fails, try with normalization of seconds.
1033 - t = time2sub(tmp, funcp, offset, okayp, FALSE);
1034 - return *okayp ? t : time2sub(tmp, funcp, offset, okayp, TRUE);
1035 + t = time2sub(tmp, funcp, offset, okayp, FALSE, unix03);
1036 + return *okayp ? t : time2sub(tmp, funcp, offset, okayp, TRUE, unix03);
1040 -time1(tmp, funcp, offset)
1041 +__private_extern__ time_t
1042 +time1(tmp, funcp, offset, unix03)
1043 struct tm * const tmp;
1045 +struct tm *(* const funcp)(const time_t *, long, struct tm *);
1046 +#else /* !__LP64__ */
1047 void (* const funcp)(const time_t *, long, struct tm *);
1048 +#endif /* __LP64__ */
1053 const struct state * sp;
1054 @@ -1620,7 +2091,7 @@
1056 if (tmp->tm_isdst > 1)
1058 - t = time2(tmp, funcp, offset, &okay);
1059 + t = time2(tmp, funcp, offset, &okay, unix03);
1062 ** PCTS code courtesy Grant Sullivan (grant@osf.org).
1063 @@ -1664,7 +2135,7 @@
1064 tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
1065 sp->ttis[samei].tt_gmtoff;
1066 tmp->tm_isdst = !tmp->tm_isdst;
1067 - t = time2(tmp, funcp, offset, &okay);
1068 + t = time2(tmp, funcp, offset, &okay, unix03);
1071 tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
1072 @@ -1674,19 +2145,25 @@
1076 +#else /* BUILDING_VARIANT */
1077 +__private_extern__ pthread_mutex_t lcl_mutex;
1078 +#endif /* BUILDING_VARIANT */
1082 struct tm * const tmp;
1084 time_t mktime_return_value;
1085 + int serrno = errno;
1086 _MUTEX_LOCK(&lcl_mutex);
1088 - mktime_return_value = time1(tmp, localsub, 0L);
1089 + mktime_return_value = time1(tmp, localsub, 0L, __DARWIN_UNIX03);
1090 _MUTEX_UNLOCK(&lcl_mutex);
1092 return(mktime_return_value);
1095 +#if !BUILDING_VARIANT
1099 @@ -1702,7 +2179,7 @@
1100 struct tm * const tmp;
1103 - return time1(tmp, gmtsub, 0L);
1104 + return time1(tmp, gmtsub, 0L, __DARWIN_UNIX03);
1108 @@ -1711,7 +2188,7 @@
1112 - return time1(tmp, gmtsub, offset);
1113 + return time1(tmp, gmtsub, offset, __DARWIN_UNIX03);
1116 #endif /* defined STD_INSPIRED */
1117 @@ -1811,3 +2288,4 @@
1120 #endif /* defined STD_INSPIRED */
1121 +#endif /* !BUILDING_VARIANT */