~ubuntu-branches/ubuntu/trusty/eglibc/trusty

« back to all changes in this revision

Viewing changes to timezone/zdump.c

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-01-10 18:39:35 UTC
  • mfrom: (1.5.2) (4.4.24 experimental)
  • Revision ID: package-import@ubuntu.com-20130110183935-afsgfxkmg7wk5eaj
Tags: 2.17-0ubuntu1
* Merge with Debian, bringing in a new upstream and many small fixes:
  - patches/any/cvs-malloc-deadlock.diff: Dropped, merged upstream.
  - patches/ubuntu/lddebug-scopes.diff: Rebase for upstream changes.
  - patches/ubuntu/local-CVE-2012-3406.diff: Rebased against upstream.
  - patches/ubuntu/no-asm-mtune-i686.diff: Fixed in recent binutils.
* This upstream merge fixes a nasty hang in pulseaudio (LP: #1085342)
* Bump MIN_KERNEL_SUPPORTED to 2.6.32 on ARM, now that we no longer
  have to support shonky 2.6.31 kernels on imx51 babbage builders.
* Drop patches/ubuntu/local-disable-nscd-host-caching.diff, as these
  issues were apparently resolved upstream a while ago (LP: #613662)
* Fix the compiled-in bug URL to point to launchpad.net, not Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
** 2009-05-17 by Arthur David Olson.
4
4
*/
5
5
 
6
 
static char     elsieid[] = "@(#)zdump.c        8.10";
 
6
#include "version.h"
7
7
 
8
8
/*
9
9
** This code has been made independent of the rest of the time
11
11
** You can use this code to help in verifying other implementations.
12
12
*/
13
13
 
14
 
#include "config.h"
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. */
22
22
#ifndef isascii
23
23
#define isascii(x) 1
120
120
#endif /* !defined GNUC_or_lint */
121
121
#endif /* !defined INITIALIZE */
122
122
 
 
123
#if 2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)
 
124
# define ATTRIBUTE_PURE __attribute__ ((__pure__))
 
125
#else
 
126
# define ATTRIBUTE_PURE /* empty */
 
127
#endif
 
128
 
123
129
/*
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];
147
153
 
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 =
 
158
  ((time_t) 0.5 == 0.5
 
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
 
162
      : 0)
 
163
   : (time_t) -1 < 0
 
164
#ifdef LLONG_MAX
 
165
   ? (time_t) ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1))
 
166
#else
 
167
   ? (time_t) ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1))
 
168
#endif
 
169
   : 0);
 
170
static time_t const absolute_max_time =
 
171
  ((time_t) 0.5 == 0.5
 
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
 
175
      : -1)
 
176
   : (time_t) -1 < 0
 
177
#ifdef LLONG_MAX
 
178
   ? (time_t) (- (~ 0 < 0) - ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1)))
 
179
#else
 
180
   ? (time_t) (- (~ 0 < 0) - ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1)))
 
181
#endif
 
182
   : (time_t) -1);
150
183
static size_t   longest;
151
184
static char *   progname;
152
185
static int      warned;
153
186
 
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;
163
196
 
164
197
#ifndef TYPECHECK
165
198
#define my_localtime    localtime
166
199
#else /* !defined TYPECHECK */
167
200
static struct tm *
168
 
my_localtime(tp)
169
 
time_t *        tp;
 
201
my_localtime(time_t *tp)
170
202
{
171
203
        register struct tm *    tmp;
172
204
 
199
231
#endif /* !defined TYPECHECK */
200
232
 
201
233
static void
202
 
abbrok(abbrp, zone)
203
 
const char * const      abbrp;
204
 
const char * const      zone;
 
234
abbrok(const char *const abbrp, const char *const zone)
205
235
{
206
236
        register const char *   cp;
207
 
        register char *         wp;
 
237
        register const char *   wp;
208
238
 
209
239
        if (warned)
210
240
                return;
237
267
}
238
268
 
239
269
static void
240
 
usage(stream, status)
241
 
FILE * const    stream;
242
 
const int       status;
 
270
usage(FILE * const stream, const int status)
243
271
{
244
272
        (void) fprintf(stream,
245
273
_("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n\
246
274
\n\
247
 
For bug reporting instructions, please see:\n\
248
 
%s.\n"),
 
275
Report bugs to %s.\n"),
249
276
                       progname, progname, REPORT_BUGS_TO);
250
277
        exit(status);
251
278
}
252
279
 
253
280
int
254
 
main(argc, argv)
255
 
int     argc;
256
 
char *  argv[];
 
281
main(int argc, char *argv[])
257
282
{
258
283
        register int            i;
259
284
        register int            c;
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);
317
342
                                exit(EXIT_FAILURE);
318
343
                        }
319
344
                }
320
 
                setabsolutes();
 
345
                checkabsolutes();
321
346
                cutlotime = yeartot(cutloyear);
322
347
                cuthitime = yeartot(cuthiyear);
323
348
        }
332
357
 
333
358
                for (i = 0; environ[i] != NULL; ++i)
334
359
                        continue;
335
 
                fakeenv = (char **) malloc((size_t) ((i + 2) *
336
 
                        sizeof *fakeenv));
337
 
                if (fakeenv == NULL ||
338
 
                        (fakeenv[0] = (char *) malloc(longest + 4)) == NULL) {
 
360
                fakeenv = malloc((i + 2) * sizeof *fakeenv);
 
361
                if (fakeenv == NULL
 
362
                    || (fakeenv[0] = malloc(longest + 4)) == NULL) {
339
363
                                        (void) perror(progname);
340
364
                                        exit(EXIT_FAILURE);
341
365
                }
408
432
}
409
433
 
410
434
static void
411
 
setabsolutes(void)
 
435
checkabsolutes(void)
412
436
{
413
 
        if (0.5 == (time_t) 0.5) {
414
 
                /*
415
 
                ** time_t is floating.
416
 
                */
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;
423
 
                } else {
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"),
426
 
                                progname);
427
 
                        exit(EXIT_FAILURE);
428
 
                }
429
 
        } else if (0 > (time_t) -1) {
430
 
                /*
431
 
                ** time_t is signed.  Assume overflow wraps around.
432
 
                */
433
 
                time_t t = 0;
434
 
                time_t t1 = 1;
435
 
 
436
 
                while (t < t1) {
437
 
                        t = t1;
438
 
                        t1 = 2 * t1 + 1;
439
 
                }
440
 
 
441
 
                absolute_max_time = t;
442
 
                t = -t;
443
 
                absolute_min_time = t - 1;
444
 
                if (t < absolute_min_time)
445
 
                        absolute_min_time = t;
446
 
        } else {
447
 
                /*
448
 
                ** time_t is unsigned.
449
 
                */
450
 
                absolute_min_time = 0;
451
 
                absolute_max_time = absolute_min_time - 1;
 
440
                               progname);
 
441
                exit(EXIT_FAILURE);
452
442
        }
453
443
}
454
444
 
455
445
static time_t
456
 
yeartot(y)
457
 
const long      y;
 
446
yeartot(const long y)
458
447
{
459
448
        register long   myy;
460
449
        register long   seconds;
532
521
*/
533
522
 
534
523
static long
535
 
delta(newp, oldp)
536
 
struct tm *     newp;
537
 
struct tm *     oldp;
 
524
delta(struct tm * newp, struct tm *oldp)
538
525
{
539
526
        register long   result;
540
527
        register int    tmy;
588
575
}
589
576
 
590
577
static char *
591
 
abbr(tmp)
592
 
struct tm *     tmp;
 
578
abbr(struct tm *tmp)
593
579
{
594
580
        register char * result;
595
581
        static char     nada;
628
614
}
629
615
 
630
616
static void
631
 
dumptime(timeptr)
632
 
register const struct tm *      timeptr;
 
617
dumptime(register const struct tm *timeptr)
633
618
{
634
619
        static const char       wday_name[][3] = {
635
620
                "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"