bug-coreutils
[Top][All Lists]
Advanced

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

"touch -- MMDDhhmm file" conformance bug (for POSIX.2-1992)


From: Paul Eggert
Subject: "touch -- MMDDhhmm file" conformance bug (for POSIX.2-1992)
Date: Mon, 06 Sep 2004 23:25:27 -0700

I installed this patch to fix a bug where "touch" didn't conform to
POSIX.2-1992.

2004-09-06  Paul Eggert  <address@hidden>

        * src/touch.c (main): Fix POSIX-conformance bug: "touch --
        MMDDhhmm file" must be treated like "touch MMDDhhmm file" when
        conforming to pre-2001 POSIX.
        * NEWS: Document this.
        * tests/touch/obsolescent: Test for this bug.  Also, set
        _POSIX2_VERSION=199209 and POSIXLY_CORRECT=1 so that it's
        a better test for obsolescent features.

Index: src/touch.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/touch.c,v
retrieving revision 1.123
diff -p -u -r1.123 touch.c
--- src/touch.c 3 Aug 2004 23:13:09 -0000       1.123
+++ src/touch.c 7 Sep 2004 05:56:07 -0000
@@ -373,8 +373,7 @@ 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 && !STREQ (argv[optind - 1], "--")
-      && posix2_version () < 200112)
+  if (!date_set && 2 <= argc - optind && posix2_version () < 200112)
     {
       if (posixtime (&newtime[0].tv_sec, argv[optind], PDS_TRAILING_YEAR))
        {
Index: NEWS
===================================================================
RCS file: /home/eggert/coreutils/cu/NEWS,v
retrieving revision 1.231
diff -p -u -r1.231 NEWS
--- NEWS        6 Sep 2004 07:49:06 -0000       1.231
+++ NEWS        7 Sep 2004 06:15:34 -0000
@@ -103,6 +103,9 @@ GNU coreutils NEWS                      
     like %#d, instead of relying on undefined behavior in the underlying
     printf function.
 
+  "touch -- MMDDhhmm[yy] file" is now equivalent to
+  "touch MMDDhhmm[yy] file" even when conforming to pre-2001 POSIX.
+
   who now prints user names in full instead of truncating them after 8 bytes.
 
 ** New features
Index: tests/touch/obsolescent
===================================================================
RCS file: /home/eggert/coreutils/cu/tests/touch/obsolescent,v
retrieving revision 1.2
diff -p -u -r1.2 obsolescent
--- tests/touch/obsolescent     23 Jun 2004 15:07:05 -0000      1.2
+++ tests/touch/obsolescent     7 Sep 2004 06:10:00 -0000
@@ -1,5 +1,8 @@
 #!/bin/sh
-# make sure touch succeeds with a single 8- or 10-digit file name argument
+# Test touch with obsolescent 8- or 10-digit time stamps.
+
+_POSIX2_VERSION=199209; export _POSIX2_VERSION
+POSIXLY_CORRECT=1; export POSIXLY_CORRECT
 
 if test "$VERBOSE" = yes; then
   set -x
@@ -22,9 +25,15 @@ fi
 
 fail=0
 
+yearstart=01010000
+
 for ones in 11111111 1111111111; do
-  touch $ones || fail=1
-  test -f $ones || fail=1
+  for args in $ones "-- $ones" "$yearstart $ones" "-- $yearstart $ones"; do
+    touch $args || fail=1
+    test -f $ones || fail=1
+    test -f $yearstart && fail=1
+    rm -f $ones || fail=1
+  done
 done
 
 (exit $fail); exit $fail




reply via email to

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