From owner-freebsd-bugs Thu Sep 3 20:10:11 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id UAA14575 for freebsd-bugs-outgoing; Thu, 3 Sep 1998 20:10:11 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAA14567 for ; Thu, 3 Sep 1998 20:10:09 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id UAA21672; Thu, 3 Sep 1998 20:10:02 -0700 (PDT) Received: from tick.ssec.wisc.edu (tick.ssec.wisc.edu [144.92.108.121]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAA14091 for ; Thu, 3 Sep 1998 20:02:53 -0700 (PDT) (envelope-from dglo@tick.ssec.wisc.edu) Received: from tick.ssec.wisc.edu (localhost [127.0.0.1]) by tick.ssec.wisc.edu (8.8.7/8.8.7) with ESMTP id WAA22572 for ; Thu, 3 Sep 1998 22:01:48 -0500 (CDT) Message-Id: <199809040301.WAA22572@tick.ssec.wisc.edu> Date: Thu, 03 Sep 1998 22:01:47 -0500 From: Dave Glowacki Reply-To: dglo@SSEC.WISC.EDU To: FreeBSD-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: 3.2 Subject: bin/7826: ls(1) knows too much about format of strftime() Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 7826 >Category: bin >Synopsis: ls(1) knows too much about format of strftime() >Confidential: yes >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Sep 3 20:10:01 PDT 1998 >Last-Modified: >Originator: Dave Glowacki >Organization: >Release: FreeBSD 3.0-CURRENT i386 >Environment: >Description: ls(1) thinks it knows the exact layout of the "%c" format of strftime(). >How-To-Repeat: Alter the "national representation of time and date" in strftime() and ls(1) will break. Rather than hard-coding the locations of the time elements and hoping they don't move, ls(1) should use format strings which produce the desired strings. >Fix: Index: print.c =================================================================== RCS file: /disk0/freebsd/src/bin/ls/print.c,v retrieving revision 1.17 diff -c -r1.17 print.c *** print.c 1998/07/29 00:46:13 1.17 --- print.c 1998/09/04 02:46:49 *************** *** 242,268 **** int i; char longstring[80]; static time_t now; if (now == 0) now = time(NULL); - strftime(longstring, sizeof(longstring), "%c", localtime(&ftime)); - for (i = 4; i < 11; ++i) - (void)putchar(longstring[i]); - #define SIXMONTHS ((365 / 2) * 86400) if (f_sectime) ! for (i = 11; i < 24; i++) ! (void)putchar(longstring[i]); else if (ftime + SIXMONTHS > now && ftime < now + SIXMONTHS) ! for (i = 11; i < 16; ++i) ! (void)putchar(longstring[i]); ! else { ! (void)putchar(' '); ! for (i = 20; i < 24; ++i) ! (void)putchar(longstring[i]); ! } ! (void)putchar(' '); } static int --- 242,265 ---- int i; char longstring[80]; static time_t now; + const char *format; if (now == 0) now = time(NULL); #define SIXMONTHS ((365 / 2) * 86400) if (f_sectime) ! /* Mmm dd hh:mm:ss yyyy */ ! format = "%b %e %T %Y "; else if (ftime + SIXMONTHS > now && ftime < now + SIXMONTHS) ! /* Mmm dd hh:mm */ ! format = "%b %e %R "; ! else ! /* Mmm dd yyyy */ ! format = "%b %e %Y "; ! strftime(longstring, sizeof(longstring), format, localtime(&ftime)); ! fputs(longstring, stdout); } static int >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message