16f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic char	elsieid[] = "@(#)zdump.c	8.8";
26f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
36f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
46f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** This code has been made independent of the rest of the time
56f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** conversion package to increase confidence in the verification it provides.
66f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** You can use this code to help in verifying other implementations.
76f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
86f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
96f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * ICU note: Mr. Arthur David Olson (olsona@dc37a.nci.nih.gov) stated that
116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * "zdump.c is indeed in the public domain" in e-mail on Feb 22, 2007.
126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * This version of zdump.c is modified by ICU team to change output format
136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * and some additional options.
146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "stdio.h"	/* for stdout, stderr, perror */
186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "string.h"	/* for strcpy */
196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "sys/types.h"	/* for time_t */
206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "time.h"	/* for struct tm */
216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "stdlib.h"	/* for exit, malloc, atoi */
226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "float.h"	/* for FLT_MAX and DBL_MAX */
236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "ctype.h"	/* for isalpha et al. */
246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* Enable extensions and modifications for ICU. */
266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define ICU
276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "dirent.h"
306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef isascii
336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define isascii(x) 1
346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined isascii */
356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef ZDUMP_LO_YEAR
376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define ZDUMP_LO_YEAR	(-500)
386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined ZDUMP_LO_YEAR */
396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef ZDUMP_HI_YEAR
416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define ZDUMP_HI_YEAR	2500
426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined ZDUMP_HI_YEAR */
436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef MAX_STRING_LENGTH
456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define MAX_STRING_LENGTH	1024
466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined MAX_STRING_LENGTH */
476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef TRUE
496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define TRUE		1
506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined TRUE */
516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef FALSE
536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define FALSE		0
546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined FALSE */
556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef EXIT_SUCCESS
576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define EXIT_SUCCESS	0
586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined EXIT_SUCCESS */
596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef EXIT_FAILURE
616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define EXIT_FAILURE	1
626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined EXIT_FAILURE */
636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef SECSPERMIN
656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define SECSPERMIN	60
666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined SECSPERMIN */
676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef MINSPERHOUR
696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define MINSPERHOUR	60
706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined MINSPERHOUR */
716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef SECSPERHOUR
736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define SECSPERHOUR	(SECSPERMIN * MINSPERHOUR)
746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined SECSPERHOUR */
756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef HOURSPERDAY
776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define HOURSPERDAY	24
786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined HOURSPERDAY */
796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef EPOCH_YEAR
816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define EPOCH_YEAR	1970
826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined EPOCH_YEAR */
836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef TM_YEAR_BASE
856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define TM_YEAR_BASE	1900
866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined TM_YEAR_BASE */
876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef DAYSPERNYEAR
896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define DAYSPERNYEAR	365
906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined DAYSPERNYEAR */
916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef isleap
936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined isleap */
956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef isleap_sum
976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** See tzfile.h for details on isleap_sum.
996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
1006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
1016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined isleap_sum */
1026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define SECSPERDAY	((long) SECSPERHOUR * HOURSPERDAY)
1046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define SECSPERNYEAR	(SECSPERDAY * DAYSPERNYEAR)
1056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define SECSPERLYEAR	(SECSPERNYEAR + SECSPERDAY)
1066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef HAVE_GETTEXT
1086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define HAVE_GETTEXT 0
1096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
1106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if HAVE_GETTEXT
1116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "locale.h"	/* for setlocale */
1126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "libintl.h"
1136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* HAVE_GETTEXT */
1146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef GNUC_or_lint
1166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef lint
1176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define GNUC_or_lint
1186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#else /* !defined lint */
1196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef __GNUC__
1206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define GNUC_or_lint
1216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* defined __GNUC__ */
1226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined lint */
1236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined GNUC_or_lint */
1246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef INITIALIZE
1266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef GNUC_or_lint
1276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define INITIALIZE(x)	((x) = 0)
1286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#else /* !defined GNUC_or_lint */
1296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define INITIALIZE(x)
1306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined GNUC_or_lint */
1316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined INITIALIZE */
1326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
1346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** For the benefit of GNU folk...
1356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** `_(MSGID)' uses the current locale's message library string for MSGID.
1366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** The default is to use gettext if available, and use MSGID otherwise.
1376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
1386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef _
1406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if HAVE_GETTEXT
1416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define _(msgid) gettext(msgid)
1426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#else /* !HAVE_GETTEXT */
1436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define _(msgid) msgid
1446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !HAVE_GETTEXT */
1456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined _ */
1466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef TZ_DOMAIN
1486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define TZ_DOMAIN "tz"
1496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined TZ_DOMAIN */
1506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgextern char **	environ;
1526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgextern int	getopt(int argc, char * const argv[],
1536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			const char * options);
1546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgextern char *	optarg;
1556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgextern int	optind;
1566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgextern char *	tzname[2];
1576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic time_t	absolute_min_time;
1596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic time_t	absolute_max_time;
1606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic size_t	longest;
1616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic char *	progname;
1626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int	warned;
1636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic char *	abbr(struct tm * tmp);
1656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void	abbrok(const char * abbrp, const char * zone);
1666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic long	delta(struct tm * newp, struct tm * oldp);
1676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void	dumptime(const struct tm * tmp);
1686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic time_t	hunt(char * name, time_t lot, time_t	hit);
1696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void	setabsolutes(void);
1706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void	show(char * zone, time_t t, int v);
1716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *	tformat(void);
1726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic time_t	yeartot(long y);
1736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
1746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgtypedef struct listentry {
1756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	char *		name;
1766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct listentry *	next;
1776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org} listentry;
1786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic time_t	huntICU(char * name, time_t lot, time_t	hit, FILE *fp);
1806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void	dumptimeICU(FILE * fp, time_t t);
1816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void	showICU(FILE * fp, char * zone, time_t t1, time_t t2);
1826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int	getall(struct listentry ** namelist);
1836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void getzones(char * basedir, char * subdir, struct listentry ** last, int * count);
1846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
1856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifndef TYPECHECK
1876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define my_localtime	localtime
1886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#else /* !defined TYPECHECK */
1896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic struct tm *
1906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgmy_localtime(tp)
1916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgtime_t *	tp;
1926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register struct tm *	tmp;
1946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tmp = localtime(tp);
1966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (tp != NULL && tmp != NULL) {
1976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		struct tm	tm;
1986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		register time_t	t;
1996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		tm = *tmp;
2016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t = mktime(&tm);
2026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (t - *tp >= 1 || *tp - t >= 1) {
2036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fflush(stdout);
2046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, "\n%s: ", progname);
2056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, tformat(), *tp);
2066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " ->");
2076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " year=%d", tmp->tm_year);
2086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " mon=%d", tmp->tm_mon);
2096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " mday=%d", tmp->tm_mday);
2106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " hour=%d", tmp->tm_hour);
2116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " min=%d", tmp->tm_min);
2126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " sec=%d", tmp->tm_sec);
2136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " isdst=%d", tmp->tm_isdst);
2146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, " -> ");
2156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, tformat(), t);
2166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr, "\n");
2176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
2186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
2196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return tmp;
2206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !defined TYPECHECK */
2226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
2246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgabbrok(abbrp, zone)
2256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgconst char * const	abbrp;
2266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgconst char * const	zone;
2276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register const char *	cp;
2296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register char *		wp;
2306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (warned)
2326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return;
2336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	cp = abbrp;
2346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	wp = NULL;
2356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	while (isascii((unsigned char) *cp) && isalpha((unsigned char) *cp))
2366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		++cp;
2376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (cp - abbrp == 0)
2386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		wp = _("lacks alphabetic at start");
2396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	else if (cp - abbrp < 3)
2406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		wp = _("has fewer than 3 alphabetics");
2416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	else if (cp - abbrp > 6)
2426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		wp = _("has more than 6 alphabetics");
2436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (wp == NULL && (*cp == '+' || *cp == '-')) {
2446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		++cp;
2456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (isascii((unsigned char) *cp) &&
2466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			isdigit((unsigned char) *cp))
2476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				if (*cp++ == '1' && *cp >= '0' && *cp <= '4')
2486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					++cp;
2496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (*cp != '\0')
2506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			wp = _("differs from POSIX standard");
2516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
2526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (wp == NULL)
2536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return;
2546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) fflush(stdout);
2556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) fprintf(stderr,
2566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		_("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"),
2576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		progname, zone, abbrp, wp);
2586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	warned = TRUE;
2596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
2626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgusage(const char *progname, FILE *stream, int status)
2636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) fprintf(stream,
2656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org_("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n\
2666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org\n\
2676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgReport bugs to tz@elsie.nci.nih.gov.\n"),
2686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		       progname, progname);
2696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	exit(status);
2706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgint
2736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgmain(argc, argv)
2746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgint	argc;
2756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgchar *	argv[];
2766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register int		i;
2786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register int		c;
2796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register int		vflag;
2806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register char *		cutarg;
2816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register long		cutloyear = ZDUMP_LO_YEAR;
2826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register long		cuthiyear = ZDUMP_HI_YEAR;
2836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register time_t		cutlotime;
2846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register time_t		cuthitime;
2856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register char **	fakeenv;
2866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	time_t			now;
2876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	time_t			t;
2886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	time_t			newt;
2896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct tm		tm;
2906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct tm		newtm;
2916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register struct tm *	tmp;
2926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register struct tm *	newtmp;
2936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
2946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	int		nextopt;
2956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	char *	dirarg;
2966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	int		aflag;
2976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	int		iflag;
2986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	listentry *	namelist = NULL;
2996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	FILE *	fp = stdout;
3006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
3016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	INITIALIZE(cutlotime);
3036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	INITIALIZE(cuthitime);
3046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if HAVE_GETTEXT
3056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) setlocale(LC_ALL, "");
3066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef TZ_DOMAINDIR
3076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
3086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* defined TEXTDOMAINDIR */
3096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) textdomain(TZ_DOMAIN);
3106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* HAVE_GETTEXT */
3116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	progname = argv[0];
3126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	for (i = 1; i < argc; ++i)
3136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (strcmp(argv[i], "--version") == 0) {
3146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) printf("%s\n", elsieid);
3156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			exit(EXIT_SUCCESS);
3166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		} else if (strcmp(argv[i], "--help") == 0) {
3176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			usage(progname, stdout, EXIT_SUCCESS);
3186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
3196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	vflag = 0;
3206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	cutarg = NULL;
3216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
3226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	aflag = 0;
3236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	iflag = 0;
3246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	dirarg = NULL;
3256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	nextopt = 1;
3266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	while(nextopt) {
3276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		c = getopt(argc, argv, "ac:d:iv");
3286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		switch(c) {
3296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		case 'a':
3306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			aflag = 1;
3316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			break;
3326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		case 'c':
3336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			cutarg = optarg;
3346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			break;
3356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		case 'd':
3366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			dirarg = optarg;
3376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			break;
3386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		case 'i':
3396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			iflag = 1;
3406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			break;
3416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		case 'v':
3426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			vflag = 1;
3436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			break;
3446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		default:
3456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			nextopt = 0;
3466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			break;
3476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
3486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
3496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if ((c != EOF && c != -1) ||
3506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(optind == argc - 1 && strcmp(argv[optind], "=") == 0)) {
3516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr,
3526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				_("%s: usage is %s [ --version ] [ -a ] [ -v ] [ -i ] [ -c [loyear,]hiyear ] [ -d dir ] [ zonename ... ]\n"),
3536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				progname, progname);
3546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			exit(EXIT_FAILURE);
3556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
3566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (dirarg != NULL) {
3586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		DIR *	dp;
3596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/* create the output directory */
3606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		mkdir(dirarg, 0777);
3616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if ((dp = opendir(dirarg)) == NULL) {
3626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			fprintf(stderr, "cannot create the target directory");
3636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			exit(EXIT_FAILURE);
3646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
3656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		closedir(dp);
3666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
3676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#else
3686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	while ((c = getopt(argc, argv, "c:v")) == 'c' || c == 'v')
3696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (c == 'v')
3706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			vflag = 1;
3716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		else	cutarg = optarg;
3726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if ((c != EOF && c != -1) ||
3736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(optind == argc - 1 && strcmp(argv[optind], "=") == 0)) {
3746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			usage(progname, stderr, EXIT_FAILURE);
3756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
3766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
3776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (vflag) {
3786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (cutarg != NULL) {
3796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			long	lo;
3806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			long	hi;
3816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			char	dummy;
3826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (sscanf(cutarg, "%ld%c", &hi, &dummy) == 1) {
3846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				cuthiyear = hi;
3856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			} else if (sscanf(cutarg, "%ld,%ld%c",
3866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				&lo, &hi, &dummy) == 2) {
3876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					cutloyear = lo;
3886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					cuthiyear = hi;
3896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			} else {
3906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org(void) fprintf(stderr, _("%s: wild -c argument %s\n"),
3916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					progname, cutarg);
3926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				exit(EXIT_FAILURE);
3936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
3946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
3956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		setabsolutes();
3966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		cutlotime = yeartot(cutloyear);
3976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		cuthitime = yeartot(cuthiyear);
3986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
3996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
4016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (aflag) {
4026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/* get all available zones */
4036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		char ** fakeargv;
4046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		int i;
4056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		int count;
4066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		count = getall(&namelist);
4086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		fakeargv = (char **) malloc((size_t) (argc + count) * sizeof *argv);
4106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/*
4116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if ((fakeargv = (char **) malloc((size_t) (argc + count) * sizeof *argv)) == NULL) {
4126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			exit(EXIT_FAILURE);
4136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
4146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		*/
4156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		for (i = 0; i < argc; i++) {
4166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			fakeargv[i] = argv[i];
4176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
4186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		for (i = 0; i < count; i++) {
4196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			fakeargv[i + argc] = namelist->name;
4206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			namelist = namelist->next;
4216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
4226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		argv = fakeargv;
4236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		argc += count;
4246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
4256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
4266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) time(&now);
4276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	longest = 0;
4286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	for (i = optind; i < argc; ++i)
4296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (strlen(argv[i]) > longest)
4306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			longest = strlen(argv[i]);
4316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	{
4326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		register int	from;
4336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		register int	to;
4346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		for (i = 0; environ[i] != NULL; ++i)
4366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			continue;
4376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		fakeenv = (char **) malloc((size_t) ((i + 2) *
4386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			sizeof *fakeenv));
4396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (fakeenv == NULL ||
4406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(fakeenv[0] = (char *) malloc(longest + 4)) == NULL) {
4416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					(void) perror(progname);
4426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					exit(EXIT_FAILURE);
4436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
4446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		to = 0;
4456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) strcpy(fakeenv[to++], "TZ=");
4466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		for (from = 0; environ[from] != NULL; ++from)
4476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (strncmp(environ[from], "TZ=", 3) != 0)
4486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				fakeenv[to++] = environ[from];
4496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		fakeenv[to] = NULL;
4506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		environ = fakeenv;
4516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
4526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	for (i = optind; i < argc; ++i) {
4536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		static char	buf[MAX_STRING_LENGTH];
4546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) strcpy(&fakeenv[0][3], argv[i]);
4566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (!vflag) {
4576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			show(argv[i], now, FALSE);
4586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			continue;
4596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
4606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
4616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		fp = NULL;
4626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (iflag) {
4636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (dirarg == NULL) {
4646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				/* we want to display a zone name here */
4656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				if (i != optind) {
4666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					printf("\n");
4676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				}
4686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				printf("ZONE: %s\n", argv[i]);
4696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			} else {
4706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				int		zstart;
4716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				char	path[FILENAME_MAX + 1];
4726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				strcpy(path, dirarg);
4736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				strcat(path, "/");
4746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				zstart = strlen(path);
4756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				strcat(path, argv[i]);
4766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				/* replace '/' with '-' */
4776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				while(path[++zstart] != 0) {
4786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					if (path[zstart] == '/') {
4796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org						path[zstart] = '-';
4806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					}
4816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				}
4826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				if ((fp = fopen(path, "w")) == NULL) {
4836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					fprintf(stderr, "cannot create output file %s\n", path);
4846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					exit(EXIT_FAILURE);
4856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				}
4866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
4876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
4886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
4896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		warned = FALSE;
4906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t = absolute_min_time;
4916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
4926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/* skip displaying info for the lowest time, which is actually not
4936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		 * a transition when -i option is set */
4946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (!iflag) {
4956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
4966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		show(argv[i], t, TRUE);
4976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t += SECSPERHOUR * HOURSPERDAY;
4986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		show(argv[i], t, TRUE);
4996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
5006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
5016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
5026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (t < cutlotime)
5036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			t = cutlotime;
5046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		tmp = my_localtime(&t);
5056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (tmp != NULL) {
5066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			tm = *tmp;
5076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) strncpy(buf, abbr(&tm), (sizeof buf) - 1);
5086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
5096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		for ( ; ; ) {
5106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (t >= cuthitime || t >= cuthitime - SECSPERHOUR * 12)
5116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				break;
5126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			newt = t + SECSPERHOUR * 12;
5136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			newtmp = localtime(&newt);
5146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (newtmp != NULL)
5156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				newtm = *newtmp;
5166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
5176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (iflag) {
5186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				/* We  do not want to capture transitions just for
5196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				 * abbreviated zone name changes */
5206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) :
5216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					(delta(&newtm, &tm) != (newt - t) ||
5226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					newtm.tm_isdst != tm.tm_isdst)) {
5236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org						newt = huntICU(argv[i], t, newt, fp);
5246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org						newtmp = localtime(&newt);
5256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org						if (newtmp != NULL) {
5266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org							newtm = *newtmp;
5276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org							(void) strncpy(buf,
5286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org								abbr(&newtm),
5296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org								(sizeof buf) - 1);
5306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org						}
5316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				}
5326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			} else {
5336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
5346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if ((tmp == NULL || newtmp == NULL) ? (tmp != newtmp) :
5356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				(delta(&newtm, &tm) != (newt - t) ||
5366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				newtm.tm_isdst != tm.tm_isdst ||
5376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				strcmp(abbr(&newtm), buf) != 0)) {
5386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					newt = hunt(argv[i], t, newt);
5396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					newtmp = localtime(&newt);
5406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					if (newtmp != NULL) {
5416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org						newtm = *newtmp;
5426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org						(void) strncpy(buf,
5436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org							abbr(&newtm),
5446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org							(sizeof buf) - 1);
5456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org					}
5466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
5476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
5486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
5496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
5506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			t = newt;
5516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			tm = newtm;
5526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			tmp = newtmp;
5536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
5546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
5556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (!iflag) {
5566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/* skip displaying info for the highest time, which is actually not
5576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		 * a transition when -i option is used*/
5586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
5596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t = absolute_max_time;
5606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t -= SECSPERHOUR * HOURSPERDAY;
5616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		show(argv[i], t, TRUE);
5626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t += SECSPERHOUR * HOURSPERDAY;
5636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		show(argv[i], t, TRUE);
5646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
5666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
5676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/* close file */
5686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (fp != NULL) {
5696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			fclose(fp);
5706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
5716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
5726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
5736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (fflush(stdout) || ferror(stdout)) {
5746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) fprintf(stderr, "%s: ", progname);
5756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) perror(_("Error writing to standard output"));
5766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		exit(EXIT_FAILURE);
5776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
5786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
5796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (aflag) {
5806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		struct listentry *	entry = namelist;
5816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		struct listentry *	next;
5826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		while (entry != NULL) {
5836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			free(entry->name);
5846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			next = entry->next;
5856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			free(entry);
5866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			entry = next;
5876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
5886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
5896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
5906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	exit(EXIT_SUCCESS);
5916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	/* If exit fails to exit... */
5926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return EXIT_FAILURE;
5936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
5946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
5966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgsetabsolutes(void)
5976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
5986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (0.5 == (time_t) 0.5) {
5996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/*
6006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		** time_t is floating.
6016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		*/
6026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (sizeof (time_t) == sizeof (float)) {
6036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			absolute_min_time = (time_t) -FLT_MAX;
6046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			absolute_max_time = (time_t) FLT_MAX;
6056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		} else if (sizeof (time_t) == sizeof (double)) {
6066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			absolute_min_time = (time_t) -DBL_MAX;
6076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			absolute_max_time = (time_t) DBL_MAX;
6086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		} else {
6096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) fprintf(stderr,
6106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org_("%s: use of -v on system with floating time_t other than float or double\n"),
6116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				progname);
6126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			exit(EXIT_FAILURE);
6136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
6146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	} else if (0 > (time_t) -1) {
6156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/*
6166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		** time_t is signed.  Assume overflow wraps around.
6176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		*/
6186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		time_t t = 0;
6196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		time_t t1 = 1;
6206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		while (t < t1) {
6226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			t = t1;
6236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			t1 = 2 * t1 + 1;
6246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
6256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		absolute_max_time = t;
6276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t = -t;
6286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		absolute_min_time = t - 1;
6296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (t < absolute_min_time)
6306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			absolute_min_time = t;
6316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	} else {
6326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/*
6336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		** time_t is unsigned.
6346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		*/
6356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		absolute_min_time = 0;
6366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		absolute_max_time = absolute_min_time - 1;
6376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
6386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic time_t
6416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgyeartot(y)
6426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgconst long	y;
6436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register long	myy;
6456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register long	seconds;
6466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register time_t	t;
6476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	myy = EPOCH_YEAR;
6496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	t = 0;
6506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	while (myy != y) {
6516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (myy < y) {
6526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR;
6536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			++myy;
6546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (t > absolute_max_time - seconds) {
6556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				t = absolute_max_time;
6566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				break;
6576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
6586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			t += seconds;
6596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		} else {
6606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			--myy;
6616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			seconds = isleap(myy) ? SECSPERLYEAR : SECSPERNYEAR;
6626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (t < absolute_min_time + seconds) {
6636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				t = absolute_min_time;
6646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				break;
6656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
6666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			t -= seconds;
6676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
6686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
6696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return t;
6706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic time_t
6736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orghunt(char *name, time_t lot, time_t hit)
6746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	time_t			t;
6766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	long			diff;
6776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct tm		lotm;
6786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register struct tm *	lotmp;
6796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct tm		tm;
6806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register struct tm *	tmp;
6816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	char			loab[MAX_STRING_LENGTH];
6826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	lotmp = my_localtime(&lot);
6846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (lotmp != NULL) {
6856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		lotm = *lotmp;
6866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1);
6876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
6886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	for ( ; ; ) {
6896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		diff = (long) (hit - lot);
6906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (diff < 2)
6916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			break;
6926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t = lot;
6936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t += diff / 2;
6946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (t <= lot)
6956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			++t;
6966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		else if (t >= hit)
6976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			--t;
6986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		tmp = my_localtime(&t);
6996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (tmp != NULL)
7006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			tm = *tmp;
7016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if ((lotmp == NULL || tmp == NULL) ? (lotmp == tmp) :
7026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(delta(&tm, &lotm) == (t - lot) &&
7036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			tm.tm_isdst == lotm.tm_isdst &&
7046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			strcmp(abbr(&tm), loab) == 0)) {
7056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				lot = t;
7066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				lotm = tm;
7076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				lotmp = tmp;
7086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		} else	hit = t;
7096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
7106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	show(name, lot, TRUE);
7116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	show(name, hit, TRUE);
7126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return hit;
7136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
7166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** Thanks to Paul Eggert for logic used in delta.
7176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
7186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic long
7206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgdelta(newp, oldp)
7216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstruct tm *	newp;
7226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstruct tm *	oldp;
7236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
7246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register long	result;
7256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register int	tmy;
7266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (newp->tm_year < oldp->tm_year)
7286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return -delta(oldp, newp);
7296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result = 0;
7306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	for (tmy = oldp->tm_year; tmy < newp->tm_year; ++tmy)
7316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		result += DAYSPERNYEAR + isleap_sum(tmy, TM_YEAR_BASE);
7326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result += newp->tm_yday - oldp->tm_yday;
7336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result *= HOURSPERDAY;
7346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result += newp->tm_hour - oldp->tm_hour;
7356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result *= MINSPERHOUR;
7366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result += newp->tm_min - oldp->tm_min;
7376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result *= SECSPERMIN;
7386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result += newp->tm_sec - oldp->tm_sec;
7396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return result;
7406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
7436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgshow(char *zone, time_t t, int v)
7446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
7456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register struct tm *	tmp;
7466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) printf("%-*s  ", (int) longest, zone);
7486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (v) {
7496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		tmp = gmtime(&t);
7506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (tmp == NULL) {
7516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) printf(tformat(), t);
7526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		} else {
7536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			dumptime(tmp);
7546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) printf(" UTC");
7556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
7566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) printf(" = ");
7576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
7586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tmp = my_localtime(&t);
7596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	dumptime(tmp);
7606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (tmp != NULL) {
7616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (*abbr(tmp) != '\0')
7626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) printf(" %s", abbr(tmp));
7636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (v) {
7646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) printf(" isdst=%d", tmp->tm_isdst);
7656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef TM_GMTOFF
7666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(void) printf(" gmtoff=%ld", tmp->TM_GMTOFF);
7676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* defined TM_GMTOFF */
7686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
7696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
7706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) printf("\n");
7716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (tmp != NULL && *abbr(tmp) != '\0')
7726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		abbrok(abbr(tmp), zone);
7736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic char *
7766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgabbr(tmp)
7776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstruct tm *	tmp;
7786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
7796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register char *	result;
7806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	static char	nada;
7816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1)
7836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return &nada;
7846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	result = tzname[tmp->tm_isdst];
7856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return (result == NULL) ? &nada : result;
7866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
7896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** The code below can fail on certain theoretical systems;
7906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org** it works on all known real-world systems as of 2004-12-30.
7916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
7926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char *
7946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgtformat(void)
7956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
7966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (0.5 == (time_t) 0.5) {	/* floating */
7976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (sizeof (time_t) > sizeof (double))
7986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			return "%Lg";
7996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return "%g";
8006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
8016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (0 > (time_t) -1) {		/* signed */
8026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (sizeof (time_t) > sizeof (long))
8036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			return "%lld";
8046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (sizeof (time_t) > sizeof (int))
8056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			return "%ld";
8066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return "%d";
8076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
8086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (sizeof (time_t) > sizeof (unsigned long))
8096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return "%llu";
8106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (sizeof (time_t) > sizeof (unsigned int))
8116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return "%lu";
8126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return "%u";
8136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void
8166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgdumptime(timeptr)
8176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgregister const struct tm *	timeptr;
8186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
8196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	static const char	wday_name[][3] = {
8206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
8216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	};
8226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	static const char	mon_name[][3] = {
8236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
8246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
8256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	};
8266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register const char *	wn;
8276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register const char *	mn;
8286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register int		lead;
8296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register int		trail;
8306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (timeptr == NULL) {
8326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) printf("NULL");
8336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		return;
8346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
8356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	/*
8366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	** The packaged versions of localtime and gmtime never put out-of-range
8376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	** values in tm_wday or tm_mon, but since this code might be compiled
8386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	** with other (perhaps experimental) versions, paranoia is in order.
8396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	*/
8406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (timeptr->tm_wday < 0 || timeptr->tm_wday >=
8416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(int) (sizeof wday_name / sizeof wday_name[0]))
8426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			wn = "???";
8436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	else		wn = wday_name[timeptr->tm_wday];
8446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (timeptr->tm_mon < 0 || timeptr->tm_mon >=
8456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(int) (sizeof mon_name / sizeof mon_name[0]))
8466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			mn = "???";
8476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	else		mn = mon_name[timeptr->tm_mon];
8486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	(void) printf("%.3s %.3s%3d %.2d:%.2d:%.2d ",
8496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		wn, mn,
8506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		timeptr->tm_mday, timeptr->tm_hour,
8516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		timeptr->tm_min, timeptr->tm_sec);
8526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define DIVISOR	10
8536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	trail = timeptr->tm_year % DIVISOR + TM_YEAR_BASE % DIVISOR;
8546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	lead = timeptr->tm_year / DIVISOR + TM_YEAR_BASE / DIVISOR +
8556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		trail / DIVISOR;
8566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	trail %= DIVISOR;
8576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (trail < 0 && lead > 0) {
8586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		trail += DIVISOR;
8596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		--lead;
8606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	} else if (lead < 0 && trail > 0) {
8616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		trail -= DIVISOR;
8626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		++lead;
8636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
8646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (lead == 0)
8656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) printf("%d", trail);
8666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	else	(void) printf("%d%d", lead, ((trail < 0) ? -trail : trail));
8676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#ifdef ICU
8706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic time_t
8716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orghuntICU(char *name, time_t lot, time_t hit, FILE * fp)
8726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
8736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	time_t			t;
8746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	long			diff;
8756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct tm		lotm;
8766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register struct tm *	lotmp;
8776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct tm		tm;
8786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register struct tm *	tmp;
8796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	char			loab[MAX_STRING_LENGTH];
8806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	lotmp = my_localtime(&lot);
8826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (lotmp != NULL) {
8836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		lotm = *lotmp;
8846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		(void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1);
8856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
8866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	for ( ; ; ) {
8876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		diff = (long) (hit - lot);
8886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (diff < 2)
8896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			break;
8906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t = lot;
8916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		t += diff / 2;
8926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (t <= lot)
8936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			++t;
8946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		else if (t >= hit)
8956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			--t;
8966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		tmp = my_localtime(&t);
8976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (tmp != NULL)
8986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			tm = *tmp;
8996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/* We  do not want to capture transitions just for
9006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		 * abbreviated zone name changes */
9016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if ((lotmp == NULL || tmp == NULL) ? (lotmp == tmp) :
9026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(delta(&tm, &lotm) == (t - lot) &&
9036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			tm.tm_isdst == lotm.tm_isdst)) {
9046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				lot = t;
9056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				lotm = tm;
9066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				lotmp = tmp;
9076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		} else	hit = t;
9086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
9096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	showICU(fp, name, lot, hit);
9106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return hit;
9116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
9126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void showICU(FILE * fp, char *zone, time_t t1, time_t t2)
9146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
9156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (fp == NULL) {
9166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		fp = stdout;
9176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
9186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	dumptimeICU(fp, t1);
9196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, " > ");
9206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	dumptimeICU(fp, t2);
9216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, "\n");
9226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
9236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void dumptimeICU(FILE * fp, time_t t)
9256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
9266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	static const char	wday_name[][3] = {
9276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
9286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	};
9296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct tm gmt;
9306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct tm loc;
9316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register int		lead;
9326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	register int		trail;
9336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	long	offset;
9346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	long	hour, min, sec;
9356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	loc = *my_localtime(&t);
9376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	trail = loc.tm_year % DIVISOR + TM_YEAR_BASE % DIVISOR;
9396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	lead = loc.tm_year / DIVISOR + TM_YEAR_BASE / DIVISOR + trail / DIVISOR;
9406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	trail %= DIVISOR;
9416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (trail < 0 && lead > 0) {
9426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		trail += DIVISOR;
9436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		--lead;
9446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	} else if (lead < 0 && trail > 0) {
9456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		trail -= DIVISOR;
9466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		++lead;
9476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
9486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, "%04d-%02d-%02d", lead * DIVISOR + trail, loc.tm_mon + 1, loc.tm_mday);
9506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, " %.3s ", wday_name[loc.tm_wday]);
9516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, "%02d:%02d:%02d", loc.tm_hour, loc.tm_min, loc.tm_sec);
9526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	gmt = *gmtime(&t);
9546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	offset = delta(&loc, &gmt);
9556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (offset < 0) {
9566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		offset = -offset;
9576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		fprintf(fp, "-");
9586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	} else {
9596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		fprintf(fp, "+");
9606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
9616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	sec = offset % 60;
9636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	offset = (offset - sec) / 60;
9646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	min = offset % 60;
9656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	hour = offset / 60;
9666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, "%02d", hour);
9686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, "%02d", min);
9696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, "%02d", sec);
9706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	fprintf(fp, "[DST=%d]", loc.tm_isdst);
9716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
9726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int getall(struct listentry ** namelist) {
9746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	int count = 0;
9756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct listentry dummyentry;
9766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct listentry *	last = &dummyentry;
9776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	getzones(TZDIR, NULL, &last, &count);
9796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (count > 0) {
9806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		*namelist = dummyentry.next;
9816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
9826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	return count;
9846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
9856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void getzones(char * basedir, char * relpath, struct listentry ** last, int * count) {
9876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	char	path[FILENAME_MAX + 1];
9886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	struct	dirent *	dir;
9896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	DIR *	dp;
9906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	strcpy(path, basedir);
9926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if (relpath != NULL) {
9936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		strcat(path, "/");
9946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		strcat(path, relpath);
9956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
9966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	if ((dp = opendir(path)) == NULL) {
9986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/* file */
9996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		if (strstr(relpath, ".tab") == NULL && strcmp(relpath, "Etc/Unknown") != 0) {
10006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			char *		pzonename;
10016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			listentry *	pentry;
10026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if ((pzonename = malloc(strlen(relpath) + 1)) == NULL) {
10046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				exit(EXIT_FAILURE);
10056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
10066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			strcpy(pzonename, relpath);
10076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if ((pentry = malloc(sizeof(listentry))) == NULL) {
10096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				exit(EXIT_FAILURE);
10106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
10116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			pentry->name = pzonename;
10136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			pentry->next = NULL;
10146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(*last)->next = pentry;
10156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			*last = pentry;
10166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			(*count)++;
10176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
10186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	} else {
10196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		/* directory */
10206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		while ((dir = readdir(dp)) != NULL) {
10216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			char	subpath[FILENAME_MAX + 1];
10226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (strcmp(dir->d_name, ".") == 0
10246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				|| strcmp(dir->d_name, "..") == 0) {
10256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				continue;
10266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
10276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			if (relpath != NULL) {
10286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				strcpy(subpath, relpath);
10296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				strcat(subpath, "/");
10306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				strcat(subpath, dir->d_name);
10316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			} else {
10326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org				strcpy(subpath, dir->d_name);
10336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			}
10346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org			getzones(basedir, subpath, last, count);
10356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		}
10366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		closedir(dp);
10376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
10386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
10396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
1040