Subject: misc/2308: Year 2000 breakage with tm_year
To: None <gnats-bugs@NetBSD.ORG>
From: None <sjr@zombie.ncsc.mil>
List: netbsd-bugs
Date: 04/07/1996 20:26:55
>Number:         2308
>Category:       misc
>Synopsis:       Year 2000 breakage with tm_year
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Apr  7 21:05:01 1996
>Last-Modified:
>Originator:     Stephen J. Roznowski
>Organization:
Stephen J. Roznowski	(sjr@zombie.ncsc.mil)
>Release:        NetBSD-current
>Environment:
	
System: NetBSD 1.1B () #1: Sat Mar 23 22:10:29 EST 1996 amiga

Machine: amiga
>Description:
	Several programs have a hardcoded 19 in responses for the year.
	This will break in 4 years...
>How-To-Repeat:
	find /usr/src -type f -print | xargs grep '19%'
>Fix:
	I've adopted a fix similiar to what is currently in
	lib/libc/time/asctime.c; defining a constant (TM_YEAR_BASE),
	including it in <time.h>, and changing '19%d's to doing
	the add and printing the results.

	There is also similiar code in "gnu/usr.bin/rcs/lib/rcstime.c",
	but I'm less sure of the proper fix there.

*** usr.bin/yacc/test/ftp.tab.c.orig	Sun Apr  7 20:07:58 1996
--- usr.bin/yacc/test/ftp.tab.c	Sun Apr  7 20:10:38 1996
***************
*** 1468,1475 ****
  					struct tm *gmtime();
  					t = gmtime(&stbuf.st_mtime);
  					reply(213,
! 					    "19%02d%02d%02d%02d%02d%02d",
! 					    t->tm_year, t->tm_mon+1, t->tm_mday,
  					    t->tm_hour, t->tm_min, t->tm_sec);
  				}
  			}
--- 1468,1476 ----
  					struct tm *gmtime();
  					t = gmtime(&stbuf.st_mtime);
  					reply(213,
! 					    "%04d%02d%02d%02d%02d%02d",
! 					    TM_YEAR_BASE + t->tm_year,
! 					    t->tm_mon+1, t->tm_mday,
  					    t->tm_hour, t->tm_min, t->tm_sec);
  				}
  			}

*** usr.bin/yacc/test/ftp.y.orig	Sun Apr  7 20:07:59 1996
--- usr.bin/yacc/test/ftp.y	Sun Apr  7 20:11:30 1996
***************
*** 457,464 ****
  					struct tm *gmtime();
  					t = gmtime(&stbuf.st_mtime);
  					reply(213,
! 					    "19%02d%02d%02d%02d%02d%02d",
! 					    t->tm_year, t->tm_mon+1, t->tm_mday,
  					    t->tm_hour, t->tm_min, t->tm_sec);
  				}
  			}
--- 457,465 ----
  					struct tm *gmtime();
  					t = gmtime(&stbuf.st_mtime);
  					reply(213,
! 					    "%04d%02d%02d%02d%02d%02d",
! 					    TM_YEAR_BASE + t->tm_year,
! 					    t->tm_mon+1, t->tm_mday,
  					    t->tm_hour, t->tm_min, t->tm_sec);
  				}
  			}

*** libexec/ftpd/ftpcmd.y.orig	Sun Apr  7 20:07:59 1996
--- libexec/ftpd/ftpcmd.y	Sun Apr  7 20:11:51 1996
***************
*** 496,503 ****
  					struct tm *t;
  					t = gmtime(&stbuf.st_mtime);
  					reply(213,
! 					    "19%02d%02d%02d%02d%02d%02d",
! 					    t->tm_year, t->tm_mon+1, t->tm_mday,
  					    t->tm_hour, t->tm_min, t->tm_sec);
  				}
  			}
--- 496,504 ----
  					struct tm *t;
  					t = gmtime(&stbuf.st_mtime);
  					reply(213,
! 					    "%04d%02d%02d%02d%02d%02d",
! 					    TM_YEAR_BASE + t->tm_year,
! 					    t->tm_mon+1, t->tm_mday,
  					    t->tm_hour, t->tm_min, t->tm_sec);
  				}
  			}

*** usr.bin/make/targ.c.orig	Sun Apr  7 20:07:59 1996
--- usr.bin/make/targ.c	Sun Apr  7 20:13:41 1996
***************
*** 471,479 ****
  
      parts = localtime(&time);
  
!     sprintf (buf, "%d:%02d:%02d %s %d, 19%d",
  	     parts->tm_hour, parts->tm_min, parts->tm_sec,
! 	     months[parts->tm_mon], parts->tm_mday, parts->tm_year);
      return(buf);
  }
      
--- 471,480 ----
  
      parts = localtime(&time);
  
!     sprintf (buf, "%d:%02d:%02d %s %d, %d",
  	     parts->tm_hour, parts->tm_min, parts->tm_sec,
! 	     months[parts->tm_mon], parts->tm_mday,
! 	     TM_YEAR_BASE + parts->tm_year);
      return(buf);
  }
      

*** include/time.h.orig	Sun Apr  7 20:08:00 1996
--- include/time.h	Sun Apr  7 20:08:37 1996
***************
*** 67,79 ****
  
  #define CLOCKS_PER_SEC	100
  
  struct tm {
  	int	tm_sec;		/* seconds after the minute [0-60] */
  	int	tm_min;		/* minutes after the hour [0-59] */
  	int	tm_hour;	/* hours since midnight [0-23] */
  	int	tm_mday;	/* day of the month [1-31] */
  	int	tm_mon;		/* months since January [0-11] */
! 	int	tm_year;	/* years since 1900 */
  	int	tm_wday;	/* days since Sunday [0-6] */
  	int	tm_yday;	/* days since January 1 [0-365] */
  	int	tm_isdst;	/* Daylight Savings Time flag */
--- 67,81 ----
  
  #define CLOCKS_PER_SEC	100
  
+ #define TM_YEAR_BASE	1900
+ 
  struct tm {
  	int	tm_sec;		/* seconds after the minute [0-60] */
  	int	tm_min;		/* minutes after the hour [0-59] */
  	int	tm_hour;	/* hours since midnight [0-23] */
  	int	tm_mday;	/* day of the month [1-31] */
  	int	tm_mon;		/* months since January [0-11] */
! 	int	tm_year;	/* years since TM_YEAR_BASE */
  	int	tm_wday;	/* days since Sunday [0-6] */
  	int	tm_yday;	/* days since January 1 [0-365] */
  	int	tm_isdst;	/* Daylight Savings Time flag */

*** lib/libc/time/tzfile.h.orig	Sun Apr  7 20:08:00 1996
--- lib/libc/time/tzfile.h	Sun Apr  7 20:09:47 1996
***************
*** 144,150 ****
--- 144,152 ----
  #define TM_NOVEMBER	10
  #define TM_DECEMBER	11
  
+ #ifndef TM_YEAR_BASE
  #define TM_YEAR_BASE	1900
+ #endif
  
  #define EPOCH_YEAR	1970
  #define EPOCH_WDAY	TM_THURSDAY

>Audit-Trail:
>Unformatted: