Home | History | Annotate | Download | only in touch
History log of /src/usr.bin/touch/touch.c
RevisionDateAuthorComments
 1.40  10-Feb-2024  kre Add a -D option to touch, which acts like the -d option added to
chmod/chown/chgrp (probably others) in the not too far distant past,
and causes the operation to be a no-op if no actual change would be
made (avoiding updating the file's ctime for no reason).

That is, with touch, -D causes no modifying sys call to be made to
a file if that file's atime and mtime are already set to the values
that would be used. A common case for this is when a "-r ref-file"
is also a target file for the operation.

Unfortunately -d was already taken in touch, so next best available is -D.
 1.39  09-Feb-2024  kre Add a -R option, which is identical to -r, except that if the reference file
is a symbolic link, the times to use are taken from those of the symbolic
link itself, instead of from the file it references. If the reference file
is not a symbolic link, -R and -r are identical.

This allows the BUGS entry in the manual page to be removed.
 1.38  08-Feb-2024  kre Check that mktime() (or timegm() the one time it is used) do not
alter any of the material fields of the struct tm that was handed
to it. If any were altered, then the time string passed in was
not a valid time representation, and so should be rejected.

This one is not an invisible change, it prevents use of things like
"-t 202402300000" (which previously would have been interpreted as
"-t 202403010000" - the day after the 29th of Feb in 2024).

I believe this is an improvement however, and in line with the
general intent that if you specify a date and time, that exact
date and time is what touch should be using. It does mean that
specifying "60" for the seconds field is almost guaranteed to
fail on any POSIX system, as leap seconds simply don't exist
there (on a non-POSIX-conforming system that uses leap seconds,
the :60 should work, if specified with the correct date and time
at which the leap second actually occurs).

The one exception is when parsedate(3) is used, as that does not
do this check (which allows things like "-1 day" on the 1st of
a month to work).

(This is the last of this sequence of updates to touch.c, an
update to touch.1 follows).
 1.37  08-Feb-2024  kre Properly implement the POSIX format -d option.

Previously we have hacked that using parsedate(3) - but parsedate()
returns a time_t and consequently while it "handles" fractional seconds,
all that meant (all it really can mean) is that they're ignored.

The POSIX spec expects that (at least if the filesystem supports them)
fractional seconds can be set using the -d option.

Handle that by first attempting to parse the -d arg as a posix format
date-time string (using a reasonably strict parser), and if that fails,
then fall back on parsedate(3) to parse the arg.

If the posix format parse succeeds, the result will be the same as
parsedate(3) would return for the same string - except any fractional
seconds will be handled properly. If it fails, then nothing changes
from what we currently do.

Note the POSIX string is
YYYY-MM-DDThh:mm:ss[.frac][Z]
where YYYY is (at least) 4 digits (leading 0's are acceptable if
you really must!) all the MM DD hh mm ss fields are exactly 2
digits, T is either 'T' or ' ', '.' is either itself, or ',',
and 'frac' is one or more digits. Z (if given) is 'Z'. The
[.,]frac and Z fields are optional. Specify a time in a
slight shorthand like 2024-2-8T7:44:20 and the POSIX parse
will fail, leaving parsedate() to handle that (which it should).
But any fractional seconds which were given would be ignored.

Doc update coming - note the doc will call the YYYY field CCYY
instead, that's just a convenience to make other parts of what
is there make more sense - it is still one 4 (or more) digit field.

This should be an almost invisible change.
 1.36  08-Feb-2024  kre Sprinkle come const - but not too much of a good thing.

NFCI
 1.35  08-Feb-2024  kre Parameterise the "if year < 69 it is 20xx and if >=69 it is 19xx" rule
to make it simpler to (eventually, many years hence) to change that rule
to be "if year is < NN it is 21xx and if >= NN it is 20xx" instead.

Avoid comparing a time_t to -1 directly, as time_t might be unsigned.
Instead define NO_TIME as ((time_t)-1) and compare with that instead.
This makes no difference at all when time_t is signed (as it is on
NetBSD).

Use "ss" rather than "SS" as the seconds indicators (in messages)
to match with hh (hours) and mm (minutes) rather than looking like
some relation to YY (year) MM (month) and DD (day). Why this was
ever written as SS is beyond me, but it has been that way forever.
(doc update will follow).

Minor improvement to the error message if the arg to a -t option
is unable to be parsed correctly.

NMFCI (No meaningful...)
 1.34  08-Feb-2024  kre KNF (space after keyword, and 80 column police).

NFCI

(This is the first of a series of changes to be committed
in rapid sequence).
 1.33  02-Mar-2015  enami Don't truncate at microseconds while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html
 1.32  22-Oct-2012  christos branches: 1.32.8; 1.32.10;
Recognize --date and --reference like gnu.
 1.31  25-Jul-2012  christos branches: 1.31.2;
add an option to parse human dates.
 1.30  06-Sep-2011  joerg branches: 1.30.2;
ANSIfy, static + __dead
 1.29  22-Feb-2011  pooka -f no longer has effect. from Snader_LB on irc.
 1.28  28-Apr-2009  yamt branches: 1.28.2;
remove read-write code because it's dangerous.
there's no point to try this hard anyway.
 1.27  21-Jul-2008  lukem branches: 1.27.6;
Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
 1.26  18-Mar-2006  dsl branches: 1.26.22;
Coverty 1212: Avoid close(-1).
 1.25  26-Nov-2005  tsutsui Fix more FALLTHOUGH -> FALLTHROUGH typo.
 1.24  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
 1.23  05-Nov-1999  mycroft branches: 1.23.2;
Nit: In the compatibility case, set the seconds to 0.
 1.22  25-Aug-1998  ross branches: 1.22.4;
Add { and } to shut up egcs. Reformat the more questionable code.
 1.21  21-Jan-1998  mycroft Fix the old-style date parsing code as well.
 1.20  21-Jan-1998  mycroft Minor code rearrangement, and allow less of the time stamp to be specified.
 1.19  20-Jan-1998  mycroft Pull in tzfile.h.
 1.18  20-Jan-1998  mycroft Use TM_YEAR_BASE to adjust tm_year, not 1900.
 1.17  22-Oct-1997  fvdl Revert to previous version; new libc function "versioning" works
with the original.
 1.16  21-Oct-1997  thorpej Make this work with the new versioned stat(2) functions.
 1.15  20-Oct-1997  lukem branches: 1.15.2;
WARNSify, fix .Nm usage, getopt returns -1 not EOF
 1.14  19-Oct-1997  mycroft Purely cosmetic change.
 1.13  11-Oct-1997  enami Add h option to usage.
 1.12  06-Oct-1997  enami Introduce new flag, -h, to manupilate access/modification time of
symbolic link.
 1.11  31-Aug-1995  jtc Sync with 44lite2
 1.10  07-Jun-1995  cgd can't assume that timeval.ts_sec is same type as time_t. grr.
 1.9  07-Dec-1994  jtc Merged with 4.4lite.
Changed to conform to NetBSD's new RCS Id convention.
 1.8  31-Dec-1993  jtc Localization changes + minor bug fix.
 1.7  16-Sep-1993  cgd fix for "touch -t CCYYMMDDhhmm[.SS]". the CC part didn't work. from
Thomas Eberhardt <thomas@mathematik.uni-Bremen.de>
 1.6  07-Aug-1993  mycroft Add 4.4-specific code in `#ifdef notyet's.
 1.5  01-Aug-1993  mycroft Add RCS identifiers.
 1.4  02-Jun-1993  glass fix bug in touch's non-posix compatibility support. bug report also
forwarded to CSRG as this is their current 'touch'. bug reported by
Kim Andersen <kim@dde.dk>
 1.3  01-May-1993  mycroft s/__dead/volatile/
 1.2  30-Apr-1993  glass new touch
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3  31-Aug-1995  jtc imported from 44lite2
 1.1.1.2  07-Dec-1994  jtc imported from 4.4lite
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.15.2.3  29-Jan-1998  mellon Pull up 1.18-1.21 (mycroft)
 1.15.2.2  22-Oct-1997  thorpej Pull up from trunk: revert to previous revision.
 1.15.2.1  21-Oct-1997  thorpej Pull up from trunk:

Make this work with the new versioned stat(2) functions.
 1.22.4.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.23.2.2  05-Nov-1999  mycroft Nit: In the compatibility case, set the seconds to 0.
 1.23.2.1  05-Nov-1999  mycroft file touch.c was added on branch comdex-fall-1999 on 1999-11-05 04:54:11 +0000
 1.26.22.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.27.6.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.28.2.1  05-Mar-2011  bouyer Sync with HEAD
 1.30.2.1  30-Oct-2012  yamt sync with head
 1.31.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.32.10.1  03-Mar-2016  martin Pull up following revision(s) (requested by nakayama in ticket #1096):
bin/mv/mv.c: revision 1.44
bin/cp/utils.c: revision 1.43-1.44
lib/librumphijack/hijack.c: revision 1.112-1.115
usr.bin/touch/touch.c: revision 1.33
sbin/restore/tape.c: revision 1.68
sbin/restore/dirs.c: revision 1.51
Don't truncate at sub-microsecond while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html

Fix the name of failed function in warning message.

Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are
changed to use the system call. Linux also has this system call, but
not tested this on linux.

Also hijack futimens(2) so that t_sh test passes.

Define a generic ATCALL() and use it to implement utimensat()
Make ATCALL() behave for absolute paths too.
 1.32.8.1  03-Mar-2016  martin Pull up following revision(s) (requested by nakayama in ticket #1096):
bin/mv/mv.c: revision 1.44
bin/cp/utils.c: revision 1.43-1.44
lib/librumphijack/hijack.c: revision 1.112-1.115
usr.bin/touch/touch.c: revision 1.33
sbin/restore/tape.c: revision 1.68
sbin/restore/dirs.c: revision 1.51
Don't truncate at sub-microsecond while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html

Fix the name of failed function in warning message.

Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are
changed to use the system call. Linux also has this system call, but
not tested this on linux.

Also hijack futimens(2) so that t_sh test passes.

Define a generic ATCALL() and use it to implement utimensat()
Make ATCALL() behave for absolute paths too.

RSS XML Feed