]> git.saurik.com Git - apple/system_cmds.git/blobdiff - zdump.tproj/zdump.c
system_cmds-735.20.1.tar.gz
[apple/system_cmds.git] / zdump.tproj / zdump.c
index f98d1177dd86ab11db1f696deae124585bd6907e..7068cdfd73107d5083e11db87035671456c42908 100644 (file)
@@ -1,8 +1,9 @@
 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 */
 
 /*
@@ -18,6 +19,7 @@ static const char rcsid[] =
 #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
@@ -134,21 +136,28 @@ static void       show P((char * zone, time_t t, int v));
 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;
 
@@ -170,7 +179,7 @@ char *      argv[];
                if (c == 'v')
                        vflag = 1;
                else    cutoff = optarg;
-       if ((c != EOF && c != -1) ||
+       if ((c != -1) ||
                (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) {
                        usage();
        }
@@ -188,11 +197,13 @@ char *    argv[];
        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;
@@ -222,9 +233,13 @@ char *     argv[];
                /*
                ** 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);
@@ -236,8 +251,13 @@ char *     argv[];
                        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 ||
@@ -253,9 +273,13 @@ char *     argv[];
                /*
                ** 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;
@@ -279,10 +303,7 @@ _("usage: zdump [--version] [-v] [-c cutoff] zonename ...\n"));
 }
 
 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;
@@ -315,9 +336,7 @@ time_t      hit;
 */
 
 static long
-delta(newp, oldp)
-struct tm *    newp;
-struct tm *    oldp;
+delta(struct tm *newp, struct tm *oldp)
 {
        long    result;
        int     tmy;
@@ -338,10 +357,7 @@ struct tm *        oldp;
 }
 
 static void
-show(zone, t, v)
-char * zone;
-time_t t;
-int    v;
+show(char *zone, time_t t, int v)
 {
        struct tm *     tmp;
 
@@ -362,10 +378,9 @@ int        v;
 }
 
 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)