summaryrefslogtreecommitdiffstats
path: root/toolchain/uClibc/uClibc-0.9.28-new_dst_rules.patch
blob: af1a23897dacc2190afa3541bbad0b3bd933e644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
--- uClibc/libc/misc/time/time.c	(revision 16488)
+++ uClibc/libc/misc/time/time.c	(working copy)
@@ -155,6 +155,20 @@
 #define TZNAME_MAX _POSIX_TZNAME_MAX
 #endif
 
+#if defined (L_tzset) || defined (L_localtime_r) || defined(L_strftime) || \
+    defined(L__time_mktime) || defined(L__time_mktime_tzi)
+
+void _time_tzset (int);
+
+#ifndef L__time_mktime
+
+ /* Jan 1, 2007 Z - tm = 0,0,0,1,0,107,1,0,0 */
+
+const static time_t new_rule_starts = 1167609600;
+
+#endif
+#endif
+
 /**********************************************************************/
 /* The era code is currently unfinished. */
 /*  #define ENABLE_ERA_CODE */
@@ -544,7 +558,7 @@
 {
 	TZLOCK;
 
-	tzset();
+	_time_tzset(*timer < new_rule_starts);
 
 	__time_localtime_tzi(timer, result, _time_tzinfo);
 
@@ -968,7 +982,8 @@
 	unsigned char mod;
 	unsigned char code;
 
-	tzset();					/* We'll, let's get this out of the way. */
+	/* We'll, let's get this out of the way. */
+	_time_tzset(_time_mktime((struct tm *) timeptr, 0) < new_rule_starts);
 
 	lvl = 0;
 	p = format;
@@ -1650,7 +1665,9 @@
 	6,  0,  0,					/* Note: overloaded for non-M non-J case... */
 	0, 1, 0,					/* J */
 	',', 'M',      '4', '.', '1', '.', '0',
-	',', 'M', '1', '0', '.', '5', '.', '0', 0
+	',', 'M', '1', '0', '.', '5', '.', '0', 0,
+	',', 'M',      '3', '.', '2', '.', '0',
+	',', 'M', '1', '1', '.', '1', '.', '0', 0
 };
 
 #define TZ    vals
@@ -1658,6 +1675,7 @@
 #define RANGE (vals + 7)
 #define RULE  (vals + 11 - 1)
 #define DEFAULT_RULES (vals + 22)
+#define DEFAULT_2007_RULES (vals + 38)
 
 /* Initialize to UTC. */
 int daylight = 0;
@@ -1782,6 +1800,11 @@
 
 void tzset(void)
 {
+    _time_tzset((time(NULL)) < new_rule_starts);
+}
+
+void _time_tzset(int use_old_rules)
+{
 	register const char *e;
 	register char *s;
 	long off;
@@ -1904,7 +1927,15 @@
 	} else {					/* OK, we have dst, so get some rules. */
 		count = 0;
 		if (!*e) {				/* No rules so default to US rules. */
-			e = DEFAULT_RULES;
+		        e = use_old_rules ? DEFAULT_RULES : DEFAULT_2007_RULES;
+#ifdef DEBUG_TZSET			
+			if (e == DEFAULT_RULES)
+			    printf("tzset: Using old rules.\n");
+			else if (e == DEFAULT_2007_RULES)
+			    printf("tzset: Using new rules\n");
+			else
+			    printf("tzset: Using undefined rules\n");
+#endif /* DEBUG_TZSET */
 		}
 
 		do {
@@ -2238,6 +2269,8 @@
 		--d;
 	}
 
+	_time_tzset (x.tm_year < 2007);	/* tm_year was expanded above */
+
 #ifdef __BCC__
 	d = p[5] - 1;
 	days = -719163L + ((long)d)*365 + ((d/4) - (d/100) + (d/400) + p[3] + p[7]);