From dglo@tick.ssec.wisc.edu  Thu Sep  3 20:02:54 1998
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 <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <dglo@SSEC.WISC.EDU>
Reply-To: dglo@SSEC.WISC.EDU
To: FreeBSD-gnats-submit@freebsd.org
Subject: ls(1) knows too much about format of strftime()
X-Send-Pr-Version: 3.2

>Number:         7826
>Category:       bin
>Synopsis:       ls(1) knows too much about format of strftime()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep  3 20:10:01 PDT 1998
>Closed-Date:    Sun Jun 18 15:31:36 PDT 2000
>Last-Modified:  Sun Jun 18 15:32:53 PDT 2000
>Originator:     Dave Glowacki
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>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
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: joe 
State-Changed-When: Sun Jun 18 15:31:36 PDT 2000 
State-Changed-Why:  
Thanks.  I've committed this to -current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=7826 
>Unformatted:

