summaryrefslogtreecommitdiff
path: root/lib/libc/time/zdump.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2004-10-18 22:33:44 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2004-10-18 22:33:44 +0000
commit41db8ca9db05facd02607c875e089f625ef045ed (patch)
treeaa3b9310139323a730e1f792a2fd9436b7190434 /lib/libc/time/zdump.c
parenta43112dd39844076189de66b2714fe7ae5d6f3a1 (diff)
Update to tzcode2004e from elsie.nci.nih.gov
Diffstat (limited to 'lib/libc/time/zdump.c')
-rw-r--r--lib/libc/time/zdump.c76
1 files changed, 55 insertions, 21 deletions
diff --git a/lib/libc/time/zdump.c b/lib/libc/time/zdump.c
index baaec05b26a..df9669979a9 100644
--- a/lib/libc/time/zdump.c
+++ b/lib/libc/time/zdump.c
@@ -5,8 +5,8 @@
#if defined(LIBC_SCCS) && !defined(lint) && !defined(NOID)
static char elsieid[] = "@(#)zdump.c 7.31";
-static char rcsid[] = "$OpenBSD: zdump.c,v 1.13 2004/04/01 11:37:02 jmc Exp $";
-#endif /* LIBC_SCCS and not lint */
+static char rcsid[] = "$OpenBSD: zdump.c,v 1.14 2004/10/18 22:33:43 millert Exp $";
+static char elsieid[] = "@(#)zdump.c 7.40";
/*
** This code has been made independent of the rest of the time
@@ -15,7 +15,7 @@ static char rcsid[] = "$OpenBSD: zdump.c,v 1.13 2004/04/01 11:37:02 jmc Exp $";
*/
#include "stdio.h" /* for stdout, stderr, perror */
-#include "string.h" /* for strcpy */
+#include "string.h" /* for strlcpy */
#include "sys/types.h" /* for time_t */
#include "time.h" /* for struct tm */
#include "stdlib.h" /* for exit, malloc, atoi */
@@ -72,16 +72,15 @@ static char rcsid[] = "$OpenBSD: zdump.c,v 1.13 2004/04/01 11:37:02 jmc Exp $";
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
#endif /* !defined isleap */
-#if HAVE_GETTEXT - 0
+#if HAVE_GETTEXT
#include "locale.h" /* for setlocale */
#include "libintl.h"
-#endif /* HAVE_GETTEXT - 0 */
+#endif /* HAVE_GETTEXT */
#ifndef GNUC_or_lint
#ifdef lint
#define GNUC_or_lint
-#endif /* defined lint */
-#ifndef lint
+#else /* !defined lint */
#ifdef __GNUC__
#define GNUC_or_lint
#endif /* defined __GNUC__ */
@@ -91,8 +90,7 @@ static char rcsid[] = "$OpenBSD: zdump.c,v 1.13 2004/04/01 11:37:02 jmc Exp $";
#ifndef INITIALIZE
#ifdef GNUC_or_lint
#define INITIALIZE(x) ((x) = 0)
-#endif /* defined GNUC_or_lint */
-#ifndef GNUC_or_lint
+#else /* !defined GNUC_or_lint */
#define INITIALIZE(x)
#endif /* !defined GNUC_or_lint */
#endif /* !defined INITIALIZE */
@@ -104,11 +102,11 @@ static char rcsid[] = "$OpenBSD: zdump.c,v 1.13 2004/04/01 11:37:02 jmc Exp $";
*/
#ifndef _
-#if HAVE_GETTEXT - 0
+#if HAVE_GETTEXT
#define _(msgid) gettext(msgid)
-#else /* !(HAVE_GETTEXT - 0) */
+#else /* !HAVE_GETTEXT */
#define _(msgid) msgid
-#endif /* !(HAVE_GETTEXT - 0) */
+#endif /* !HAVE_GETTEXT */
#endif /* !defined _ */
#ifndef TZ_DOMAIN
@@ -118,8 +116,7 @@ static char rcsid[] = "$OpenBSD: zdump.c,v 1.13 2004/04/01 11:37:02 jmc Exp $";
#ifndef P
#ifdef __STDC__
#define P(x) x
-#endif /* defined __STDC__ */
-#ifndef __STDC__
+#else /* !defined __STDC__ */
#define P(x) ()
#endif /* !defined __STDC__ */
#endif /* !defined P */
@@ -137,6 +134,7 @@ static time_t hunt P((char * name, time_t lot, time_t hit));
static size_t longest;
static char * progname;
static void show P((char * zone, time_t t, int v));
+static void dumptime P((const struct tm * tmp));
int
main(argc, argv)
@@ -158,13 +156,13 @@ char * argv[];
struct tm newtm;
INITIALIZE(cuttime);
-#if HAVE_GETTEXT - 0
+#if HAVE_GETTEXT
(void) setlocale(LC_MESSAGES, "");
#ifdef TZ_DOMAINDIR
(void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
-#endif /* defined(TEXTDOMAINDIR) */
+#endif /* defined TEXTDOMAINDIR */
(void) textdomain(TZ_DOMAIN);
-#endif /* HAVE_GETTEXT - 0 */
+#endif /* HAVE_GETTEXT */
progname = argv[0];
vflag = 0;
cutoff = NULL;
@@ -326,7 +324,7 @@ struct tm * oldp;
return -delta(oldp, newp);
result = 0;
for (tmy = oldp->tm_year; tmy < newp->tm_year; ++tmy)
- result += DAYSPERNYEAR + isleap(tmy + TM_YEAR_BASE);
+ result += DAYSPERNYEAR + isleap(tmy + (long) TM_YEAR_BASE);
result += newp->tm_yday - oldp->tm_yday;
result *= HOURSPERDAY;
result += newp->tm_hour - oldp->tm_hour;
@@ -346,10 +344,12 @@ int v;
struct tm * tmp;
(void) printf("%-*s ", (int) longest, zone);
- if (v)
- (void) printf("%.24s UTC = ", asctime(gmtime(&t)));
+ if (v) {
+ dumptime(gmtime(&t));
+ (void) printf(" UTC = ");
+ }
tmp = localtime(&t);
- (void) printf("%.24s", asctime(tmp));
+ dumptime(tmp);
if (*abbr(tmp) != '\0')
(void) printf(" %s", abbr(tmp));
if (v) {
@@ -373,3 +373,37 @@ struct tm * tmp;
result = tzname[tmp->tm_isdst];
return (result == NULL) ? &nada : result;
}
+
+static void
+dumptime(timeptr)
+register const struct tm * timeptr;
+{
+ static const char wday_name[][3] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+ };
+ static const char mon_name[][3] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ };
+ register const char * wn;
+ register const char * mn;
+
+ /*
+ ** The packaged versions of localtime and gmtime never put out-of-range
+ ** values in tm_wday or tm_mon, but since this code might be compiled
+ ** with other (perhaps experimental) versions, paranoia is in order.
+ */
+ if (timeptr->tm_wday < 0 || timeptr->tm_wday >=
+ (int) (sizeof wday_name / sizeof wday_name[0]))
+ wn = "???";
+ else wn = wday_name[timeptr->tm_wday];
+ if (timeptr->tm_mon < 0 || timeptr->tm_mon >=
+ (int) (sizeof mon_name / sizeof mon_name[0]))
+ mn = "???";
+ else mn = mon_name[timeptr->tm_mon];
+ (void) printf("%.3s %.3s%3d %.2d:%.2d:%.2d %ld",
+ wn, mn,
+ timeptr->tm_mday, timeptr->tm_hour,
+ timeptr->tm_min, timeptr->tm_sec,
+ timeptr->tm_year + (long) TM_YEAR_BASE);
+}