Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/w Eliminate non-literal format strings, and now that...



details:   https://anonhg.NetBSD.org/src/rev/5c317bfdcaa2
branches:  trunk
changeset: 768483:5c317bfdcaa2
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Aug 17 13:48:11 2011 +0000

description:
Eliminate non-literal format strings, and now that gcc warns, kill y2k format
warning.

diffstat:

 usr.bin/w/Makefile  |   4 +++-
 usr.bin/w/pr_time.c |  27 ++++++++++++---------------
 2 files changed, 15 insertions(+), 16 deletions(-)

diffs (70 lines):

diff -r f96a29e77f7c -r 5c317bfdcaa2 usr.bin/w/Makefile
--- a/usr.bin/w/Makefile        Wed Aug 17 13:37:39 2011 +0000
+++ b/usr.bin/w/Makefile        Wed Aug 17 13:48:11 2011 +0000
@@ -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 <bsd.own.mk>
@@ -13,4 +13,6 @@
 
 .PATH: ${NETBSDSRCDIR}/bin/ps
 
+COPTS.pr_time.c += -Wno-format-y2k
+
 .include <bsd.prog.mk>
diff -r f96a29e77f7c -r 5c317bfdcaa2 usr.bin/w/pr_time.c
--- a/usr.bin/w/pr_time.c       Wed Aug 17 13:37:39 2011 +0000
+++ b/usr.bin/w/pr_time.c       Wed Aug 17 13:48:11 2011 +0000
@@ -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 @@
        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);
 }



Home | Main Index | Thread Index | Old Index