bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

posixtm fixes imported from coreutils


From: Paul Eggert
Subject: posixtm fixes imported from coreutils
Date: Mon, 09 Jan 2006 15:33:09 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

I installed this:

2006-01-09  Paul Eggert  <address@hidden>

        Sync from coreutils.

        * lib/posixtm.h (PDS_PRE_2000): New macro.
        * lib/posixtm.c (year): Arg is now syntax_bits rather than 
allow_century.
        All usages changed.  Reject dates outside the range 1969-1999 if
        PDS_PRE_2000 is used.

Index: lib/posixtm.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/posixtm.c,v
retrieving revision 1.21
diff -p -u -r1.21 posixtm.c
--- lib/posixtm.c       23 Sep 2005 04:15:13 -0000      1.21
+++ lib/posixtm.c       9 Jan 2006 23:02:07 -0000
@@ -62,8 +62,8 @@ time_t mktime ();
     (PDS_LEADING_YEAR | PDS_CENTURY | PDS_SECONDS)
 
   touch mmddhhmm[YY] FILE... (obsoleted by POSIX 1003.1-2001)
-    8 or 10 digits
-    (PDS_TRAILING_YEAR)
+    8 or 10 digits, YY (if present) must be in the range 69-99
+    (PDS_TRAILING_YEAR | PDS_PRE_2000)
 
   date mmddhhmm[[CC]YY]
     8, 10, or 12 digits
@@ -72,7 +72,7 @@ time_t mktime ();
 */
 
 static int
-year (struct tm *tm, const int *digit_pair, size_t n, int allow_century)
+year (struct tm *tm, const int *digit_pair, size_t n, unsigned int syntax_bits)
 {
   switch (n)
     {
@@ -82,11 +82,15 @@ year (struct tm *tm, const int *digit_pa
         POSIX requires that 00-68 be interpreted as 2000-2068,
         and that 69-99 be interpreted as 1969-1999.  */
       if (digit_pair[0] <= 68)
-       tm->tm_year += 100;
+       {
+         if (syntax_bits & PDS_PRE_2000)
+           return 1;
+         tm->tm_year += 100;
+       }
       break;
 
     case 2:
-      if (!allow_century)
+      if (! (syntax_bits & PDS_CENTURY))
        return 1;
       tm->tm_year = digit_pair[0] * 100 + digit_pair[1] - 1900;
       break;
@@ -148,7 +152,7 @@ posix_time_parse (struct tm *tm, const c
   p = pair;
   if (syntax_bits & PDS_LEADING_YEAR)
     {
-      if (year (tm, p, len - 4, syntax_bits & PDS_CENTURY))
+      if (year (tm, p, len - 4, syntax_bits))
        return 1;
       p += len - 4;
       len = 4;
@@ -164,7 +168,7 @@ posix_time_parse (struct tm *tm, const c
   /* Handle any trailing year.  */
   if (syntax_bits & PDS_TRAILING_YEAR)
     {
-      if (year (tm, p, len, syntax_bits & PDS_CENTURY))
+      if (year (tm, p, len, syntax_bits))
        return 1;
     }
 
Index: lib/posixtm.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/posixtm.h,v
retrieving revision 1.6
diff -p -u -r1.6 posixtm.h
--- lib/posixtm.h       14 May 2005 06:03:58 -0000      1.6
+++ lib/posixtm.h       9 Jan 2006 23:02:07 -0000
@@ -1,6 +1,6 @@
 /* Parse dates for touch and date.
 
-   Copyright (C) 1998, 2003 Free Software Foundation Inc.
+   Copyright (C) 1998, 2003, 2005 Free Software Foundation Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@
 # define PDS_TRAILING_YEAR 2
 # define PDS_CENTURY 4
 # define PDS_SECONDS 8
+# define PDS_PRE_2000 16
 
 bool posixtime (time_t *p, const char *s, unsigned int syntax_bits);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]