Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Sep 1998 22:01:47 -0500
From:      Dave Glowacki <dglo@SSEC.WISC.EDU>
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/7826: ls(1) knows too much about format of strftime()
Message-ID:  <199809040301.WAA22572@tick.ssec.wisc.edu>

next in thread | raw e-mail | index | archive | help

>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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809040301.WAA22572>