The patch below removes a feature from touch(1) that is probably in more
situations undesired than desired.

When an 8 or 10 digit time format is specified as the first argument,
and it has at least two arguments in total, it is interpreted as a time
formatting instead of a file name.  This feature/form is obsolete in the
current version of POSIX 1003.1.

When I first saw the behaviour, I thought it was a bug, but the code,
the man page and the standard explain it.  Removing the feature could
break old scripts or habits.  However, I found the behaviour quite
unexpected, and the standard says it is obsolete.

 - Marco


Index: touch.1
===================================================================
RCS file: /cvs/src/usr.bin/touch/touch.1,v
retrieving revision 1.35
diff -u -p -r1.35 touch.1
--- touch.1     25 Sep 2015 17:02:57 -0000      1.35
+++ touch.1     17 Apr 2017 19:14:12 -0000
@@ -164,18 +164,6 @@ The
 utility is compliant with the
 .St -p1003.1-2008
 specification.
-.Pp
-The obsolescent form of
-.Nm touch ,
-where a time format is specified as the first argument, is supported.
-When no
-.Fl d , r ,
-or
-.Fl t
-option is specified, there are at least two arguments, and the first
-argument is a string of digits either eight or ten characters in length,
-the first argument is interpreted as a time specification of the form
-.Dq mmddHHMM[yy] .
 .Sh HISTORY
 A
 .Nm
Index: touch.c
===================================================================
RCS file: /cvs/src/usr.bin/touch/touch.c,v
retrieving revision 1.25
diff -u -p -r1.25 touch.c
--- touch.c     9 Oct 2015 01:37:09 -0000       1.25
+++ touch.c     17 Apr 2017 19:14:12 -0000
@@ -99,20 +99,7 @@ main(int argc, char *argv[])
        if (aflag == 0 && mflag == 0)
                aflag = mflag = 1;
 
-       /*
-        * If no -r or -t flag, at least two operands, the first of which
-        * is an 8 or 10 digit number, use the obsolete time specification.
-        */
-       if (!timeset && argc > 1) {
-               (void)strtol(argv[0], &p, 10);
-               len = p - argv[0];
-               if (*p == '\0' && (len == 8 || len == 10)) {
-                       timeset = 1;
-                       stime_arg2(*argv++, len == 10, ts);
-               }
-       }
-
-       /* Otherwise use the current time of day. */
+       /* By default use the current time of day. */
        if (!timeset)
                ts[0].tv_nsec = ts[1].tv_nsec = UTIME_NOW;

Reply via email to