7 static char elsieid[] = "@(#)zdump.c 7.2";
8 #endif /* !defined NOID */
9 #endif /* !defined lint */
12 ** This code has been made independent of the rest of the time
13 ** conversion package to increase confidence in the verification it provides.
14 ** You can use this code to help in verifying other implementations.
17 #include "stdio.h" /* for stdout, stderr */
18 #include "string.h" /* for strcpy */
19 #include "sys/types.h" /* for time_t */
20 #include "time.h" /* for struct tm */
22 #ifndef MAX_STRING_LENGTH
23 #define MAX_STRING_LENGTH 1024
24 #endif /* !defined MAX_STRING_LENGTH */
28 #endif /* !defined TRUE */
32 #endif /* !defined FALSE */
35 #define EXIT_SUCCESS 0
36 #endif /* !defined EXIT_SUCCESS */
39 #define EXIT_FAILURE 1
40 #endif /* !defined EXIT_FAILURE */
44 #endif /* !defined SECSPERMIN */
47 #define SECSPERHOUR 3600
48 #endif /* !defined SECSPERHOUR */
51 #define HOURSPERDAY 24
52 #endif /* !defined HOURSPERDAY */
55 #define EPOCH_YEAR 1970
56 #endif /* !defined EPOCH_YEAR */
59 #define DAYSPERNYEAR 365
60 #endif /* !defined DAYSPERNYEAR */
62 extern char ** environ;
67 extern char * tzname[2];
73 #endif /* defined USG */
79 static char * progname;
89 register char * cutoff;
91 register long cuttime;
100 while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v')
103 else cutoff = optarg;
105 (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) {
106 (void) fprintf(stderr,
107 "%s: usage is %s [ -v ] [ -c cutoff ] zonename ...\n",
109 (void) exit(EXIT_FAILURE);
112 cutyear = atoi(cutoff);
116 cuttime = (long) (cutyear - EPOCH_YEAR) *
117 SECSPERHOUR * HOURSPERDAY * DAYSPERNYEAR;
120 for (i = optind; i < argc; ++i)
121 if (strlen(argv[i]) > longest)
122 longest = strlen(argv[i]);
123 for (hibit = 1; (hibit << 1) != 0; hibit <<= 1)
125 for (i = optind; i < argc; ++i) {
126 register char ** saveenv;
127 static char buf[MAX_STRING_LENGTH];
130 if (strlen(argv[i]) + 4 > sizeof buf) {
131 (void) fflush(stdout);
132 (void) fprintf(stderr, "%s: argument too long -- %s\n",
134 (void) exit(EXIT_FAILURE);
136 (void) strcpy(buf, "TZ=");
137 (void) strcat(buf, argv[i]);
144 show(argv[i], now, FALSE);
148 ** Get lowest value of t.
151 if (t > 0) /* time_t is unsigned */
153 show(argv[i], t, TRUE);
154 t += SECSPERHOUR * HOURSPERDAY;
155 show(argv[i], t, TRUE);
157 (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1);
159 if (cutoff != NULL && t >= cuttime)
161 newt = t + SECSPERHOUR * 12;
162 if (cutoff != NULL && newt >= cuttime)
166 newtm = *localtime(&newt);
167 if (delta(&newtm, &tm) != (newt - t) ||
168 newtm.tm_isdst != tm.tm_isdst ||
169 strcmp(abbr(&newtm), buf) != 0) {
170 hunt(argv[i], t, newt);
171 (void) strncpy(buf, abbr(&newtm),
178 ** Get highest value of t.
181 if (t < 0) /* time_t is signed */
183 t -= SECSPERHOUR * HOURSPERDAY;
184 show(argv[i], t, TRUE);
185 t += SECSPERHOUR * HOURSPERDAY;
186 show(argv[i], t, TRUE);
188 if (fflush(stdout) || ferror(stdout)) {
189 (void) fprintf(stderr, "%s: Error writing standard output ",
191 (void) perror("standard output");
192 (void) exit(EXIT_FAILURE);
196 /* gcc -Wall pacifier */
210 static char loab[MAX_STRING_LENGTH];
212 lotm = *localtime(&lot);
213 (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1);
214 while ((hit - lot) >= 2) {
215 t = lot / 2 + hit / 2;
221 if (delta(&tm, &lotm) == (t - lot) &&
222 tm.tm_isdst == lotm.tm_isdst &&
223 strcmp(abbr(&tm), loab) == 0) {
228 show(name, lot, TRUE);
229 show(name, hit, TRUE);
239 result = newp->tm_hour - oldp->tm_hour;
241 result += HOURSPERDAY;
242 result *= SECSPERHOUR;
243 result += (newp->tm_min - oldp->tm_min) * SECSPERMIN;
244 return result + newp->tm_sec - oldp->tm_sec;
254 extern struct tm * localtime();
256 (void) printf("%-*s ", longest, zone);
258 (void) printf("%.24s GMT = ", asctime(gmtime(&t)));
260 (void) printf("%.24s", asctime(tmp));
261 if (*abbr(tmp) != '\0')
262 (void) printf(" %s", abbr(tmp));
264 (void) printf(" isdst=%d", tmp->tm_isdst);
266 (void) printf(" gmtoff=%ld", tmp->TM_GMTOFF);
267 #endif /* defined TM_GMTOFF */
276 register char * result;
278 if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1)
280 result = tzname[tmp->tm_isdst];
281 return (result == NULL) ? "" : result;