Commit Graph

20741 Commits

Author SHA1 Message Date
kre b064b3fad8 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.
2024-02-10 00:19:30 +00:00
kre 69d75f9748 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.
2024-02-09 23:41:48 +00:00
andvar 100a3398b8 fix spelling mistakes, mainly in comments and log messages. 2024-02-09 22:08:30 +00:00
christos acaab79677 PR/57914: Jan-Benedict Glaw: Set reproducible timestamp
Cleanup lint.
2024-02-09 16:10:18 +00:00
rillig 82caa5d69a lint: clean up variable names, parameter order, comments
No functional change.
2024-02-08 20:59:19 +00:00
rillig 9296a8c8d9 lint: clean up redundant braces
No functional change.
2024-02-08 20:45:20 +00:00
andvar a5175f1e98 s/sharable/shareable in comments and documentation. 2024-02-08 20:11:55 +00:00
rillig 7d2bd99786 lint: clean up comments, add debug output for Bison 2024-02-08 19:32:12 +00:00
kre cfc0411834 Document the -d posix-datetime arg variation, to allow specifying
fractional seconds.   (Alternate ways to achieve that for the other
ways of specifying the date and time may be forthcoming in a future
update).

Also add a warning about the (still far) future likely change of
the interpretation of 2 digit years (the coming POSIX standard
contains a similar warning).

While here, clean up wording, some macro usage, etc etc etc...
2024-02-08 02:54:13 +00:00
kre a9640bbfb2 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).
2024-02-08 02:54:07 +00:00
kre 7724ab9123 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.
2024-02-08 02:53:53 +00:00
kre bda400655a Sprinkle come const - but not too much of a good thing.
NFCI
2024-02-08 02:53:40 +00:00
kre 1a8d06c811 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...)
2024-02-08 02:53:28 +00:00
kre 9298a61de3 KNF (space after keyword, and 80 column police).
NFCI

(This is the first of a series of changes to be committed
in rapid sequence).
2024-02-08 02:53:13 +00:00
rillig a30ba4f0a2 lint: use consistent variable names, reduce code for reading a byte
No functional change.
2024-02-07 08:00:36 +00:00
rillig 26428579ad lint: unify rules for determining the type of an integer constant
Previously, in traditional C mode, large decimal numbers were treated as
unsigned, which disagreed with the book from 1978.
2024-02-07 07:42:50 +00:00
rillig 716f56f56e make: remove redundant comments
No functional change.
2024-02-07 07:21:22 +00:00
rillig 0dd36725b6 make: remove unneeded conditional-compilation toggles
The toggles INCLUDES, LIBRARIES, POSIX, SYSVINCLUDE, SYSVVARSUB,
GMAKEEXPORT and SUNSHCMD are no longer needed, they were unconditionally
set.

The toggle NO_REGEX was configurable from the command line, but
disabling it would result in various error messages about the unknown
':C' modifier.

OK sjg@.
2024-02-07 06:43:02 +00:00
rillig bc8fe445c4 lint: tab-align message numbers in err.c
By replacing block comments with end-of-line comments, the comments take
up less space and thus no longer require to be indented by 6 spaces.

The messages and their comments are used in 3 places: the manual page
lint.7, the err-msgs.h header for debug mode, and check-msgs.lua to
verify that the comments above the message IDs correspond to the actual
messages.

No functional change.
2024-02-06 22:47:21 +00:00
rillig c4266104cb lint.7: remove implementation details from message list
From a user's perspective, it's irrelevant whether a lint message is
generated using '%s' or '%.*s'; same for the integer widths, as they are
platform-dependent.
2024-02-06 21:28:15 +00:00
rillig 5c34ad8f3f lint: make function call arguments directly accessible
Previously, the arguments of a function call expression were arranged in
a linear tree structure, from right to left.  To allow easier access to
the arguments, store them in an array instead.
2024-02-05 23:11:22 +00:00
andvar 82bba4e936 fix various typos in comments. 2024-02-05 21:46:04 +00:00
rillig 68c43e85ca make: do not evaluate indirect modifiers in parse-only mode
Discovered by sjg.
2024-02-04 10:03:10 +00:00
rillig 86d09a000c make: in parse-only mode, don't evaluate modifiers
Previously, the ':S', ':ts', ':tA' and ':from=to' modifiers were
evaluated in parse-only mode, unnecessarily.  This is only noticeable
when an indirect modifier is evaluated in parse-only mode, which is
another bug that will be fixed in a follow-up commit.
2024-02-04 09:56:24 +00:00
rillig 985de0af40 tests/make: extend test for wrong evaluation in parse-only mode 2024-02-04 09:29:50 +00:00
rillig 4aa832f99f tests/make: indirect modifiers are evaluated in parse-only mode
Found by sjg@.
2024-02-04 08:51:57 +00:00
mrg 2026b7285b update my email address. 2024-02-04 05:43:05 +00:00
mrg 8f36055f87 bump copyright and version. 2024-02-03 22:40:29 +00:00
rillig 139c6401cd lint: warn about short octal escape followed by '8' or '9'
These mistakes is typically found in snprintb format directives but is
probably a typo everywhere else as well.
2024-02-03 20:10:10 +00:00
rillig e6cddd1286 lint: remove excessive empty lines 2024-02-03 19:37:02 +00:00
rillig 095f481327 lint: keep strings in their source representation
This allows further analysis depending on whether individual characters are
escaped as octal, hexadecimal or not at all.
2024-02-03 19:25:16 +00:00
rillig 29354841ac lint: allow hexadecimal character escapes up to UINT_MAX
Previously, any value larger than INT_MAX was regarded as negative and
thus terminated the loop around get_escaped_char.
2024-02-03 18:58:05 +00:00
rillig ffb2a8ebeb lint: clean up comments, reduce scope of variables 2024-02-03 12:57:12 +00:00
rillig 661078afe6 lint: remove unused code for converting multibyte character sequences 2024-02-03 10:56:18 +00:00
rillig c1862de9dd lint: allow larger numbers in escapes for wide characters and strings 2024-02-03 10:01:58 +00:00
sjg 7106e16450 make: state of save_dollars affects what is a parse error
When save_dollars is false it is not a parse error to
encounter $$ rather than \$.
2024-02-03 00:20:23 +00:00
rillig 03951da31e lint: use the locale for interpreting wide character strings 2024-02-02 23:36:01 +00:00
andvar 947fbafb45 fix typos, mainly s/unsupport/unsupported/ in log messages. 2024-02-02 22:33:42 +00:00
rillig 8016349204 lint: fix debug output for strings, reduce code size
The debug output contained too many newlines.

The buffer functions were built into lint2 even though they weren't
used.

Enable the query for invisible characters in string literals, to make
sure that a newline in a string literal does not trigger that query.
2024-02-02 16:25:58 +00:00
rillig 402b4579b3 lint: make newline in a string literal an error in C90 and later 2024-02-02 16:05:37 +00:00
rillig 2f96b2b84b lint: reuse buffer editing code across lint1
Fix cat_strings to update the capacity of the buffer, to prevent
quadratic runtime when concatenating string literals.
2024-02-01 21:19:13 +00:00
rillig c9edda031f lint: use standard buffer for storing string values
No functional change.
2024-02-01 18:37:06 +00:00
christos 283a7ed9be fix tools build 2024-01-29 22:01:58 +00:00
christos ed7b026d6f PR/57891: Ricardo Branco: add symbolic flags printing (from FreeBSD) 2024-01-29 21:55:24 +00:00
rillig 9e650a18b6 lint: do not remember content of wide string literals
The plain char literals are needed for checking printf/scanf format
strings; lint has no similar check for wide strings. These format
strings are checked by modern compilers, making this check less
relevant.
2024-01-29 21:30:24 +00:00
rillig 49766a0931 lint: check getopt call more strictly
Previously, '(c = getopt(...)) != -2' would match as well.
2024-01-29 21:04:21 +00:00
rillig 8c7fbc585c lint: fix type of large integer constants 2024-01-27 20:03:14 +00:00
christos 063b07317d PR/57875: Jason Bacon: Try again without an _ for portability. 2024-01-27 16:04:36 +00:00
rillig 708007c3c9 lint: split determining the type of an integer constant
No functional change.
2024-01-27 15:53:27 +00:00
rillig 32781b5733 lint: extract signedness detection from lexing an integer constant
An integer constant that is signed in traditional C but unsigned since
C90 is an edge case that should not clutter the main code of determining
the resulting type of the constant.

The code for lexing an integer constant doesn't implement the C99 rules
yet, which convert a constant to the 'long long' types if the 'long'
types don't suffice.
2024-01-27 12:14:58 +00:00