From e6c0663544a1202063aa14b8b5be71a6d201e962 Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 17 Aug 2011 13:48:11 +0000 Subject: [PATCH] Eliminate non-literal format strings, and now that gcc warns, kill y2k format warning. --- usr.bin/w/Makefile | 4 +++- usr.bin/w/pr_time.c | 27 ++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/usr.bin/w/Makefile b/usr.bin/w/Makefile index 307b793a8b03..e736de7aabcd 100644 --- a/usr.bin/w/Makefile +++ b/usr.bin/w/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.19 2003/02/26 15:01:09 christos Exp $ +# $NetBSD: Makefile,v 1.20 2011/08/17 13:48:11 christos Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93 .include @@ -13,4 +13,6 @@ CPPFLAGS+= -DSUPPORT_UTMP -DSUPPORT_UTMPX .PATH: ${NETBSDSRCDIR}/bin/ps +COPTS.pr_time.c += -Wno-format-y2k + .include diff --git a/usr.bin/w/pr_time.c b/usr.bin/w/pr_time.c index f558ba5f4d3a..a64cb696204d 100644 --- a/usr.bin/w/pr_time.c +++ b/usr.bin/w/pr_time.c @@ -1,4 +1,4 @@ -/* $NetBSD: pr_time.c,v 1.17 2009/04/14 07:41:36 lukem Exp $ */ +/* $NetBSD: pr_time.c,v 1.18 2011/08/17 13:48:11 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 4/4/94"; #else -__RCSID("$NetBSD: pr_time.c,v 1.17 2009/04/14 07:41:36 lukem Exp $"); +__RCSID("$NetBSD: pr_time.c,v 1.18 2011/08/17 13:48:11 christos Exp $"); #endif #endif /* not lint */ @@ -62,25 +62,22 @@ pr_attime(time_t *started, time_t *now) int tnow_yday; struct tm *tp; time_t diff; - const char *fmt; tnow_yday = localtime(now)->tm_yday; tp = localtime(started); diff = *now - *started; - /* If more than a week, use day-month-year. */ - if (diff > SECSPERDAY * DAYSPERWEEK) - fmt = "%d%b%y"; + if (diff > SECSPERDAY * DAYSPERWEEK) { + /* If more than a week, use day-month-year. */ + (void)strftime(buf, sizeof(buf), "%d%b%y", tp); + } else if (tp->tm_yday != tnow_yday) { + /* If not today, use day-hour-am/pm. Damn SCCS */ + (void)strftime(buf, sizeof(buf), "%a%" "I%p", tp); + } else { + /* Default is hh:mm{am,pm}. Damn SCCS */ + (void)strftime(buf, sizeof(buf), "%l:%" "M%p", tp); + } - /* If not today, use day-hour-am/pm. */ - else if (tp->tm_yday != tnow_yday) - fmt = "%a%" "I%p"; - - /* Default is hh:mm{am,pm}. */ - else - fmt = "%l:%" "M%p"; - - (void)strftime(buf, sizeof(buf), fmt, tp); buf[sizeof(buf) - 1] = '\0'; (void)fputs(buf, stdout); }