Duplicated effort

Olson, Arthur David (NIH/NCI) olsona at dc37a.nci.nih.gov
Tue Oct 12 13:49:58 UTC 2004


The notion would be to rely on strftime only to handle the year (along the
lines below); this would avoid some of the problems folks have noted.
(There's still the business of zero padding of the year to consider).

				--ado

------- asctime.c -------
*** /tmp/geta26648	Tue Oct 12 09:41:36 2004
--- /tmp/getb26648	Tue Oct 12 09:41:36 2004
***************
*** 5,11 ****
  
  #ifndef lint
  #ifndef NOID
! static char	elsieid[] = "@(#)asctime.c	7.22";
  #endif /* !defined NOID */
  #endif /* !defined lint */
  
--- 5,11 ----
  
  #ifndef lint
  #ifndef NOID
! static char	elsieid[] = "@(#)asctime.c	7.25";
  #endif /* !defined NOID */
  #endif /* !defined lint */
  
***************
*** 15,21 ****
  #include "tzfile.h"
  
  #if STRICTLY_STANDARD_ASCTIME
! #define ASCTIME_FMT	"%.3s %.3s%3d %.2d:%.2d:%.2d %ld\n"
  #define ASCTIME_FMT_B	ASCTIME_FMT
  #else /* !STRICTLY_STANDARD_ASCTIME */
  /*
--- 15,21 ----
  #include "tzfile.h"
  
  #if STRICTLY_STANDARD_ASCTIME
! #define ASCTIME_FMT	"%.3s %.3s%3d %.2d:%.2d:%.2d %s\n"
  #define ASCTIME_FMT_B	ASCTIME_FMT
  #else /* !STRICTLY_STANDARD_ASCTIME */
  /*
***************
*** 31,37 ****
  ** For years that are less than four digits, we pad the output with
  ** spaces before the newline to get the newline in the traditional place.
  */
! #define ASCTIME_FMT	"%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4ld\n"
  /*
  ** For years that are more than four digits we put extra spaces before the
year
  ** so that code trying to overwrite the newline won't end up overwriting
--- 31,37 ----
  ** For years that are less than four digits, we pad the output with
  ** spaces before the newline to get the newline in the traditional place.
  */
! #define ASCTIME_FMT	"%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4s\n"
  /*
  ** For years that are more than four digits we put extra spaces before the
year
  ** so that code trying to overwrite the newline won't end up overwriting
***************
*** 38,44 ****
  ** a digit within a year and truncating the year (operating on the
assumption
  ** that no output is better than wrong output).
  */
! #define ASCTIME_FMT_B	"%.3s %.3s%3d %02.2d:%02.2d:%02.2d     %ld\n"
  #endif /* !STRICTLY_STANDARD_ASCTIME */
  
  #define STD_ASCTIME_BUF_SIZE	26
--- 38,44 ----
  ** a digit within a year and truncating the year (operating on the
assumption
  ** that no output is better than wrong output).
  */
! #define ASCTIME_FMT_B	"%.3s %.3s%3d %02.2d:%02.2d:%02.2d     %s\n"
  #endif /* !STRICTLY_STANDARD_ASCTIME */
  
  #define STD_ASCTIME_BUF_SIZE	26
***************
*** 74,80 ****
  	};
  	register const char *	wn;
  	register const char *	mn;
! 	long			year;
  	char			result[MAX_ASCTIME_BUF_SIZE];
  
  	if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
--- 74,80 ----
  	};
  	register const char *	wn;
  	register const char *	mn;
! 	char			year[INT_STRLEN_MAXIMUM(int) + 2];
  	char			result[MAX_ASCTIME_BUF_SIZE];
  
  	if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
***************
*** 83,94 ****
  	if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
  		mn = "???";
  	else	mn = mon_name[timeptr->tm_mon];
! 	year = timeptr->tm_year + (long) TM_YEAR_BASE;
  	/*
  	** We avoid using snprintf since it's not available on all systems.
  	*/
! 	(void) sprintf(result,
! 		((year >= -999 && year <= 9999) ? ASCTIME_FMT :
ASCTIME_FMT_B),
  		wn, mn,
  		timeptr->tm_mday, timeptr->tm_hour,
  		timeptr->tm_min, timeptr->tm_sec,
--- 83,94 ----
  	if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
  		mn = "???";
  	else	mn = mon_name[timeptr->tm_mon];
! 	(void) strftime(year, sizeof year, "%Y", timeptr);
  	/*
  	** We avoid using snprintf since it's not available on all systems.
  	*/
! 	(void) sprintf(result, 
! 		((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B),
  		wn, mn,
  		timeptr->tm_mday, timeptr->tm_hour,
  		timeptr->tm_min, timeptr->tm_sec,



More information about the tz mailing list