static const char elsieid[] = "@(#)zdump.c 7.31";
#ifndef lint
-static const char rcsid[] =
- "$FreeBSD: src/usr.sbin/zic/zdump.c,v 1.9 2004/06/20 21:41:11 stefanf Exp $";
+#include <sys/cdefs.h>
+__unused static const char rcsid[] =
+ "$FreeBSD: src/usr.sbin/zic/zdump.c,v 1.10 2008/02/19 07:09:19 ru Exp $";
#endif /* not lint */
/*
#include <sys/types.h> /* for time_t */
#include <time.h> /* for struct tm */
#include <unistd.h>
+#include <limits.h>
#ifndef MAX_STRING_LENGTH
#define MAX_STRING_LENGTH 1024
static void usage(void);
int
-main(argc, argv)
-int argc;
-char * argv[];
+main(int argc, char *argv[])
{
- register int i;
- register int c;
- register int vflag;
- register char * cutoff;
- register int cutyear;
- register long cuttime;
+ int i;
+ int c;
+ int vflag;
+ char * cutoff;
+ int cutyear;
+ long cuttime;
char ** fakeenv;
time_t now;
time_t t;
time_t newt;
+#ifndef __APPLE__
+// <rdar://problem/6013740>
+// The approach of walking through every day from the minimum
+// possible time_t value to the maximum possible time_t value
+// falls apart with 64-bit time_t (takes too long to iterate,
+// and causes gmtime(3) and localtime(3) to return EOVERFLOW
+// which this code does not anticipate). Limiting the time_t
+// range to [INT_MIN:INT_MAX] even on LP64.
time_t hibit;
+#endif
struct tm tm;
struct tm newtm;
if (c == 'v')
vflag = 1;
else cutoff = optarg;
- if ((c != EOF && c != -1) ||
+ if ((c != -1) ||
(optind == argc - 1 && strcmp(argv[optind], "=") == 0)) {
usage();
}
for (i = optind; i < argc; ++i)
if (strlen(argv[i]) > longest)
longest = strlen(argv[i]);
+#ifndef __APPLE__
for (hibit = 1; (hibit << 1) != 0; hibit <<= 1)
continue;
+#endif
{
- register int from;
- register int to;
+ int from;
+ int to;
for (i = 0; environ[i] != NULL; ++i)
continue;
/*
** Get lowest value of t.
*/
+#ifdef __APPLE__
+ t = INT_MIN;
+#else
t = hibit;
if (t > 0) /* time_t is unsigned */
t = 0;
+#endif
show(argv[i], t, TRUE);
t += SECSPERHOUR * HOURSPERDAY;
show(argv[i], t, TRUE);
newt = t + SECSPERHOUR * 12;
if (cutoff != NULL && newt >= cuttime)
break;
+#ifdef __APPLE__
+ if (newt > INT_MAX)
+ break;
+#else
if (newt <= t)
break;
+#endif
newtm = *localtime(&newt);
if (delta(&newtm, &tm) != (newt - t) ||
newtm.tm_isdst != tm.tm_isdst ||
/*
** Get highest value of t.
*/
+#ifdef __APPLE__
+ t = INT_MAX;
+#else
t = ~((time_t) 0);
if (t < 0) /* time_t is signed */
t &= ~hibit;
+#endif
t -= SECSPERHOUR * HOURSPERDAY;
show(argv[i], t, TRUE);
t += SECSPERHOUR * HOURSPERDAY;
}
static time_t
-hunt(name, lot, hit)
-char * name;
-time_t lot;
-time_t hit;
+hunt(char *name, time_t lot, time_t hit)
{
time_t t;
struct tm lotm;
*/
static long
-delta(newp, oldp)
-struct tm * newp;
-struct tm * oldp;
+delta(struct tm *newp, struct tm *oldp)
{
long result;
int tmy;
}
static void
-show(zone, t, v)
-char * zone;
-time_t t;
-int v;
+show(char *zone, time_t t, int v)
{
struct tm * tmp;
}
static char *
-abbr(tmp)
-struct tm * tmp;
+abbr(struct tm *tmp)
{
- register char * result;
+ char * result;
static char nada;
if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1)