@@ -77,20 +77,20 @@ static void read_header(const unsigned char **tzf, timelib_tzinfo *tz)
77
77
uint32_t buffer [6 ];
78
78
79
79
memcpy (& buffer , * tzf , sizeof (buffer ));
80
- tz -> ttisgmtcnt = timelib_conv_int (buffer [0 ]);
81
- tz -> ttisstdcnt = timelib_conv_int (buffer [1 ]);
82
- tz -> leapcnt = timelib_conv_int (buffer [2 ]);
83
- tz -> timecnt = timelib_conv_int (buffer [3 ]);
84
- tz -> typecnt = timelib_conv_int (buffer [4 ]);
85
- tz -> charcnt = timelib_conv_int (buffer [5 ]);
80
+ tz -> bit32 . ttisgmtcnt = timelib_conv_int (buffer [0 ]);
81
+ tz -> bit32 . ttisstdcnt = timelib_conv_int (buffer [1 ]);
82
+ tz -> bit32 . leapcnt = timelib_conv_int (buffer [2 ]);
83
+ tz -> bit32 . timecnt = timelib_conv_int (buffer [3 ]);
84
+ tz -> bit32 . typecnt = timelib_conv_int (buffer [4 ]);
85
+ tz -> bit32 . charcnt = timelib_conv_int (buffer [5 ]);
86
86
* tzf += sizeof (buffer );
87
87
}
88
88
89
- static void skip_transistions_64bit (const unsigned char * * tzf , timelib_tzinfo * tz )
89
+ static void skip_64bit_transistions (const unsigned char * * tzf , timelib_tzinfo * tz )
90
90
{
91
- if (tz -> timecnt ) {
92
- * tzf += (sizeof (int64_t ) * ( tz -> timecnt + 1 ) );
93
- * tzf += (sizeof (unsigned char ) * ( tz -> timecnt + 1 ) );
91
+ if (tz -> bit64 . timecnt ) {
92
+ * tzf += (sizeof (int64_t ) * tz -> bit64 . timecnt );
93
+ * tzf += (sizeof (unsigned char ) * tz -> bit64 . timecnt );
94
94
}
95
95
}
96
96
@@ -100,42 +100,42 @@ static void read_transistions(const unsigned char **tzf, timelib_tzinfo *tz)
100
100
uint32_t i ;
101
101
unsigned char * cbuffer = NULL ;
102
102
103
- if (tz -> timecnt ) {
104
- buffer = (int32_t * ) malloc (tz -> timecnt * sizeof (int32_t ));
103
+ if (tz -> bit32 . timecnt ) {
104
+ buffer = (int32_t * ) malloc (tz -> bit32 . timecnt * sizeof (int32_t ));
105
105
if (!buffer ) {
106
106
return ;
107
107
}
108
- memcpy (buffer , * tzf , sizeof (int32_t ) * tz -> timecnt );
109
- * tzf += (sizeof (int32_t ) * tz -> timecnt );
110
- for (i = 0 ; i < tz -> timecnt ; i ++ ) {
108
+ memcpy (buffer , * tzf , sizeof (int32_t ) * tz -> bit32 . timecnt );
109
+ * tzf += (sizeof (int32_t ) * tz -> bit32 . timecnt );
110
+ for (i = 0 ; i < tz -> bit32 . timecnt ; i ++ ) {
111
111
buffer [i ] = timelib_conv_int (buffer [i ]);
112
112
}
113
113
114
- cbuffer = (unsigned char * ) malloc (tz -> timecnt * sizeof (unsigned char ));
114
+ cbuffer = (unsigned char * ) malloc (tz -> bit32 . timecnt * sizeof (unsigned char ));
115
115
if (!cbuffer ) {
116
116
free (buffer );
117
117
return ;
118
118
}
119
- memcpy (cbuffer , * tzf , sizeof (unsigned char ) * tz -> timecnt );
120
- * tzf += sizeof (unsigned char ) * tz -> timecnt ;
119
+ memcpy (cbuffer , * tzf , sizeof (unsigned char ) * tz -> bit32 . timecnt );
120
+ * tzf += sizeof (unsigned char ) * tz -> bit32 . timecnt ;
121
121
}
122
122
123
123
tz -> trans = buffer ;
124
124
tz -> trans_idx = cbuffer ;
125
125
}
126
126
127
- static void skip_types_64bit (const unsigned char * * tzf , timelib_tzinfo * tz )
127
+ static void skip_64bit_types (const unsigned char * * tzf , timelib_tzinfo * tz )
128
128
{
129
- * tzf += sizeof (unsigned char ) * 6 * tz -> typecnt ;
130
- * tzf += sizeof (char ) * tz -> charcnt ;
131
- if (tz -> leapcnt ) {
132
- * tzf += sizeof (int64_t ) * tz -> leapcnt * 2 ;
129
+ * tzf += sizeof (unsigned char ) * 6 * tz -> bit64 . typecnt ;
130
+ * tzf += sizeof (char ) * tz -> bit64 . charcnt ;
131
+ if (tz -> bit64 . leapcnt ) {
132
+ * tzf += sizeof (int64_t ) * tz -> bit64 . leapcnt * 2 ;
133
133
}
134
- if (tz -> ttisstdcnt ) {
135
- * tzf += sizeof (unsigned char ) * tz -> ttisstdcnt ;
134
+ if (tz -> bit64 . ttisstdcnt ) {
135
+ * tzf += sizeof (unsigned char ) * tz -> bit64 . ttisstdcnt ;
136
136
}
137
- if (tz -> ttisgmtcnt ) {
138
- * tzf += sizeof (unsigned char ) * tz -> ttisgmtcnt ;
137
+ if (tz -> bit64 . ttisgmtcnt ) {
138
+ * tzf += sizeof (unsigned char ) * tz -> bit64 . ttisgmtcnt ;
139
139
}
140
140
}
141
141
@@ -145,77 +145,77 @@ static void read_types(const unsigned char **tzf, timelib_tzinfo *tz)
145
145
int32_t * leap_buffer ;
146
146
unsigned int i , j ;
147
147
148
- buffer = (unsigned char * ) malloc (tz -> typecnt * sizeof (unsigned char ) * 6 );
148
+ buffer = (unsigned char * ) malloc (tz -> bit32 . typecnt * sizeof (unsigned char ) * 6 );
149
149
if (!buffer ) {
150
150
return ;
151
151
}
152
- memcpy (buffer , * tzf , sizeof (unsigned char ) * 6 * tz -> typecnt );
153
- * tzf += sizeof (unsigned char ) * 6 * tz -> typecnt ;
152
+ memcpy (buffer , * tzf , sizeof (unsigned char ) * 6 * tz -> bit32 . typecnt );
153
+ * tzf += sizeof (unsigned char ) * 6 * tz -> bit32 . typecnt ;
154
154
155
- tz -> type = (ttinfo * ) malloc (tz -> typecnt * sizeof (struct ttinfo ));
155
+ tz -> type = (ttinfo * ) malloc (tz -> bit32 . typecnt * sizeof (struct ttinfo ));
156
156
if (!tz -> type ) {
157
157
free (buffer );
158
158
return ;
159
159
}
160
160
161
- for (i = 0 ; i < tz -> typecnt ; i ++ ) {
161
+ for (i = 0 ; i < tz -> bit32 . typecnt ; i ++ ) {
162
162
j = i * 6 ;
163
163
tz -> type [i ].offset = (buffer [j ] * 16777216 ) + (buffer [j + 1 ] * 65536 ) + (buffer [j + 2 ] * 256 ) + buffer [j + 3 ];
164
164
tz -> type [i ].isdst = buffer [j + 4 ];
165
165
tz -> type [i ].abbr_idx = buffer [j + 5 ];
166
166
}
167
167
free (buffer );
168
168
169
- tz -> timezone_abbr = (char * ) malloc (tz -> charcnt );
169
+ tz -> timezone_abbr = (char * ) malloc (tz -> bit32 . charcnt );
170
170
if (!tz -> timezone_abbr ) {
171
171
return ;
172
172
}
173
- memcpy (tz -> timezone_abbr , * tzf , sizeof (char ) * tz -> charcnt );
174
- * tzf += sizeof (char ) * tz -> charcnt ;
173
+ memcpy (tz -> timezone_abbr , * tzf , sizeof (char ) * tz -> bit32 . charcnt );
174
+ * tzf += sizeof (char ) * tz -> bit32 . charcnt ;
175
175
176
- if (tz -> leapcnt ) {
177
- leap_buffer = (int32_t * ) malloc (tz -> leapcnt * 2 * sizeof (int32_t ));
176
+ if (tz -> bit32 . leapcnt ) {
177
+ leap_buffer = (int32_t * ) malloc (tz -> bit32 . leapcnt * 2 * sizeof (int32_t ));
178
178
if (!leap_buffer ) {
179
179
return ;
180
180
}
181
- memcpy (leap_buffer , * tzf , sizeof (int32_t ) * tz -> leapcnt * 2 );
182
- * tzf += sizeof (int32_t ) * tz -> leapcnt * 2 ;
181
+ memcpy (leap_buffer , * tzf , sizeof (int32_t ) * tz -> bit32 . leapcnt * 2 );
182
+ * tzf += sizeof (int32_t ) * tz -> bit32 . leapcnt * 2 ;
183
183
184
- tz -> leap_times = (tlinfo * ) malloc (tz -> leapcnt * sizeof (tlinfo ));
184
+ tz -> leap_times = (tlinfo * ) malloc (tz -> bit32 . leapcnt * sizeof (tlinfo ));
185
185
if (!tz -> leap_times ) {
186
186
free (leap_buffer );
187
187
return ;
188
188
}
189
- for (i = 0 ; i < tz -> leapcnt ; i ++ ) {
189
+ for (i = 0 ; i < tz -> bit32 . leapcnt ; i ++ ) {
190
190
tz -> leap_times [i ].trans = timelib_conv_int (leap_buffer [i * 2 ]);
191
191
tz -> leap_times [i ].offset = timelib_conv_int (leap_buffer [i * 2 + 1 ]);
192
192
}
193
193
free (leap_buffer );
194
194
}
195
195
196
- if (tz -> ttisstdcnt ) {
197
- buffer = (unsigned char * ) malloc (tz -> ttisstdcnt * sizeof (unsigned char ));
196
+ if (tz -> bit32 . ttisstdcnt ) {
197
+ buffer = (unsigned char * ) malloc (tz -> bit32 . ttisstdcnt * sizeof (unsigned char ));
198
198
if (!buffer ) {
199
199
return ;
200
200
}
201
- memcpy (buffer , * tzf , sizeof (unsigned char ) * tz -> ttisstdcnt );
202
- * tzf += sizeof (unsigned char ) * tz -> ttisstdcnt ;
201
+ memcpy (buffer , * tzf , sizeof (unsigned char ) * tz -> bit32 . ttisstdcnt );
202
+ * tzf += sizeof (unsigned char ) * tz -> bit32 . ttisstdcnt ;
203
203
204
- for (i = 0 ; i < tz -> ttisstdcnt ; i ++ ) {
204
+ for (i = 0 ; i < tz -> bit32 . ttisstdcnt ; i ++ ) {
205
205
tz -> type [i ].isstdcnt = buffer [i ];
206
206
}
207
207
free (buffer );
208
208
}
209
209
210
- if (tz -> ttisgmtcnt ) {
211
- buffer = (unsigned char * ) malloc (tz -> ttisgmtcnt * sizeof (unsigned char ));
210
+ if (tz -> bit32 . ttisgmtcnt ) {
211
+ buffer = (unsigned char * ) malloc (tz -> bit32 . ttisgmtcnt * sizeof (unsigned char ));
212
212
if (!buffer ) {
213
213
return ;
214
214
}
215
- memcpy (buffer , * tzf , sizeof (unsigned char ) * tz -> ttisgmtcnt );
216
- * tzf += sizeof (unsigned char ) * tz -> ttisgmtcnt ;
215
+ memcpy (buffer , * tzf , sizeof (unsigned char ) * tz -> bit32 . ttisgmtcnt );
216
+ * tzf += sizeof (unsigned char ) * tz -> bit32 . ttisgmtcnt ;
217
217
218
- for (i = 0 ; i < tz -> ttisgmtcnt ; i ++ ) {
218
+ for (i = 0 ; i < tz -> bit32 . ttisgmtcnt ; i ++ ) {
219
219
tz -> type [i ].isgmtcnt = buffer [i ];
220
220
}
221
221
free (buffer );
@@ -261,12 +261,12 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz)
261
261
printf ("Geo Location: %f,%f\n" , tz -> location .latitude , tz -> location .longitude );
262
262
printf ("Comments:\n%s\n" , tz -> location .comments );
263
263
printf ("BC: %s\n" , tz -> bc ? "" : "yes" );
264
- printf ("UTC/Local count: %lu \n" , (unsigned long ) tz -> ttisgmtcnt );
265
- printf ("Std/Wall count: %lu \n" , (unsigned long ) tz -> ttisstdcnt );
266
- printf ("Leap.sec. count: %lu \n" , (unsigned long ) tz -> leapcnt );
267
- printf ("Trans. count: %lu \n" , (unsigned long ) tz -> timecnt );
268
- printf ("Local types count: %lu \n" , (unsigned long ) tz -> typecnt );
269
- printf ("Zone Abbr. count: %lu \n" , (unsigned long ) tz -> charcnt );
264
+ printf ("UTC/Local count: " TIMELIB_ULONG_FMT " \n" , (timelib_ulong ) tz -> bit32 . ttisgmtcnt );
265
+ printf ("Std/Wall count: " TIMELIB_ULONG_FMT " \n" , (timelib_ulong ) tz -> bit32 . ttisstdcnt );
266
+ printf ("Leap.sec. count: " TIMELIB_ULONG_FMT " \n" , (timelib_ulong ) tz -> bit32 . leapcnt );
267
+ printf ("Trans. count: " TIMELIB_ULONG_FMT " \n" , (timelib_ulong ) tz -> bit32 . timecnt );
268
+ printf ("Local types count: " TIMELIB_ULONG_FMT " \n" , (timelib_ulong ) tz -> bit32 . typecnt );
269
+ printf ("Zone Abbr. count: " TIMELIB_ULONG_FMT " \n" , (timelib_ulong ) tz -> bit32 . charcnt );
270
270
271
271
printf ("%8s (%12s) = %3d [%5ld %1d %3d '%s' (%d,%d)]\n" ,
272
272
"" , "" , 0 ,
@@ -277,7 +277,7 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz)
277
277
tz -> type [0 ].isstdcnt ,
278
278
tz -> type [0 ].isgmtcnt
279
279
);
280
- for (i = 0 ; i < tz -> timecnt ; i ++ ) {
280
+ for (i = 0 ; i < tz -> bit32 . timecnt ; i ++ ) {
281
281
printf ("%08X (%12d) = %3d [%5ld %1d %3d '%s' (%d,%d)]\n" ,
282
282
tz -> trans [i ], tz -> trans [i ], tz -> trans_idx [i ],
283
283
(long int ) tz -> type [tz -> trans_idx [i ]].offset ,
@@ -288,7 +288,7 @@ void timelib_dump_tzinfo(timelib_tzinfo *tz)
288
288
tz -> type [tz -> trans_idx [i ]].isgmtcnt
289
289
);
290
290
}
291
- for (i = 0 ; i < tz -> leapcnt ; i ++ ) {
291
+ for (i = 0 ; i < tz -> bit32 . leapcnt ; i ++ ) {
292
292
printf ("%08X (%12ld) = %d\n" ,
293
293
tz -> leap_times [i ].trans ,
294
294
(long ) tz -> leap_times [i ].trans ,
@@ -352,10 +352,23 @@ int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb)
352
352
return (seek_to_tz_position (& tzf , timezone , tzdb ));
353
353
}
354
354
355
- static void skip_2nd_header_and_data (const unsigned char * * tzf , timelib_tzinfo * tz )
355
+ static void skip_64bit_preamble (const unsigned char * * tzf , timelib_tzinfo * tz )
356
356
{
357
- * tzf += 20 ; /* skip 2nd header (preamble) */
358
- * tzf += sizeof (int32_t ) * 6 ; /* Counts */
357
+ * tzf += 20 ;
358
+ }
359
+
360
+ static void read_64bit_header (const unsigned char * * tzf , timelib_tzinfo * tz )
361
+ {
362
+ uint32_t buffer [6 ];
363
+
364
+ memcpy (& buffer , * tzf , sizeof (buffer ));
365
+ tz -> bit64 .ttisgmtcnt = timelib_conv_int (buffer [0 ]);
366
+ tz -> bit64 .ttisstdcnt = timelib_conv_int (buffer [1 ]);
367
+ tz -> bit64 .leapcnt = timelib_conv_int (buffer [2 ]);
368
+ tz -> bit64 .timecnt = timelib_conv_int (buffer [3 ]);
369
+ tz -> bit64 .typecnt = timelib_conv_int (buffer [4 ]);
370
+ tz -> bit64 .charcnt = timelib_conv_int (buffer [5 ]);
371
+ * tzf += sizeof (buffer );
359
372
}
360
373
361
374
timelib_tzinfo * timelib_parse_tzfile (char * timezone , const timelib_tzdb * tzdb )
@@ -372,9 +385,10 @@ timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb)
372
385
read_transistions (& tzf , tmp );
373
386
read_types (& tzf , tmp );
374
387
if (version == 2 ) {
375
- skip_2nd_header_and_data (& tzf , tmp );
376
- skip_transistions_64bit (& tzf , tmp );
377
- skip_types_64bit (& tzf , tmp );
388
+ skip_64bit_preamble (& tzf , tmp );
389
+ read_64bit_header (& tzf , tmp );
390
+ skip_64bit_transistions (& tzf , tmp );
391
+ skip_64bit_types (& tzf , tmp );
378
392
skip_posix_string (& tzf , tmp );
379
393
}
380
394
read_location (& tzf , tmp );
@@ -391,9 +405,9 @@ static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib
391
405
392
406
/* If there is no transition time, we pick the first one, if that doesn't
393
407
* exist we return NULL */
394
- if (!tz -> timecnt || !tz -> trans ) {
408
+ if (!tz -> bit32 . timecnt || !tz -> trans ) {
395
409
* transition_time = 0 ;
396
- if (tz -> typecnt == 1 ) {
410
+ if (tz -> bit32 . typecnt == 1 ) {
397
411
return & (tz -> type [0 ]);
398
412
}
399
413
return NULL ;
@@ -408,36 +422,36 @@ static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib
408
422
409
423
* transition_time = 0 ;
410
424
j = 0 ;
411
- while (j < tz -> timecnt && tz -> type [j ].isdst ) {
425
+ while (j < tz -> bit32 . timecnt && tz -> type [j ].isdst ) {
412
426
++ j ;
413
427
}
414
- if (j == tz -> timecnt ) {
428
+ if (j == tz -> bit32 . timecnt ) {
415
429
j = 0 ;
416
430
}
417
431
return & (tz -> type [j ]);
418
432
}
419
433
420
434
/* In all other cases we loop through the available transtion times to find
421
435
* the correct entry */
422
- for (i = 0 ; i < tz -> timecnt ; i ++ ) {
436
+ for (i = 0 ; i < tz -> bit32 . timecnt ; i ++ ) {
423
437
if (ts < tz -> trans [i ]) {
424
438
* transition_time = tz -> trans [i - 1 ];
425
439
return & (tz -> type [tz -> trans_idx [i - 1 ]]);
426
440
}
427
441
}
428
- * transition_time = tz -> trans [tz -> timecnt - 1 ];
429
- return & (tz -> type [tz -> trans_idx [tz -> timecnt - 1 ]]);
442
+ * transition_time = tz -> trans [tz -> bit32 . timecnt - 1 ];
443
+ return & (tz -> type [tz -> trans_idx [tz -> bit32 . timecnt - 1 ]]);
430
444
}
431
445
432
446
static tlinfo * fetch_leaptime_offset (timelib_tzinfo * tz , timelib_sll ts )
433
447
{
434
448
int i ;
435
449
436
- if (!tz -> leapcnt || !tz -> leap_times ) {
450
+ if (!tz -> bit32 . leapcnt || !tz -> leap_times ) {
437
451
return NULL ;
438
452
}
439
453
440
- for (i = tz -> leapcnt - 1 ; i > 0 ; i -- ) {
454
+ for (i = tz -> bit32 . leapcnt - 1 ; i > 0 ; i -- ) {
441
455
if (ts > tz -> leap_times [i ].trans ) {
442
456
return & (tz -> leap_times [i ]);
443
457
}
0 commit comments