11
11
** You can use this code to help in verifying other implementations.
15
14
#include "stdio.h" /* for stdout, stderr, perror */
16
15
#include "string.h" /* for strcpy */
17
16
#include "sys/types.h" /* for time_t */
18
17
#include "time.h" /* for struct tm */
19
18
#include "stdlib.h" /* for exit, malloc, atoi */
20
19
#include "float.h" /* for FLT_MAX and DBL_MAX */
20
#include "limits.h" /* for CHAR_BIT, LLONG_MAX */
21
21
#include "ctype.h" /* for isalpha et al. */
23
23
#define isascii(x) 1
120
120
#endif /* !defined GNUC_or_lint */
121
121
#endif /* !defined INITIALIZE */
123
#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)
124
# define ATTRIBUTE_PURE __attribute__ ((__pure__))
126
# define ATTRIBUTE_PURE /* empty */
124
130
** For the benefit of GNU folk...
125
131
** `_(MSGID)' uses the current locale's message library string for MSGID.
145
151
extern int optind;
146
152
extern char * tzname[2];
148
static time_t absolute_min_time;
149
static time_t absolute_max_time;
154
/* The minimum and maximum finite time values. Shift 'long long' or
155
'long' instead of 'time_t'; this avoids compile-time errors when
156
time_t is floating-point. In practice, 'long long' is wide enough. */
157
static time_t const absolute_min_time =
159
? (sizeof (time_t) == sizeof (float) ? (time_t) -FLT_MAX
160
: sizeof (time_t) == sizeof (double) ? (time_t) -DBL_MAX
161
: sizeof (time_t) == sizeof (long double) ? (time_t) -LDBL_MAX
165
? (time_t) ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1))
167
? (time_t) ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1))
170
static time_t const absolute_max_time =
172
? (sizeof (time_t) == sizeof (float) ? (time_t) FLT_MAX
173
: sizeof (time_t) == sizeof (double) ? (time_t) DBL_MAX
174
: sizeof (time_t) == sizeof (long double) ? (time_t) LDBL_MAX
178
? (time_t) (- (~ 0 < 0) - ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1)))
180
? (time_t) (- (~ 0 < 0) - ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1)))
150
183
static size_t longest;
151
184
static char * progname;
152
185
static int warned;
154
187
static char * abbr(struct tm * tmp);
155
188
static void abbrok(const char * abbrp, const char * zone);
156
static long delta(struct tm * newp, struct tm * oldp);
189
static long delta(struct tm * newp, struct tm * oldp) ATTRIBUTE_PURE;
157
190
static void dumptime(const struct tm * tmp);
158
191
static time_t hunt(char * name, time_t lot, time_t hit);
159
static void setabsolutes(void);
192
static void checkabsolutes(void);
160
193
static void show(char * zone, time_t t, int v);
161
194
static const char * tformat(void);
162
static time_t yeartot(long y);
195
static time_t yeartot(long y) ATTRIBUTE_PURE;
164
197
#ifndef TYPECHECK
165
198
#define my_localtime localtime
166
199
#else /* !defined TYPECHECK */
167
200
static struct tm *
201
my_localtime(time_t *tp)
171
203
register struct tm * tmp;
199
231
#endif /* !defined TYPECHECK */
203
const char * const abbrp;
204
const char * const zone;
234
abbrok(const char *const abbrp, const char *const zone)
206
236
register const char * cp;
237
register const char * wp;
240
usage(stream, status)
270
usage(FILE * const stream, const int status)
244
272
(void) fprintf(stream,
245
273
_("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n\
247
For bug reporting instructions, please see:\n\
275
Report bugs to %s.\n"),
249
276
progname, progname, REPORT_BUGS_TO);
281
main(int argc, char *argv[])
284
309
progname = argv[0];
285
310
for (i = 1; i < argc; ++i)
286
311
if (strcmp(argv[i], "--version") == 0) {
287
(void) printf("zdump %s%s\n", PKGVERSION, elsieid);
312
(void) printf("zdump %s%s\n", PKGVERSION, TZVERSION);
288
313
exit(EXIT_SUCCESS);
289
314
} else if (strcmp(argv[i], "--help") == 0) {
290
315
usage(stdout, EXIT_SUCCESS);
333
358
for (i = 0; environ[i] != NULL; ++i)
335
fakeenv = (char **) malloc((size_t) ((i + 2) *
337
if (fakeenv == NULL ||
338
(fakeenv[0] = (char *) malloc(longest + 4)) == NULL) {
360
fakeenv = malloc((i + 2) * sizeof *fakeenv);
362
|| (fakeenv[0] = malloc(longest + 4)) == NULL) {
339
363
(void) perror(progname);
340
364
exit(EXIT_FAILURE);
413
if (0.5 == (time_t) 0.5) {
415
** time_t is floating.
417
if (sizeof (time_t) == sizeof (float)) {
418
absolute_min_time = (time_t) -FLT_MAX;
419
absolute_max_time = (time_t) FLT_MAX;
420
} else if (sizeof (time_t) == sizeof (double)) {
421
absolute_min_time = (time_t) -DBL_MAX;
422
absolute_max_time = (time_t) DBL_MAX;
424
(void) fprintf(stderr,
437
if (absolute_max_time < absolute_min_time) {
438
(void) fprintf(stderr,
425
439
_("%s: use of -v on system with floating time_t other than float or double\n"),
429
} else if (0 > (time_t) -1) {
431
** time_t is signed. Assume overflow wraps around.
441
absolute_max_time = t;
443
absolute_min_time = t - 1;
444
if (t < absolute_min_time)
445
absolute_min_time = t;
448
** time_t is unsigned.
450
absolute_min_time = 0;
451
absolute_max_time = absolute_min_time - 1;
446
yeartot(const long y)
459
448
register long myy;
460
449
register long seconds;
632
register const struct tm * timeptr;
617
dumptime(register const struct tm *timeptr)
634
619
static const char wday_name[][3] = {
635
620
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"