[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
POSIX-conformance patch for obsolete usages of "touch"
From: |
Paul Eggert |
Subject: |
POSIX-conformance patch for obsolete usages of "touch" |
Date: |
Tue, 01 Nov 2005 15:46:53 -0800 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
In reviewing today's "tail" patch, I see now that the old POSIX
requires support for the obsolescent Y2k-vulnerable usages of "touch"
only for dates in the range 1969--1999. Since this obsolescent usage
conflicts with the current POSIX standard (and GNU touch chatters
about this) I installed the following patch to minimize its scope.
2005-11-01 Paul Eggert <address@hidden>
* NEWS: "tail -c 2 FILE" and "touch 0101000000" now operate as
POSIX 1002.1-2001 requires.
* doc/coreutils.texi (touch invocation): The old usage works only
for 1969-1999 now.
* src/touch.c (main): Pass PDS_PRE_2000 to posixtime.
* tests/touch/obsolescent: Add y2000 test.
* 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: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.333
diff -p -u -r1.333 NEWS
--- NEWS 1 Nov 2005 23:04:37 -0000 1.333
+++ NEWS 1 Nov 2005 23:40:12 -0000
@@ -22,9 +22,10 @@ GNU coreutils NEWS
tac now works when stdin is a tty, even on non-Linux systems
- "tail -c 2 FILE" now operates as POSIX 1003.1-2001 requires, even
- when "tail" is conforming to older POSIX standards, as the
- newly-mandated behavior is upward-compatible with the old.
+ "tail -c 2 FILE" and "touch 0101000000" now operate as POSIX
+ 1003.1-2001 requires, even when coreutils is conforming to older
+ POSIX standards, as the newly-required behavior is upward-compatible
+ with the old.
** Build-related bug fixes
Index: doc/coreutils.texi
===================================================================
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.291
diff -p -u -r1.291 coreutils.texi
--- doc/coreutils.texi 1 Nov 2005 23:05:00 -0000 1.291
+++ doc/coreutils.texi 1 Nov 2005 23:40:15 -0000
@@ -8726,7 +8726,8 @@ If no timestamp is given with any of the
@option{-t} options, and if there are two or more @var{file}s and the
first @var{file} is of the form @address@hidden@var{YY}]} and this
would be a valid argument to the @option{-t} option (if the @var{YY}, if
-any, were moved to the front), that argument is interpreted as the time
+any, were moved to the front), and if the represented year
+is in the range 1969--1999, that argument is interpreted as the time
for the other files instead of as a file name.
This obsolete behavior can be enabled or disabled with the
@env{_POSIX2_VERSION} environment variable (@pxref{Standards
Index: lib/posixtm.c
===================================================================
RCS file: /fetish/cu/lib/posixtm.c,v
retrieving revision 1.22
diff -p -u -r1.22 posixtm.c
--- lib/posixtm.c 22 Sep 2005 06:05:39 -0000 1.22
+++ lib/posixtm.c 1 Nov 2005 23:40:15 -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: /fetish/cu/lib/posixtm.h,v
retrieving revision 1.7
diff -p -u -r1.7 posixtm.h
--- lib/posixtm.h 14 May 2005 07:58:06 -0000 1.7
+++ lib/posixtm.h 1 Nov 2005 23:40:15 -0000
@@ -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);
Index: src/touch.c
===================================================================
RCS file: /fetish/cu/src/touch.c,v
retrieving revision 1.136
diff -p -u -r1.136 touch.c
--- src/touch.c 26 Sep 2005 23:02:14 -0000 1.136
+++ src/touch.c 1 Nov 2005 23:40:15 -0000
@@ -375,7 +375,8 @@ main (int argc, char **argv)
/* The obsolete `MMDDhhmm[YY]' form is valid IFF there are
two or more non-option arguments. */
if (!date_set && 2 <= argc - optind && posix2_version () < 200112
- && posixtime (&newtime[0].tv_sec, argv[optind], PDS_TRAILING_YEAR))
+ && posixtime (&newtime[0].tv_sec, argv[optind],
+ PDS_TRAILING_YEAR | PDS_PRE_2000))
{
newtime[0].tv_nsec = 0;
newtime[1] = newtime[0];
Index: tests/touch/obsolescent
===================================================================
RCS file: /fetish/cu/tests/touch/obsolescent,v
retrieving revision 1.3
diff -p -u -r1.3 obsolescent
--- tests/touch/obsolescent 7 Sep 2004 06:23:09 -0000 1.3
+++ tests/touch/obsolescent 1 Nov 2005 23:40:15 -0000
@@ -36,4 +36,8 @@ for ones in 11111111 1111111111; do
done
done
+y2000=0101000000
+rm -f $y2000 file || fail=1
+touch $y2000 file && test -f $y2000 && test -f file || fail=1
+
(exit $fail); exit $fail
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- POSIX-conformance patch for obsolete usages of "touch",
Paul Eggert <=