Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 06 Apr 1999 23:22:11 -0600
From:      Wes Peters <wes@softweyr.com>
To:        Sergey Babkin <babkin@bellatlantic.net>, freebsd-hackers@freebsd.org
Subject:   Re: Y2K issue
Message-ID:  <370AEB83.5FB06D98@softweyr.com>
References:  <3702BF79.EE5801AE@bellatlantic.net> <37031575.F7A2399D@softweyr.com> <37040BB7.56E25907@bellatlantic.net> <3705AE7E.23D356D8@softweyr.com> <3706A4D6.5BDE3F87@bellatlantic.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Sergey Babkin <babkin@bellatlantic.net> has suggested the following
fix to the strptime library function so it will behave in a manner
compatible with the Posix spec.  Specifically, two-digit years on
input will be interpreted in the 20th century if greater than 69, and
in the 21st century otherwise.

Any objections to committing this in -CURRENT and/or -RELENG_3?  DG?

Sergey Babkin wrote:
> 
> Thanks! Here is the patch (a fairly simple one, also attached):
> 
> ----------------------------- cut here ------------------------------------
> *** strptime.c  1999/04/03 23:15:37     1.1
> --- lib/libc/stdtime/strptime.c  1999/04/03 23:20:08
> ***************
> *** 333,338 ****
> --- 333,340 ----
>                         }
>                         if (c == 'Y')
>                                 i -= 1900;
> +                       if (c == 'y' && i < 69)
> +                               i += 100;
>                         if (i < 0)
>                                 return 0;
> 
> ------------------------------- cut here -----------------------------------
> 
> Hare is the test program (also at
> ftp://ftp.rdg.opengroup.org/pub/unsupported/stdtools/y2k/strptime.c) :
> 
> ------------------------------- cut here -----------------------------------
> /*
>  * Taken from comp.unix.aix
>  * From: John Crothers <jscrothers@statestreet.NOSPAM.com>
>  * Subject: strptime() and %y  checker
>  */
> 
> #ifndef lint
> static char *_version = "@(#)strptime_win.c 1.1 - 98/05/04";
> #endif
> /*
>  * Determine window for the strptime(3C) function.
>  */
> #include <stdio.h>
> #include <time.h>
> #include <stdlib.h>
> #ifdef sun
> #include <tzfile.h>
> #else
> #define TM_YEAR_BASE 1900
> #endif
> 
> main()
> {
>  int i;
>  struct tm tm;
>  char buf[4];
>  int years[100];
> 
>  for (i = 0; i < 100; i++) {
>   sprintf(buf, "%02d", i);
>   (void) strptime(buf, "%y", &tm);
>   years[i] = tm.tm_year + TM_YEAR_BASE;
>  }
> 
>  printf("strptime(3C) window: %04d-", years[0]);
>  for (i = 1; i < 100; i++) {
>   if (years[i-1] / 100 != years[i] / 100)
>    printf("%04d %04d-", years[i-1], years[i]);
>  }
>  printf("%04d\n", years[99]);
>  exit(0);
>  return (0);  /* quiet lint gripes */
> }
> 
> ------------------------------- cut here -----------------------------------
> 
> And its description is at
> ftp://ftp.rdg.opengroup.org/pub/unsupported/stdtools/y2k/README

-- 
       "Where am I, and what am I doing in this handbasket?"

Wes Peters                                                 Softweyr LLC
http://www.softweyr.com/~softweyr                      wes@softweyr.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?370AEB83.5FB06D98>