Compare commits

..

212 Commits
v9.0 ... v9.1

Author SHA1 Message Date
Pádraig Brady
ca22b9eba0 version 9.1
* NEWS: Record release date.
2022-04-15 22:10:07 +01:00
Pádraig Brady
0f2cf20af6 doc: avoid unicode errors in texi conversion
Avoid "Unicode character U+#1 not supported, sorry" error
when converting from texi to dvi or pdf.

* doc/coreutils.texi (tr invocation): Avoid the @U{XXXX}
texi representation, as even though info and html can represent
these characters directly, there are conversion errors
for pdf and dvi.  Instead use the more abstract shell
$'\uXXXX' representation.
2022-04-15 18:28:38 +01:00
Pádraig Brady
bcfbcef928 build: copy: fix build on macos 10.12
* src/copy.c (copy_reg): Handle the case where CLONE_NOOWNERCOPY
is not defined.
Reported by Jeffrey Walton
2022-04-14 13:37:23 +01:00
Pádraig Brady
87d5f1e17e tail: detect closed stdout on Solaris
* src/tail.c (check_output_alive): Use poll() on Solaris.
Also handle POLLHUP, which Solaris returns in this case.
* tests/tail-2/pipe-f.sh: Use `head -n2` rather than `sed 2q`
as Solaris sed does not exit in this case.
* NEWS: Mention the improvement.
Reported by Bruno Haible.
2022-04-13 20:10:14 +01:00
Pádraig Brady
48e15cef45 maint: syntax-check: fix preprocessor indentation
* gl/lib/targetdir.h: Keep '#' at start of line.
2022-04-13 12:21:01 +01:00
Paul Eggert
b411f21414 cp,mv,install: omit an ‘inline’
* gl/lib/targetdir.c (target_directory_operand):
Omit unnecessary ‘inline’.
2022-04-12 23:57:15 -07:00
Paul Eggert
f0a9f5e7da cp,mv,install: improve EACCES targetdir messages
This improves on the fix for --target-directory diagnostics bugs on
Solaris 11.  Problem reported by Bruno Haible and Pádraig Brady; see:
https://lists.gnu.org/r/coreutils/2022-04/msg00044.html
Also, omit some unnecessary stat calls.
* gl/lib/targetdir.c (target_directory_operand): If !O_DIRECTORY,
do not bother calling open if stat failed with errno != EOVERFLOW.
Rename is_a_dir to try_to_open since that’s closer to what it means.
If the open failed with EACCES and we used O_SEARCH, look at stat
results to see whether errno should be ENOTDIR for better diagnostics.
Treat EOVERFLOW as an “I don’t know whether it’s a directory and
there’s no easy way to find out” rather than as an error.
2022-04-12 23:57:15 -07:00
Paul Eggert
197a570ff0 cp,mv,install: avoid excess stat calls on non-GNU
* gl/lib/targetdir.c (target_directory_operand): New arg ST.
All callers changed.
* src/cp.c (do_copy):
* src/mv.c (main):
Avoid unnecessary stat call if target_directory_operand already
got the status.
2022-04-12 23:57:15 -07:00
Paul Eggert
30c932a309 cp,mv,install: modularize targetdir
Move target directory code out of system.h to a new targetdir module.
This doesn’t change functionality.
* bootstrap.conf (gnulib_modules): Add targetdir.
* src/cp.c, src/install.c, src/mv.c: Include targetdir.h.
* src/system.h (must_be_working_directory, target_directory_operand)
(targetdir_dirfd_valid): Move from here ...
* gl/lib/targetdir.c, gl/lib/targetdir.h, gl/modules/targetdir:
... to these new files.
2022-04-12 23:57:15 -07:00
Pádraig Brady
52139fd690 cp,mv,install: avoid EACCES with non directory destination
* src/system.h (target_directory_operand): Also check with stat()
on systems with O_SEARCH, to avoid open("file", O_SEARCH|O_DIRECTORY)
returning EACCES rather than ENOTDIR, which was seen on Solaris 11.4
when operating on non dirs without execute bit set.
* NEWS: Remove related bug entry, as that issue was only introduced
after coreutils v9.0 was released.
Reported by Bruno Haible.
2022-04-13 00:37:12 +01:00
Pádraig Brady
6e9bf0765f sync: support syncing files on cygwin
* src/sync.c (sync_arg): Similarly to AIX, Cygwin 2.9.0
was seen to need write access to have permission to sync a file.
2022-04-13 00:36:25 +01:00
Pádraig Brady
4f920e93ec tests: cygwin: handle ENOENT from execvp(".")
* tests/misc/env.sh: Verify with another command that
execvp() doesn not return ENOENT, before testing the
exit code from the command in question.
* tests/misc/nice-fail.sh: Likewise.
* tests/misc/stdbuf.sh: Likewise.
* tests/misc/timeout-parameters.sh: Likewise.
2022-04-13 00:36:25 +01:00
Pádraig Brady
f98dcbfc1c tests: env-S.pl: unset cygwin hardwired env vars
* tests/misc/env-S.pl: Unset SYSTEMROOT and WINDIR.
2022-04-13 00:36:25 +01:00
Pádraig Brady
028cad9149 tests: md5sum: fix false failures on cygwin
* tests/misc/md5sum-newline.pl: Avoid binary '*' tags when
comparing checksums.
* tests/misc/md5sum-bsd.sh: Avoid binary '*' tags so that we correctly
trigger the ambiguity test.
Reported by Bruno Haible
2022-04-12 13:30:50 +01:00
Pádraig Brady
2122ceba8e tests: b2sum.sh: fix false failure on cygwin
* tests/misc/b2sum.sh: Avoid binary '*' tags when comparing checksums.
Reported by Bruno Haible
2022-04-11 15:47:16 +01:00
Pádraig Brady
e43099f6e9 tests: dircolors.pl: avoid false failure with TERM=dumb
* tests/Coreutils.pm: Ensure an unset $TERM env var,
which is required on perl 5.22.2 on Solaris 11 OpenIndiana at least,
where TERM was being reset to 'dumb'.
Reported By Bruno Haible.
2022-04-11 15:47:16 +01:00
Pádraig Brady
021fc4fad2 tests: printf-mb.sh: fix false failure with french translations
* tests/misc/printf-mb.sh: As per commit 04148c99c,
adjust non C warnings before comparison, to those of LC_MESSAGES=C.
Reported by Adam Sampson
2022-04-11 15:46:57 +01:00
Pádraig Brady
046ab76166 tests: stty.sh: skip on systems without perl
* init.cfg (stty_reversible_init_): Add require_perl_
to ensure we skip rather than error, without perl.
2022-04-10 15:48:29 +01:00
Pádraig Brady
cc01b8a8f4 cp,mv,install: avoid opening non directory destination
commit v9.0-66-ge2daa8f79 introduced an issue, for example
where cp could hang when overwriting a destination fifo,
when it would try to open() the fifo on systems
like Solaris 10 that didn't support the O_DIRECTORY flag.

This is still racy on such systems, but only in the
case where a directory is replaced by a fifo in
the small window between stat() and open().

* src/system.h (target_directory_operand): On systems without
O_DIRECTORY, ensure the file is a directory before attempting to open().
* tests/cp/special-f.sh: Protect cp with timeout(1),
as cp was seen to hang when trying to overwrite an existing fifo.
* NEWS: Mention the bug fix.
2022-04-09 22:21:24 +01:00
Pádraig Brady
54bec51754 doc: install --compare: clarify mode of operation
* doc/coreutils.texi (install invocation): For the --compare option,
clarify that the ownership or permissions of the source files don't
matter.  Also don't imply --owner or --group need to be specified
for --compare to be effective.
* src/install.c (usage): Add more detail on what's being compared.
Fixes https://bugs.gnu.org/50889
2022-04-09 13:00:52 +01:00
Pádraig Brady
d28e369960 doc: remove older ChangeLog items
* Makefile.am: Update the oldest documented version
to 8.27 which is now about 5 years old.
2022-04-08 17:08:32 +01:00
Bernhard Voelker
8f1f0dc975 maint: remove obsolete statat gnulib module
* bootstrap.conf (gnulib_modules): Remove statat.
2022-04-08 17:05:56 +01:00
Pádraig Brady
73c0c15225 build: update gnulib submodule to latest
* gnulib: Update to latest
* src/copy.c: Replace deprecated {l,}statat(), with fstatat().
* src/cp.c: Likewise.
* src/install.c: Likewise.
* src/remove.c: Likewise.
2022-04-07 17:38:17 +01:00
Pádraig Brady
224c1fee69 factor: improve support on RISCV and loongson
* src/longlong.h: Pull in RISCV fix and loongarch64 support from
https://gmplib.org/repo/gmp/log/tip/longlong.h
2022-04-04 13:41:32 +01:00
Pádraig Brady
8d9321ee0f doc: describe dd iseek as a feature not a change
* NEWS: Move description from "Changes in behavior"
to "New features".
2022-04-03 22:11:25 +01:00
Pádraig Brady
6b5134770d ls: avoid expensive capability lookup by default
Lookup of file-based capabilities adds 30% overhead to the common
case of ls --color usage.  Since the use of file capabilities is
very rare, it doesn't make sense to pay this cost in the common
case.  It's better to use getcap to inspect capabilities, and the
following run shows only 8 files using capabilities on my fedora
35 distro (14 years after the feature was introduced to the linux
kernel).

  $ getcap -r /
  /usr/bin/arping = cap_net_raw+p
  /usr/bin/clockdiff = cap_net_raw+p
  /usr/bin/gnome-keyring-daemon = cap_ipc_lock+ep
  /usr/bin/gnome-shell = cap_sys_nice+ep
  /usr/bin/newgidmap = cap_setgid+ep
  /usr/bin/newuidmap = cap_setuid+ep
  /usr/sbin/mtr-packet = cap_net_raw+ep
  /usr/sbin/suexec = cap_setgid,cap_setuid+ep

* src/dircolors.hin: Set "CAPABILITY" to "00", to indicate unused.
* src/ls.c: Set the default C_CAP color to not colored.
* NEWS: Mention the change in behavior.
2022-04-03 22:10:35 +01:00
Ville Skyttä
52aeae2c3d dircolors: colorize backup files with bright black
* src/dircolors.hin: Add patterns for suffixes for "backup files".
The color used is so they stand out less than non-backup files,
and bright black works well on both light and dark backgrounds.
* THANKS.in: Remove duplicate.
Fixes https://bugs.gnu.org/54521
2022-04-03 20:59:38 +01:00
Pádraig Brady
120ce321d5 doc: join: clarify that -e only effective for -12jo fields
* src/join.c (usage): Clarify that -e is not sufficient
to enable output of missing fields from one of the inputs.
Rather the -12jo options are required to explicitly
enable output of those fields.
Fixes https://bugs.gnu.org/54625
2022-03-29 16:34:10 +01:00
Pádraig Brady
e07c40c3ea maint: sync latest bootstrap from gnulib
* bootstrap: Should have updated this with the last gnulib update.
2022-03-25 19:08:28 +00:00
Pádraig Brady
500c697cc8 tests: improve recent printf test
* tests/misc/printf-mb.sh: Given we shortcut the single char
(invalid multi-byte) case, add a case to ensure we're correctly
checking the return from mbrtowc().
2022-03-20 17:46:13 +00:00
Pádraig Brady
6367cfe5fc printf: support printing the numeric value of multi-byte chars
* src/printf.c (STRTOX): Update to support multi-byte chars.
* tests/misc/printf-mb.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the improvement.
Fixes https://bugs.gnu.org/54388
2022-03-19 16:57:07 +00:00
Pádraig Brady
28adf9cf58 maint: move build-related NEWS item to its own section
* NEWS: Follow other Build-related patterns in NEWS.
2022-03-18 15:02:42 +00:00
Pádraig Brady
aa53e73974 doc: test: clarify that -rwx don't just check perm bits
* src/test.c (usage): State that -rwx is determined by
user access, rather than permission bits.
* doc/coreutils.texi (Access permission tests): Likewise.
* man/test.x [SEE ALSO]: access(2).
Fixes https://bugs.gnu.org/54338
2022-03-12 13:19:06 +00:00
Pádraig Brady
8767d75b9d maint: address syntax-check issues in recent commit
* cfg.mk (sc_die_EXIT_FAILURE): Generalize to match any EXIT_ define,
and also relax to ignore error() usage with ternary operator.
* src/chroot.c (main): Use () to avoid the sc_error_quotes check.
2022-03-07 23:33:25 +00:00
Pádraig Brady
92cb8427c5 stat: only automount with --cached=never
Revert to the default behavior before the introduction of statx().

* src/stat.c (do_stat): Set AT_NO_AUTOMOUNT without --cached=never.
* doc/coreutils.texi (stat invocation): Mention the automount
behavior with --cached=never.
* NEWS: Mention the change in behavior.

Fixes https://bugs.gnu.org/54287
2022-03-07 23:33:21 +00:00
Rohan Sable
85c975df2c ls: avoid triggering automounts
statx() has different defaults wrt automounting
compared to stat() or lstat(), so explicitly
set the AT_NO_AUTOMOUNT flag to suppress that behavior,
and avoid unintended operations or potential errors.

* src/ls.c (do_statx): Pass AT_NO_AUTOMOUNT to avoid this behavior.
* NEWS: Mention the change in behavior.
Fixes https://bugs.gnu.org/54286

Signed-off-by: Rohan Sable <rsable@redhat.com>
2022-03-07 23:26:42 +00:00
Pádraig Brady
3f61958495 build: ensure AT_NO_AUTOMOUNT is defined
update gnulib submodule to latest,
where this is the only change
2022-03-07 22:00:22 +00:00
Paul Eggert
4306bb6246 date: fix newly-introduced %%-N bug
* src/date.c (adjust_resolution): Don’t mishandle %%-N.
* tests/misc/date.pl (pct-pct): New test.
2022-03-05 11:23:38 -08:00
Paul Eggert
8f31074cb4 chown: warn about USER.GROUP
Suggested by Dan Jacobson (Bug#44770).
* src/chown.c, src/chroot.c (main):
Issue warnings if obsolete USER.GROUP notation is present.
2022-02-24 18:19:40 -08:00
Paul Eggert
3abaa2ad67 build: update gnulib submodule to latest 2022-02-24 18:19:40 -08:00
Pádraig Brady
6dc702928e fmt: fix invalid multi-byte splitting on macOS
On macOS, isspace(0x85) returns true,
which results in splitting within multi-byte characters.

* src/fmt.c (get_line): s/isspace/c_isspace/.
* tests/fmt/non-space.sh: Add a new test.
* tests/local.mk: Reference new test.
* NEWS: Mention the fix.
Addresses https://bugs.gnu.org/54124
2022-02-24 13:58:06 +00:00
Pádraig Brady
677fb3e4ab tests: improve compat with macOS
* tests/misc/wc-nbsp.sh: Only the en_US.iso8859-1 form
is accepted on macOS 10.15.7 at least.  GNU/Linux also
accepts ISO-8859-1 (and canonicalizes the charmap to this).
2022-02-24 13:58:06 +00:00
Paul Eggert
97e9778296 dd: counts ending in "B" now count bytes
This implements my suggestion in Bug#54112.
* src/dd.c (usage): Document the change.
(parse_integer, scanargs): Implement the change.
Omit some now-obsolete checks for invalid flags.
* tests/dd/bytes.sh: Test the new behavior, while retaining
checks for the now-obsolete usage.
* tests/dd/nocache_eof.sh: Avoid now-obsolete usage.
2022-02-22 18:56:53 -08:00
Paul Eggert
ef694d3448 dd: improve doc relative to POSIX
* doc/coreutils.texi (dd invocation): Improve documentation,
clarifying whether features are extensions to POSIX.
2022-02-22 09:04:27 -08:00
Paul Eggert
4439ef3ec4 dd: support iseek= and oseek=
Alias iseek=N to skip=N, oseek=N to seek=N (Bug#45648).
* src/dd.c (scanargs): Parse iseek= and oseek=.
* tests/dd/skip-seek.pl (sk-seek5): New test case.
2022-02-22 09:04:27 -08:00
Paul Eggert
3f7519130a cp: avoid unnecessary buffer allocation
Do not allocate I/O buffer if copy_file_range suffices.
* src/copy.c (sparse_copy, lseek_copy): Buffer arg is now char **
instead of char *, and buffer is now allocated only if needed.
All uses changed.
2022-02-21 00:19:24 -08:00
Paul Eggert
7dbe465fd3 build: update gnulib submodule to latest 2022-02-19 15:54:45 -08:00
Pádraig Brady
cee468f9c5 doc: env: fix man page reference of exec(2) to exec(3p)
* man/env.x: Change exec() reference from section 2 to 3p.
2022-02-15 17:07:22 +00:00
Pádraig Brady
63228501e6 doc: use bold style for man page references
It's more common to use bold style than not,
for references to other man pages.
Ideally each man page renderer would highlight references,
but currently some rely on styles in the page itself.

* man/help2man: Implement a --bold-refs option that
will mark up references like "name(1)" with bold
style around the "name" component.
* man/local.mk: Pass --bold-refs to our help2man unless disabled.
* configure.ac: Add a --disable-bold-man-page-references option.
Addresses https://bugs.gnu.org/53977
2022-02-15 17:07:22 +00:00
Pádraig Brady
041dfff5db dircolors: speed up processing of TERM entries
* src/dircolors.c (main): Avoid glob matching
when we've already matched in a group of {COLOR,}TERM entries.
2022-02-15 17:01:19 +00:00
Pádraig Brady
75c9fc6740 dircolors: consider COLORTERM as well as TERM env vars
COLORTERM is an environment used usually to expose truecolor support in
terminal emulators.  Therefore support matches on that in addition
to TERM.  Also set the default COLORTERM match pattern so that
we apply colors if COLORTERM is any value.

This implicitly supports a terminal like "foot"
without a need for an explicit TERM entry.

* NEWS: Mention the new feature.
* src/dircolors.c (main): Match COLORTERM like we do for TERM.
* src/dircolors.hin: Add default config to match any COLORTERM.
* tests/misc/dircolors.pl: Add test cases.
2022-02-15 17:01:19 +00:00
Paul Eggert
0b0f1965fb tr: mention multibyte problem in man page
* man/tr.x: Document tr problem.
2022-02-14 12:16:40 -08:00
Paul Eggert
8d3dce9861 tr: improve multibyte etc. doc
Problem reported by Dan Jacobson (Bug#48248).
* doc/coreutils.texi (tr invocation): Improve documentation for
tr's failure to support multibyte characters POSIX-style.
* doc/coreutils.texi (tr invocation), src/tr.c (usage):
Use terminology closer to POSIX's.
2022-02-14 12:03:49 -08:00
Pádraig Brady
abc4533fe4 dircolors: add --print-ls-colors to display colored entries
* NEWS: Mention the new feature.
* doc/coreutils.texi (dircolors invocation): Describe the new
--print-ls-colors option.
* src/dircolors.c (print_ls_colors): A new global to select
between shell or terminal output.
(append_entry): A new function refactored from dc_parse_stream()
to append the entry in the appropriate format.
(dc_parse_stream): Adjust to call append_entry().
* tests/misc/dircolors.pl: Add test cases.
2022-02-13 18:25:59 +00:00
Pádraig Brady
26db930c81 chown,chgrp: reinstate numeric id output in -v messages
since gnulib commit ff208d546a,
related to coreutils commit v9.0-143-gabde15969
we no longer maintain numeric IDs through chopt->{user,group}_name.
Therefore we need to adjust to ensure tests/chown/basic.sh passes.

* src/chown-core.c (uid_to_str, gid_to_str): New helper functions
to convert numeric id to string.
(change_file_owner): Use the above new functions to pass
numeric ids to describe_change().
2022-02-13 14:20:16 +00:00
Paul Eggert
d8047ae86d sort: fix several version-sort problems
This also affects ls -v in some corner cases.
Problems reported by Michael Debertol <https://bugs.gnu.org/49239>.
While looking into this, I spotted some more areas where the
code and documentation did not agree, or where the documentation
was unclear.  In some cases I changed the code; in others
the documentation.  I hope things are nailed down better now.
* doc/sort-version.texi: Distinguish more carefully between
characters and bytes.  Say that non-identical strings can
compare equal, since they now can.  Improve readability in
various ways.  Make it clearer that a suffix can be the
entire string.
* src/ls.c (cmp_version): Fall back on strcmp if filevercmp
reports equality, since filevercmp is no longer a total order.
* src/sort.c (keycompare): Use filenvercmp, to treat NULs correctly.
* tests/misc/ls-misc.pl (v_files):
Adjust test to match new behavior.
* tests/misc/sort-version.sh: Add tests for stability,
and for sorting with NUL bytes.
2022-02-12 20:15:03 -08:00
Paul Eggert
e7ccf4775e build: update gnulib submodule to latest 2022-02-12 20:15:02 -08:00
Pádraig Brady
195e943be7 doc: avoid using "[" is URLS in --help output
* src/system.h (emit_ancillary_info): While supported if entered
  manually, the "[" character is not highlighted as part of a
  URL by default in terminals, so avoid using it.
  Addresses https://bugs.gnu.org/53946
2022-02-12 18:43:25 +00:00
Pádraig Brady
d35b305109 doc: adust --help, --version alignment
* src/system.h: Adjust the alignment of the --help
and --version option descriptions, to start at column 21.
This better aligns with the descriptions of most commands,
and also aligns with the minimum column a description must
start at to ensure a blank line is not output when a description
follows an option on a line by itself.
2022-02-12 18:23:48 +00:00
Pádraig Brady
a4d8d58429 doc: rmdir: improve --help formatting
* src/rmdir.c (usage): Move description to column 21,
so that a --long-option on its own line without a
trailing description, doesn't have an erroneous blank
line inserted between the option and description.
Also group descriptions with blank lines rather than indents,
so that man pages don't have erroneous blank lines
added within the description.
Addresses https://bugs.gnu.org/53946
2022-02-12 18:16:34 +00:00
Pádraig Brady
dc689eba57 doc: ls: reference dircolors(1) from --help
* src/ls.c (usage): s/dircolors/dircolors(1)/.
* man/ls.x [SEE ALSO]: Reference dircolors(1).
Addresses https://bugs.gnu.org/53946
2022-02-12 18:03:38 +00:00
Pádraig Brady
353ba4978f doc: ls: improve --help formatting
* src/ls.c (usage): Use blank lines to group multi-line
option descriptions, rather than indenting.
This results in more consistent alignment of descriptions,
and also avoids erroneous new lines in generated in man pages.
Addresses https://bugs.gnu.org/53946
2022-02-12 17:55:03 +00:00
Paul Eggert
cedf627a90 doc: improve version-sort doc
* doc/coreutils.texi, doc/sort-version.texi:
Capitalize “Coreutils”.
* doc/sort-version.texi: Don’t emphasize natural sort so much,
since Coreutils has just version sort.
Use the term “lexicographic” instead of “alphabetic” or “standard”.
Suggest combining ‘V’ with ‘b’, and show why ‘b’ is needed.
Use shorter titles for sections, as GNU Emacs displays info poorly
when titles are too long to fit in a line.
Use @samp instead of @code for samples of data.
Do not use @samp{@code{...}}; @samp{...} should suffice and
double-nesting looks bad with Emacs.
Omit blank lines in examples that would not be present
in actual shell sessions.
Quote with `` and '', not with " or with '.
Mention dpkg --compare-versions more prominently.
Don’t rely on "\n" being equivalent to "\\n" in shell args.
Prefer Unicode name for hyphen-minus.
2022-02-08 10:52:43 -08:00
Christian Hesse
b65ff7e4d0 dircolors: highlight .avif as image
This add highlighting for AV1 Image File Format (AVIF):
https://aomediacodec.github.io/av1-avif/

* src/dircolors.hin: Highlight .avif as image.

Signed-off-by: Christian Hesse <mail@eworm.de>
2022-02-07 13:51:24 +00:00
Paul Eggert
8a3dedfef9 date: test against bug#50115
* tests/misc/date.pl: Add test.
2022-02-05 13:47:07 -08:00
Paul Eggert
cf6c849899 build: update gnulib submodule to latest 2022-02-05 13:47:07 -08:00
Pádraig Brady
b52d66452d doc: fix somewhat ambiguous date format representation
* doc/coreutils.texi (date invocation): Remove @var{...} usage,
as that capitalizes in the representation and thus somewhat
ambiguates the format wrt Month and Minute.  This also avoids
a syntax check failure about redundant capitalization in @var{}.
2022-02-05 12:53:19 +00:00
Paul Eggert
67cd2c3b72 date: improve doc
Problem reported by Dan Jacobson (Bug#51288).
* doc/coreutils.texi (date invocation, Setting the time)
(Options for date):
* src/date.c (usage): Improve doc.
2022-02-04 18:21:46 -08:00
Paul Eggert
413a6cf521 build: update gnulib submodule to latest 2022-02-04 17:43:45 -08:00
Paul Eggert
abde159693 id: print groups of listed name
Problem reported by Vladimir D. Seleznev (Bug#53631).
* src/id.c (main): Do not canonicalize user name before
deciding what groups the user belongs to.
2022-02-04 14:53:35 -08:00
Bernhard Voelker
9a29ee2903 doc: add NEWS entry for recent cksum change
* NEWS (Changes in behavior): Add entry for commit v9.0-92-ga42a03913.
2022-02-01 13:13:05 +00:00
Paul Eggert
59da65b7fe maint: suppress bogus noreturn warnings
* configure.ac: Move the single-binary code before the
gcc-warnings code, so that the latter can depend on the former.
Suppress -Wsuggest-attribute=noreturn with single binaries,
to avoid diagnostics like the following:
  src/expr.c: In function 'single_binary_main_expr':
  error: function might be candidate for attribute 'noreturn'
Problem reported by Pádraig Brady in:
https://lists.gnu.org/r/coreutils/2022-01/msg00061.html
2022-01-31 22:09:37 -08:00
Paul Eggert
1b552e73e8 tr: pacify -fsanitizer=leak
* src/tr.c (main): Use main_exit, not return, in a couple of
places missed last time.
2022-01-31 22:09:37 -08:00
Paul Eggert
222eee9631 chgrp: fix typo in previous change
* src/chgrp.c (main): Use main_exit, not exit.
2022-01-31 22:09:37 -08:00
Paul Eggert
bcc479b0b5 maint: mark some _Noreturn functions
* src/basenc.c (finish_and_exit, do_encode, do_decode):
* src/comm.c (compare_files):
* src/tsort.c (tsort):
* src/uptime.c (uptime):
Mark with _Noreturn.  Otherwise, unoptimized compilations may warn
that the calling renamed-main function doesn't return a value,
when !lint and when single-binary.
2022-01-31 22:09:37 -08:00
Paul Eggert
fb7579768d df: fix memory leak
* src/df.c (devlist_free): Remove.
(filter_mount_list): Free all of devlist, instead of merely
the entries in devlist_table.
2022-01-31 22:09:37 -08:00
Pádraig Brady
253a46d09f maint: cut: avoid exporting recently added variable
* src/cut.c: Make output_delimiter_default static,
as identified by `make syntax-check`.
2022-01-31 22:00:12 +00:00
Paul Eggert
eb3cd9e97b maint: pacify gcc -flto -Wmaybe-uninitialized
* gl/lib/xdectoint.c (__xnumtoint): Tell gcc that ‘error’
does not return here.
* gl/modules/xdectoint (Depends-on): Add stdbool, verify.
2022-01-31 12:07:39 -08:00
Paul Eggert
604f8a6c4d dd: do not access uninitialized
* src/dd.c (parse_integer): Avoid undefined behavior
that accesses an uninitialized ‘n’ when e == LONGINT_INVALID.
Return more-accurate error code when INTMAX_MAX < n.
2022-01-31 12:07:39 -08:00
Paul Eggert
d0e3b0ae1a uptime: simplify -fsanitize=leak pacification
* src/uptime.c (uptime): Exit here ...
(main): ... instead of here.
2022-01-31 12:07:39 -08:00
Paul Eggert
701fcbc78e uniq: remove IF_LINT
* src/uniq.c (check_file): Remove a no-longer-needed IF_LINT.
2022-01-31 12:07:39 -08:00
Paul Eggert
cb99998abe unexpand: remove IF_LINT
* src/unexpand.c (unexpand): Remove a no-longer-needed IF_LINT.
2022-01-31 12:07:39 -08:00
Paul Eggert
0ea9aacee9 pr: remove IF_LINT
* src/pr.c (read_line): Remove a no-longer-needed IF_LINT.
2022-01-31 12:07:39 -08:00
Paul Eggert
10ded12481 truncate: simplify
* src/truncate.c (do_ftruncate): Check != 0 instead of == -1.
Avoid a cast.
(main): Use C99 style decls after statements.
Simplify ‘open’ logic.
2022-01-31 12:07:39 -08:00
Paul Eggert
f8664b6c8e shred: remove IF_LINT
* src/shred.c (dopass): Remove a no-longer-needed IF_LINT.

(read_line): Remove an IF_LINT; no longer needed with
today’s GCC.
2022-01-31 12:07:39 -08:00
Paul Eggert
5288f5ab5e pr: simplify -fsanitize=leak pacification
* src/pr.c (main): Remove an IF_LINT.
Use main_exit rather than return.
2022-01-31 12:07:39 -08:00
Paul Eggert
75a87dc038 pinky: simplify -fsanitize=leak pacification
* src/pinky.c (short_pinky): exit instead of freeing.
2022-01-31 12:07:39 -08:00
Paul Eggert
00973ca777 paste: remove IF_LINT
* src/paste.c (paste_parallel): Remove no-longer-needed IF_LINT.
2022-01-31 12:07:39 -08:00
Paul Eggert
aafa9bf069 hostname: simplify
* src/hostname.c (sethostname): Provide a substitute on all
platforms, to simplify the mainline code.
(main): Simplify.  Remove an IF_LINT.
Use main_exit rather than return.
2022-01-31 12:07:39 -08:00
Paul Eggert
dba02d1996 factor: remove IF_LINT
* src/factor.c (factor_using_squfof) [USE_SQUFOF]:
Use plain assert (...), not IF_LINT (assert (...)).
This code is currently never compiled or executed,
so this is merely a symbolic cleanup.
2022-01-31 12:07:39 -08:00
Paul Eggert
ec8f3ea958 expand: remove IF_LINT
* src/expand.c (expand): Remove no-longer-needed IF_LINT.
2022-01-31 12:07:39 -08:00
Paul Eggert
ed93b50eea env: simplify -fsanitize=leak pacification
* src/env.c (unset_envvars): Remove IF_LINT code.
(main): Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
04d735ea96 md5sum: remove IF_LINTs
* src/digest.c (digest_check): Remove IF_LINTs that are no longer
needed, as GCC has gotten smarter since 2008.
2022-01-31 12:07:39 -08:00
Paul Eggert
c55372d0d8 df: simplify -fsanitize=leak pacification
* src/df.c (print_table, main) [lint]: Omit unnecessary cleanup.
(main): Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
7e7ecf20aa date: simplify -fsanitize=leak pacification
* src/date.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
423fed3dd8 cut: simplify and remove an IF_LINT
* src/cut.c (enum operating_mode, operating_mode)
(output_delimiter_specified, cut_stream):
Remove; no longer needed.
(output_delimiter_default): New static var.  Code can now
use ‘output_delimiter_string != output_delimiter_default’
instead of ‘output_delimiter_specified’.
(cut_file): New arg CUT_STREAM.  Caller changed.
(main): Simplify.  Coalesce duplicate code.  Redo to avoid need
for IF_LINT, or for the static var.  No need to xstrdup optarg.
2022-01-31 12:07:39 -08:00
Paul Eggert
22a0f9c32e cut: simplify -fsanitize=leak pacification
* src/set-fields.c (reset_fields): Remove, as it’s not needed for
-fsanitize=leak even when ‘lint’ is defined.  All uses removed.
2022-01-31 12:07:39 -08:00
Paul Eggert
836617fa12 cp: simplify GCC pacification
* src/cp.c (make_dir_parents_private): Remove IF_LINT code that is
no longer needed, as GCC has apparently gotten smarter since 2008.
2022-01-31 12:07:39 -08:00
Paul Eggert
904f9e3bf4 chown: simplify -fsanitize=leak pacification
* src/chgrp.c, src/chown.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
e55ffab35b basenc: simplify -fsanitize=leak pacification
* src/basenc.c (finish_and_exit): New function.
(do_encode, do_decode): Use it.  Accept new INFILE arg.  Remove
no-longer-needed IF_LINT code.  Exit when done.  Caller changed.
2022-01-31 12:07:39 -08:00
Paul Eggert
e2feea68ac test: simplify gcc pacification
* src/test.c (get_mtime) [lint]: Omit ifdef lint code that is no
longer needed, as GCC has gotten smarter since 2005.
2022-01-31 12:07:39 -08:00
Paul Eggert
a72fc9ba5f tail: simplify -fsanitize=leak pacification
Also, close a no-longer-needed file descriptor when falling
back from inotify.
* src/tail.c (tail_forever_inotify): Return void, not bool.  Exit
on fatal error, or on successful completion.  Accept an extra
argument pointing to a hash table that the caller should free on
non-fatal error; this simplifies cleanup.  Don’t bother setting
errno when returning.  Caller changed.
(main): Omit no-longer-needed IF_LINT code.  Close inotify
descriptor if inotify fails; this fixes a file descriptor leak and
means we needn’t call inotify_rm_watch.  Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
f3984a6dba tac: simplify -fsanitize=leak pacification
* src/tac.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
0106b5a4b8 shuf: simplify -fsanitize=leak pacification
* src/shuf.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
8692f2a6d3 numfmt: simplify -fsanitize=leak pacification
* src/numfmt.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
6ca7266666 mktemp: simplify -fsanitize=leak pacification
* src/mktemp.c (main) [lint]: Omit unnecessary cleanup.
Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
d85374258a dd: simplify -fsanitize=leak pacification
* src/dd.c (cleanup) [lint]: Omit unnecessary cleanup.
(main): Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
f21ccfb02c cp: simplify cp/install/ln/mv pacification
* src/copy.c (dest_info_free, src_info_free) [lint]:
Remove.  All uses removed.
(copy_internal): Pacify only Clang and Coverity; GCC doesn’t need it.
* src/cp-hash.c (forget_all) [lint]: Remove.  All uses removed.
* src/cp.c, src/install.c, src/ln.c, src/mv.c (main):
Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
b50b63e06c chmod: pacify -fsanitizer=leak
* src/chmod.c (main): Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
8fe6dd3b77 yes: pacify -fsanitizer=leak
* src/yes.c (main): Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
a7de740baa tsort: pacify -fsanitizer=leak
* src/tsort.c (detect_loop): Free removed successor.
2022-01-31 12:07:39 -08:00
Paul Eggert
a08853948c sort: pacify -fsanitizer=leak
* src/sort.c (pipe_fork, keycompare, sort, main):
Remove lint code that no longer seems to be needed.
(sort): Unconditionally compile ifdef lint code that is needed
to free storage even when not linting.
(main): Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
06b45ef985 split: pacify -fsanitizer=leak
* src/split.c (lines_rr): New arg FILESP.  All uses changed.
(main): Use main_exit, not return.  Omit unnecessary alignfree.
2022-01-31 12:07:39 -08:00
Paul Eggert
75b50689f1 ptx: pacify -fsanitizer=leak
* src/ptx.c (unescape_string): Rename from copy_unescaped_string,
and unescape the string in place.  Callers changed.  This way,
we needn’t allocate storage and thus needn’t worry about
-fsanitizer=leak.
2022-01-31 12:07:39 -08:00
Paul Eggert
b29f782a3f seq: pacify -fsanitizer=leak
* src/seq.c (seq_fast): If successful, exit rather than returning true.
Callers changed.
(main): Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
05e889b7d5 tsort: pacify -fsanitizer=leak
* src/tsort.c (struct item.balance): Now signed char to save space.
(struct item.printed): New member.
(new_item): Initialize k->printed to false.  Simplify via xzalloc.
(scan_zeros): Use k->printed rather than nulling out string.
(tsort): Move exiting code here ...
(main): ... from here.
(tsort) [lint]: Omit no-longer-needed code.  Instead, set head->printed.
2022-01-31 12:07:39 -08:00
Paul Eggert
1a83573596 tr: pacify -fsanitizer=leak
* src/tr.c (main): Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
7a9bda0477 stat: pacify -fsanitizer=leak
* src/stat.c (main):  Use main_exit, not return.
2022-01-31 12:07:39 -08:00
Paul Eggert
9b2a58ba64 comm: pacify -fsanitizer=leak
* src/comm.c (compare_files): Move exiting code here ...
(main): ... from here, to pacify gcc -fsanitize=leak.
2022-01-31 12:07:38 -08:00
Paul Eggert
afa93e8804 expr: lint cleanup, and introducing main_exit
This introduces a new macro main_exit, which is useful
for pacifying gcc -fsanitizer=lint and in some cases
means we can remove some ‘IF_LINT’ and ‘ifdef lint’ code.
* src/expr.c (main): Use main_exit, not return.
(docolon): Omit an IF_LINT that GCC no longer needs.
* src/system.h (main_exit): New macro.
2022-01-31 12:07:38 -08:00
Pádraig Brady
a42a039132 cksum: use more exact selection of digest algorithms
Use more constrained argument matching
to improve forward compatibility and robustness.

For example it's better that `cksum -a sha3` is _not_
equivalent to `cksum -a sha386`, so that a user
specifying `-a sha3` on an older cksum would not be surprised.

Also argmatch() is used when parsing tags from lines like:
SHA3 (filename) = abcedf....
so it's more robust that older cksum instances to fail
earlier in the parsing process, when parsing output from
possible future cksum implementations that might support SHA3.

* src/digest.c (algorithm_from_tag): Use argmatch_exact()
to ensure we don't match abbreviated algorithms.
(main): Likewise.
* tests/misc/cksum-a.sh: Add a test case.
2022-01-30 23:13:52 +00:00
Pádraig Brady
703e0487e4 build: update gnulib submodule to latest
To provide argmatch_exact() that does not
use abbreviated matching, to be used by cksum.
2022-01-30 20:34:29 +00:00
Paul Eggert
57c812cc3e mv: when installing to dir use dir-relative names
When the destination for mv is a directory, use functions like openat
to access the destination files, when such functions are available.
This should be more efficient and should avoid some race conditions.
Likewise for 'install'.
* src/cp.c (must_be_working_directory, target_directory_operand)
(target_dirfd_valid): Move from here ...
* src/system.h: ... to here, so that install and mv can use them.
Make them inline so GCC doesn’t complain.
* src/install.c (lchown) [HAVE_LCHOWN]: Remove; no longer needed.
(need_copy, copy_file, change_attributes, change_timestamps)
(install_file_in_file, install_file_in_dir):
New args for directory-relative names.  All uses changed.
Continue to pass full names as needed, for diagnostics and for
lower-level functions that do not support directory-relative names.
(install_file_in_dir): Update *TARGET_DIRFD as needed.
(main): Handle target-directory in the new, cp-like way.
* src/mv.c (remove_trailing_slashes): Remove static var; now local.
(do_move): New args for directory-relative names.  All uses changed.
Continue to pass full names as needed, for diagnostics and for
lower-level functions that do not support directory-relative names.
(movefile): Remove; no longer needed.
(main): Handle target-directory in the new, cp-like way.
* tests/install/basic-1.sh:
* tests/mv/diag.sh: Adjust to match new diagnostic wording.
2022-01-29 16:29:18 -08:00
Paul Eggert
534cfbb448 cp: fix comment typo 2022-01-29 16:29:18 -08:00
Pádraig Brady
795a16627c doc: NEWS: explain _why_ copy_file_range() is used
* NEWS: Mention why we're making the change in behavior in cat(1).
2022-01-28 15:13:25 +00:00
Pádraig Brady
2fb945ef77 build: update gnulib submodule to latest
To fix a syntax-check false failure
2022-01-28 15:07:14 +00:00
Paul Eggert
50e438972b dd: synchronize output after write errors
Problem reported by Sworddragon (Bug#51345).
* src/dd.c (cleanup): Synchronize output unless dd has been interrupted.
(synchronize_output): New function, split out from dd_copy.
Update conversions_mask so synchronization is done at most once.
(main): Do not die with the output file open, since we want to be
able to synchronize it before exiting.  Synchronize output before
exiting.
2022-01-28 00:01:55 -08:00
Paul Eggert
c4f9554ee9 dd: output final progress before syncing
Problem reported by Sworddragon (Bug#51482).
* src/dd.c (reported_w_bytes): New var.
(print_xfer_stats): Set it.
(dd_copy): Print a final progress report if useful before
synchronizing output data.
2022-01-27 18:35:02 -08:00
Paul Eggert
816d84f138 cat: prefer copy_file_range to read+write
* src/cat.c (copy_cat): New function.
(main): Use it.
2022-01-27 13:04:14 -08:00
Paul Eggert
3b98e21eed csplit: improve integer overflow checking
* src/csplit.c: Prefer signed integers to unsigned for sizes
when either will do.  Check for some unlikely overflows.
(INCR_SIZE): Remove; no longer used.
(free_buffer): Also free the arg, simplifying callers.
(get_new_buffer): Use xpalloc instead of computing new
size by hand.  Add ATTRIBUTE_DEALLOC.
(delete_all_files, close_output_file):
If unlink fails with ENOENT, treat it as success.
(close_output_file): If unlink fails, decrement count anyway.
(parse_repeat_count, parse_patterns): Check for int overflow.
(check_format_conv_type): Use signed format.
2022-01-27 13:04:14 -08:00
Paul Eggert
b973d2d44a maint: simplify memory alignment
Use the new Gnulib modules alignalloc and xalignalloc
to simplify some memory allocation.
Also, fix some unlikely integer overflow problems.
* bootstrap.conf (gnulib_modules): Add alignalloc, xalignalloc.
* src/cat.c, src/copy.c, src/dd.c, src/shred.c, src/split.c:
Include alignalloc.h.
* src/cat.c (main):
* src/copy.c (copy_reg):
* src/dd.c (alloc_ibuf, alloc_obuf):
* src/shred.c (dopass):
* src/split.c (main):
Use alignalloc/xalignalloc/alignfree instead of doing page
alignment by hand.
* src/cat.c (main):
Check for integer overflow in page size calculations.
* src/dd.c (INPUT_BLOCK_SLOP, OUTPUT_BLOCK_SLOP, MAX_BLOCKSIZE):
(real_ibuf, real_obuf) [lint]:
Remove; no longer needed.
(cleanup) [lint]:
(scanargs): Simplify.
* src/ioblksize.h (io_blksize): Do not allow blocksizes largest
than the largest power of two that fits in idx_t and size_t.
* src/shred.c (PAGE_ALIGN_SLOP, PATTERNBUF_SIZE): Remove.
2022-01-27 13:04:14 -08:00
Paul Eggert
1a8a566963 build: update gnulib submodule to latest 2022-01-27 13:04:14 -08:00
Paul Eggert
fbc7958b36 copy: remove unnecessary ‘free’
* src/copy.c (copy_reg): Remove a ‘free’ call that does nothing
because its argument is always a null pointer, starting with
2007-11-1608:31:15Z!jim@meyering.net.
2022-01-27 13:04:14 -08:00
Paul Eggert
f19bc026b3 dd: simplify conv=swab code
Simplify byte-swapping, so that the code no longer needs to
allocate a page before the input buffer.
* src/dd.c (SWAB_ALIGN_OFFSET, char_is_saved, saved_char): Remove.
All uses removed.
(INPUT_BLOCK_SLOP): Simplify to just page_size.
(alloc_ibuf, dd_copy): Adjust to new swab_buffer API.
(swab_buffer): New arg SAVED_BYTE, taking the place of the old
global variables.  Do not access BUF[-1].
2022-01-27 13:04:14 -08:00
Paul Eggert
e94d95075d dd: improve integer overflow checking
* src/dd.c: Prefer signed to unsigned types where either will do,
as this helps improve checking with gcc -fsanitize=undefined.
Limit the signed types to their intended ranges.
(MAX_BLOCKSIZE): Don’t exceed IDX_MAX - slop either.
(input_offset_overflow): Remove; overflow now denoted by negative.
(parse_integer): Return INTMAX_MAX on overflow, instead of unspecified.
Do not falsely report overflow for ‘00x99999999999999999999999999999’.
* tests/dd/misc.sh: New test for 00xBIG.
* tests/dd/skip-seek-past-file.sh: Adjust to new diagnostic wording.
New test for BIGxBIG.
2022-01-27 13:04:14 -08:00
Paul Eggert
e462d928b0 shred: fix declaration typo
* gl/lib/randint.h (randint_all_new):
Do not declare with _GL_ATTRIBUTE_NONNULL (), as
the arg can be a null pointer.  This fixes a typo added in
2021-11-01T05:30:28Z!eggert@cs.ucla.edu.
2022-01-27 13:04:14 -08:00
Paul Eggert
4ec55ec0bd cat: prefer signed to unsigned
* src/cat.c: Prefer signed to unsigned types
where either will do, as they allow for better
overflow checking at runtime.
2022-01-27 13:04:14 -08:00
Paul Eggert
a36bc1910f cat: improve style
* cat.c: Improve style a bit, mostly by assuming C99-style
declarations after statements
2022-01-27 13:04:14 -08:00
Pádraig Brady
4a0a8fdbec doc: csplit: clarify [OFFSET] syntax
* src/csplit.c (usage): Clarify that '+' prefix is optional on OFFSET.
* doc/coreutils.texi (csplit invocation): Likewise.
Fixes https://bugs.gnu.org/53574
2022-01-27 13:07:28 +00:00
Paul Eggert
2ba6fb653c build: allow readlinkat calls
Problem reported by Bernhard Voelker in:
https://lists.gnu.org/r/coreutils/2022-01/msg00026.html
* cfg.mk (sc_prohibit_readlink): Remove.  It’s OK to call
readlinkat to determine whether a file is a symbolic link.
2022-01-15 12:12:49 -08:00
Paul Eggert
b197885b2d cp: rely on Gnulib for copy_file_range workaround
Gnulib now replaces copy_file_range on buggy hosts
so there is no need for Coreutils to worry about the bug.
* src/copy.c: Do not include sys/utsname.h, xstrtol.h.
(functional_copy_file_range): Remove.  All uses now
simply call copy_file_range.
2022-01-14 17:44:49 -08:00
Paul Eggert
db539b7c34 build: update gnulib submodule to latest 2022-01-14 17:44:49 -08:00
Paul Eggert
6df8e86208 doc: fix pluralization typo 2022-01-14 15:47:41 -08:00
Paul Eggert
f39a02a744 cp: fix two typos in previous change
Somehow ‘make check’ didn’t catch these the first few times.
* src/copy.c (copy_dir): Don’t pass null pointer to
copy_internal where it now expects non-null if move mode.
* src/cp.c (make_dir_parents_private): Initialize *attr_list
before recentely-added quick return.
2022-01-14 15:17:54 -08:00
Paul Eggert
95d6754451 cp: omit unnecessary stat of destination
'cp A B' attempts to open B as a directory, to see whether to
write to B/A instead of to B.  In the common case where the
open fails with ENOENT, do not bother to stat B afterwards
since the stat should also fail with ENOENT.
* src/copy.c (copy_internal, copy): Change bool arg about
nonexistent destination to a 3-way int argument.  All callers changed.
(copy_internal): Do not bother to stat a destination already known
to not exist when following symlinks.
2022-01-14 14:09:25 -08:00
Paul Eggert
43fa191b5a build: update gnulib submodule to latest 2022-01-13 12:02:16 -08:00
Paul Eggert
e2daa8f797 cp: when copying to dir use dir-relative names
When copying to a directory, use functions like openat to access
the destination files, when such functions are available.  This
should be more efficient and should avoid some race conditions.
* bootstrap.conf (gnulib_modules): Add areadlinkat-with-size,
fchmodat, fchownat, mkdirat, mkfifoat, utimensat.
* src/copy.c (lchown) [!HAVE_LCHOWN]:
* src/copy.c, src/system.h (rpl_mkfifo, mkfifo) [!HAVE_MKFIFO]:
Remove.  All uses removed.
(utimens_symlink): Remove; we shouldn’t have to worry about
those obsolete systems any more.  All uses replaced by utimensat.
* src/copy.c (copy_dir, set_owner, fchmod_or_lchmod, copy_reg)
(same_file_ok, writable_destination, overwrite_ok, abandon_move)
(create_hard_link, src_is_dst_backup, copy_internal, copy):
* src/cp.c (make_dir_parents_private, re_protect):
New args for directory-relative names.  All uses changed.
Continue to pass full names as needed, for diagnostics and for
lower-level functions like qset_acl that do not support
directory-relative names.
* src/copy.c (copy_reg): Prefer readlinkat to lstatat for merely
checking whether a file is a symlink, to avoid EOVERFLOW issues.
(subst_suffix): New function.
(create_hard_link): Accept a null SRC_NAME as meaning that if it
is needed it needs to be constructed from SRC_RELNAME, DST_NAME,
and DST_RELNAME.
(source_is_dst_backup): Use subst_suffix instead of doing it by hand.
(copy_internal): Remember and use directory-relative names instead
of full names.
* src/cp.c (lchown) [!HAVE_LCHOWN]: Remove.  All uses removed.
(must_be_working_directory): New function.
(target_directory_operand): Simply take file name as arg,
and return a file descriptor or negative number on failure;
open with O_DIRECTORY to obtain any file descriptor.
All uses changed.
(target_dirfd_valid): New function.
(do_copy): Use these new functions to obtain a file descriptor
for any target directory, and use directory-relative names
for that directory.
(main): Omit no-longer-needed stat when --target-directory,
as do_copy now does this.
* src/ln.c (O_PATHSEARCH): Move from here ...
* src/system.h: ... to here.
* tests/cp/fail-perm.sh: Adjust to change in diagnostic wording,
and add a test for --no-target-directory.
2022-01-13 11:36:51 -08:00
Paul Eggert
3f488e1d52 cp: tweak internal name
* src/cp.c (do_copy): Omit confusingly-named local new_dest, since
there’s another var new_dst that means something quite different.
2022-01-13 11:36:51 -08:00
Daniel Knittl-Frank
95ec19ecbd scripts: fix typo in commit-msg git-hook script
Commit 2f438fa9f5 (basenc: A new program
complementary to base64/base32) introduced a typo in the list of allowed
commit message prefixes, accidentally changing "basename" to
"nbasename".  Revert it back to the correct "basename".
2022-01-12 22:59:30 +00:00
Paul Eggert
73bd6306d1 df: tiny simplification
* src/df.c (LOG_EQ): Remove.  All callers replaced by ==.
2022-01-07 14:56:55 -08:00
Pádraig Brady
3067a9293a maint: update all copyright year number ranges
Run "make update-copyright" and then...

* gnulib: Update to latest with copyright year adjusted.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
* tests/sample-test: Adjust to use the single most recent year.
2022-01-02 16:15:55 +00:00
Pádraig Brady
76700e775e build: update gnulib submodule to latest
mainly to get updated copyright year

* doc/fdl.texi: Sync from gnulib.
* .gitignore: Add lib/unictype, as bitmap.h therein is depended on
since gnulib commit f698ea71
2022-01-02 16:14:40 +00:00
Paul Eggert
840ae54cf5 date: new option --resolution
* NEWS, doc/coreutils.texi (Options for date): Mention this.
* src/date.c (RESOLUTION_OPTION): New constant.
(DEBUG_DATE_PARSING_OPTION): Rename from DEBUG_DATE_PARSING.
All uses changed.
(long_options, usage, main): Support --resolution.
2021-12-31 10:53:29 -08:00
Paul Eggert
0cd39a246a date: %-N now means suppress extra digits
* NEWS, doc/coreutils.texi: Mention this.
* bootstrap.conf (gnulib_modules): Add gettime-res.
* src/date.c (res_width, adjust_resolution): New functions.
(main): Adjust %-N to be %9N, or whatever, before using it.
2021-12-31 10:53:29 -08:00
Paul Eggert
64b65cf4b8 build: update gnulib submodule to latest 2021-12-31 10:53:29 -08:00
Paul Eggert
1011b88594 doc: Document , vs . in date --rfc-3339=ns 2021-12-31 10:53:29 -08:00
Paul Eggert
6812e6baa7 build: port to AIX 7.1
This fixes a porting bug introduced in
2019-08-12T03:29:00Z!bruno@clisp.org.
Problem discovered on AIX 7.1.
* src/local.mk (LDADD): Add $(LIB_MBRTOWC), since pretty much
every command uses quotearg or mbrtowc or whatever.
(src_sort_LDADD): Add $(LIBPMULTITHREAD) and
$(LIB_PTHREAD_SIGMASK) instead of $(LIBTHREAD).
2021-12-31 10:53:29 -08:00
Paul Eggert
aa670bed50 build: be more careful about Perl
Problem reported by Serge Belyshev (Bug#52844).
* configure.ac (HAVE_PERL): Rely on latest Gnulib gl_PERL, which
sets gl_cv_prog_perl.
2021-12-28 02:03:42 -08:00
Paul Eggert
2f60fa465e build: update gnulib submodule to latest 2021-12-28 02:03:42 -08:00
Max Filippov
5bc9d92868 all: fix adjustment of /proc/$pid/cmdline by single binary
When configured with --enable-single-binary tools issue incorrect prctl:

  prctl(PR_SET_KEEPCAPS, ...)      = -1 EINVAL (Invalid argument)

PR_SET_MM_ARG_START is not a prctl 'option' parameter, it's 'arg2'
parameter for the option PR_SET_MM.  It also has to have 'arg4' and
'arg5' set to 0 explicitly, otherwise the kernel also returns -EINVAL.

* src/coreutils.c (launch_program): Fix prctl arguments.
* NEWS: Mention the improvement.
Fixes https://bugs.gnu.org/52800
2021-12-27 12:09:39 +00:00
Paul Eggert
5475fd6fe0 ls: improve doc for =WHEN
* src/ls.c (usage): Improve clarity of =WHEN args (Bug#52782).
2021-12-24 15:26:16 -08:00
Paul Eggert
d5ae6d8120 doc: colorize -> color
Living so close to Hollywood I know that "colorize"
means adding color to something that was already monochrome,
whereas "color" means to give color to something.
Coreutils apps color text instead of colorizing it.
2021-12-24 09:49:21 -08:00
Bernhard Voelker
1435e8e5c5 maint: update tests/init.sh from gnulib
* tests/init.sh: Sync from gnulib/tests/init.sh.
A recent gnulib update (4f497bf3c) missed this.
2021-12-20 23:13:36 +01:00
Jim Meyering
eb2400fb9f maint: syntax-check requires "char const *", not "const char *"
* gl/lib/mbsalign.c (mbs_align_pad): Adjust.
* src/chroot.c (is_root): Adjust.
* src/digest.c (main): Adjust.
* src/relpath.c (buffer_or_output) Adjust.
* src/ls.c (print_name_with_quoting, get_color_indicator): Adjust.
2021-12-20 12:50:08 -08:00
Jim Meyering
1cfbd4548d maint: split a long line
* src/test.c (three_arguments): Split long line.
2021-12-20 12:50:08 -08:00
Jim Meyering
a2b21e9105 maint: commit-msg: compute UTF-8-aware line-length
* scripts/git-hooks/commit-msg: Count UTF-8 characters rather
than bytes to avoid erroneously rejecting as "longer than 72" a
log message line like the UTF-8 one for id.c just prior.  It has
77 bytes but only 67 characters.
(check_msg): Read in "utf8" mode. Also include actual length
in the diagnostic.
(main): Don't loop when stdout is redirected, as it is when
invoked via vc-dwim.
Paul Eggert reported privately both the error of counting bytes
rather than chars and the re_edit loop when failing via vc-dwim.
2021-12-20 10:46:11 -08:00
Paul Eggert
915a5e3360 id: improve doc for when USER is omitted
* src/id.c (usage): “current user” → “current process” (Bug#52656).
2021-12-19 09:17:08 -08:00
Paul Eggert
8621e44cda maint: use GNU style for spacing 2021-12-18 09:35:04 -08:00
Bruno Haible
3bf118dad0 build: non-recursive Automake in a less hacky way
* bootstrap.conf (gnulib_modules): Remove
non-recursive-gnulib-prefix-hack.
(gnulib_tool_option_extras): Add --automake-subdir.
(bootstrap_post_import_hook): No need to massage lib/gnulib.mk.
2021-12-16 09:33:12 -08:00
Paul Eggert
064b31eb48 build: update bootstrap to latest 2021-12-16 09:33:12 -08:00
Paul Eggert
1827ae8243 build: update gnulib submodule to latest 2021-12-16 09:33:12 -08:00
Jim Meyering
bbc5e84513 maint: factor.c: avoid new GCC 12 warning
* src/factor.c (millerrabin2): Mark as ATTRIBUTE_PURE,
per advice from GCC 12.
2021-12-14 19:52:50 -08:00
Paul Eggert
bfc7a9b5e0 build: update gnulib submodule to latest
* NEWS: Mention the bugfix.
2021-12-14 12:47:36 -08:00
Paul Eggert
8931d571d0 mv: Bug#52410 fix
The recent Gnulib update fixed this bug reported by Vincent Vermilya.
* tests/mv/backup-dir.sh: Test for Bug#52410.
2021-12-10 14:10:51 -08:00
Paul Eggert
4f497bf3c7 build: update gnulib submodule to latest 2021-12-10 14:10:50 -08:00
Paul Eggert
e3d1ff0437 uname: port to recent macOS
Problem reported by Jakub Sokołowski (bug #52330).
* src/uname.c [__APPLE__]: Don’t include sys/syctl.h,
mach/machine.h, mach-o/arch.h.
(print_element_env): New function.  With __APPLE__, it defers to the
env var UNAME_MACHINE (if given) for uname -m, and similarly for -nrsv.
(main): Use it.  For -p with __APPLE__, rely on predefined macros
and omit any 64-bit indication, for compatibility with macOS uname.
2021-12-07 14:00:42 -08:00
Paul Eggert
5e36c0ce07 cp: clone on macOS
* configure.ac: Check for fclonefileat.
* src/copy.c [HAVE_FCLONEFILEAT && !USE_XATTR]:
Include <sys/clonefile.h>.
(copy_reg): If possible, use fclonefileat to clone.
2021-11-21 19:13:03 -08:00
Paul Eggert
41bec08d7a cp: streamline cloning by skipping fstat
* src/copy.c (copy_reg): Attempt clone_file before fstat of dest,
so that if clone_file succeeds we can skip the fstat.
2021-11-21 12:32:46 -08:00
Paul Eggert
5012223d78 cp: fix --preserve=ownership permissions bug
This fixes a bug that I introduced in
2006-12-06T19:44:08Z!eggert@cs.ucla.edu.
* src/copy.c (USE_XATTR): New macro.
(copy_reg): Use it to help the compiler.  Prefer open u+w to a
later chmod u=rw; u+r isn’t needed for xattr.  For the later u-r,
do only one (or zero) chmod calls instead of two (or one).
In the last chmod, respect the umask instead of ignoring it.
* tests/cp/preserve-mode.sh: Test for the bug.
2021-11-20 13:50:35 -08:00
Paul Eggert
3e2d644483 maint: prefer MAYBE_UNUSED
Prefer MAYBE_UNUSED to _GL_UNUSED, since the C2x syntax
will be [[maybe_unused]] at the start of the declaration,
and we want to look forward to that.  All uses of _GL_UNUSED
either changed to MAYBE_UNUSED, or (when not needed) removed.
2021-11-18 21:37:38 -08:00
Paul Eggert
d0f035fc64 cp: fix security context race
This fixes an issue introduced in the fix for Bug#11100.
* NEWS: Mention this.
* src/copy.c (copy_reg): Fix obscure bug where open-without-CREAT
failed with ENOENT and we forget to call set_process_security_ctx
before calling open-with-CREAT. Also, don’t bother to unlink
DST_NAME if open failed with ENOENT; and if unlink fails with
ENOENT, don’t consider that to be an error (someone else could
have removed the file for us, and that’s OK).  Also, don’t worry
about move mode, since we use O_EXCL|O_CREAT and so won’t open
an existing file.
2021-11-18 08:31:59 -08:00
Paul Eggert
0f84467a34 maint: update NEWS for macOS fix 2021-11-16 17:06:36 -08:00
Paul Eggert
0060ef82ee cp: minor clarity tweak
* src/copy.c (copy_reg): Use cached data_copy_required.
2021-11-16 16:51:44 -08:00
Paul Eggert
08930f21cb cp: fix ptrdiff_t/ssize_t theoretical glitches
* src/copy.c (sparse_copy): Use system.h’s SSIZE_MAX.
Don’t assume SSIZE_MAX <= PTRDIFF_MAX.
2021-11-16 16:11:27 -08:00
Paul Eggert
eae8df0d94 build: update gnulib submodule to latest 2021-11-15 22:36:57 -08:00
Paul Eggert
1b988ffa95 maint: fix nonnull decl
* gl/lib/randread.h (randread_new): Do not mark with
_GL_ATTRIBUTE_RETURNS_NONNULL, since it can return NULL.
2021-11-15 22:22:24 -08:00
Paul Eggert
0f4d9e849b build: update gnulib submodule to latest 2021-11-15 15:26:19 -08:00
Pádraig Brady
2378a53143 tests: avoid false failure in env-signal-handler.sh
* tests/misc/env-signal-handler.sh: Use retry_delay_ to
avoid a false failure under load, where env hasn't setup
the SIGINT handling before timeout(1) sends the SIGINT.
Fixes https://bugs.gnu.org/51793
2021-11-13 14:38:08 +00:00
Pádraig Brady
a0468760ff maint: fix recent syntax-check failures
* cfg.mk (exclude_file_name_regexp--sc_system_h_headers):
Add chown-core.h to the regexp, to better decouple from system.h.
* src/env.c: Remove minmax.h include already included in system.h.
* src/libstdbuf.c: Likewise.
* src/prog-fprintf.h: Remove doubled semicolon.
2021-11-01 13:45:15 +00:00
Paul Eggert
ea02406748 maint: use minmax.h instead of rolling our own
* gl/lib/mbsalign.c, gl/lib/randread.c, src/system.h (MAX, MIN):
Remove; include minmax.h instead.
* gl/modules/mbsalign, gl/modules/randread (Depends-on): Add minmax.
* src/factor.c (MIN): Remove.
2021-10-31 22:36:46 -07:00
Paul Eggert
9f8a38414b maint: add function attributes to .h files
Add _GL_ATTRIBUTE_NONNULL, _GL_ATTRIBUTE_MALLOC,
_GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DALLOC_FREE,
_GL_ATTRIBUTE_RETURNS_NONNULL to .h files when appropriate.
* gl/lib/mbsalign.h, gl/lib/randperm.h, src/chown-core.h:
Include stdlib.h, for the benefit of _GL_ATTRIBUTE_DALLOC_FREE.
* gl/lib/randread.c (randread_free_body): New static function.
(randread_new, randread_free): Use it.
* src/copy.c (valid_options): Remove assert that is no longer
needed because it is now checked statically.
2021-10-31 22:36:46 -07:00
Paul Eggert
25e68323b9 maint: enable -Wsuggest-attribute=format
* configure.ac (WERROR_CFLAGS): Enable -Wsuggest-attribute=format
for lib/ and src/.
* src/copy.c (copy_attr_error, copy_attr_allerror):
Add ATTRIBUTE_FORMAT.
(copy_attr): Ignore -Wsuggest-attribute=format in the
small section of code that needs it ignored.
* src/test.c (test_syntax_error): Mark with ATTRIBUTE_FORMAT.
(binary_operator): Omit unnecessary NULL args, pacifying
-Wsuggest-attribute=format.
2021-10-31 22:36:46 -07:00
Paul Eggert
d16821975e maint: modernize attribute usage
* src/system.h (__attribute__): Remove.  Replace all uses that
rely on this by _GL_ATTRIBUTE_xxx or ATTRIBUTE_xxx.
(ATTRIBUTE_WARN_UNUSED_RESULT): Remove.  Replace all uses by
NODISCARD.
2021-10-31 22:36:46 -07:00
Paul Eggert
9287ce5bbc maint: remove unused __attribute__ defn
* gl/lib/randread.c (__attribute__): Remove; no longer
used after the recent _Noreturn change.
2021-10-31 22:36:46 -07:00
Paul Eggert
2a9bacee50 b2sum: simplify attribute usage
* src/blake2/blake2.h (BLAKE2_PACKED): Simplify, and port better
to older GCC, by using _GL_ATTRIBUTE_PACKED.
2021-10-31 22:36:46 -07:00
Paul Eggert
389e766367 maint: prefer attribute.h in .c files
This will help us make the transition to C2x, where some
attributes must come at the start of function decls.
Leave the attributes alone in .h files for now,
as the Gnulib tradition is to not expose attribute.h to users.
* bootstrap.conf (gnulib_modules): Add ‘attribute’.
* gl/lib/randperm.c, src/make-prime-list.c, src/system.h:
Include attribute.h.
* gl/lib/strnumcmp.c (strnumcmp): Remove _GL_ATTRIBUTE_PURE here,
as this belongs in the .h file.
* gl/lib/strnumcmp.h (strnumcmp): Add _GL_ATTRIBUTE_PURE here.
* src/sort.c (human_numcompare, numcompare): Now ATTRIBUTE_PURE;
discovered due to strnumcmp.h change.
* gl/lib/randperm.c, src/copy.c, src/dd.c, src/df.c, src/digest.c:
* src/env.c, src/expr.c, src/factor.c, src/ls.c:
* src/make-prime-list.c, src/numfmt.c, src/od.c, src/pathchk.c:
* src/pinky.c, src/pr.c, src/ptx.c, src/realpath.c, src/relpath.c:
* src/seq.c, src/sort.c, src/stat.c, src/stty.c, src/system.h:
* src/tr.c, src/uniq.c, src/wc.c:
In .c files, crefer ATTRIBUTE_CONST to _GL_ATTRIBUTE_CONST, and
similarly for ATTRIBUTE_FORMAT and ATTRIBUTE_PURE.
* src/system.h (FALLTHROUGH): Remove; attribute.h defines it.
2021-10-31 22:36:46 -07:00
Pádraig Brady
bafff0019c sort: --debug: add warnings about sign, radix, and grouping chars
New warnings are added related to the handling
of thousands grouping characters, decimal points, and sign characters.
Examples now diagnosed are:

$ printf '0,9\n1,a\n' | sort -nk1 --debug -t, -s
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘,’ is treated as a group separator in numbers
1,a
_
0,9
___

$ printf '1,a\n0,9\n' | LC_ALL=fr_FR.utf8 sort -gk1 --debug -t, -s
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘,’ is treated as a decimal point in numbers
0,9
___
1,a
__

$ printf '1.0\n0.9\n' | LC_ALL=fr_FR.utf8 sort -s -k1,1g --debug
sort: note numbers use ‘,’ as a decimal point in this locale
0.9
_
1.0
_

$ LC_ALL=fr_FR.utf8 sort -n --debug /dev/null
sort: text ordering performed using ‘fr_FR.utf8’ sorting rules
sort: note numbers use ‘,’ as a decimal point in this locale
sort: the multi-byte number group separator in this locale \
      is not supported

$ sort --debug -t- -k1n /dev/null
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘-’ is treated as a minus sign in numbers
sort: note numbers use ‘.’ as a decimal point in this locale

$ sort --debug -t+ -k1g /dev/null
sort: key 1 is numeric and spans multiple fields
sort: field separator ‘+’ is treated as a plus sign in numbers
sort: note numbers use ‘.’ as a decimal point in this locale

* src/sort.c (key_warnings): Add the warnings above.
* tests/misc/sort-debug-warn.sh: Add test cases.
Also check that all sort invocations succeed.
* NEWS: Mention the improvement.
Addresses https://bugs.gnu.org/51011
2021-10-31 23:19:05 +00:00
Paul Eggert
aa31b919ca maint: modernize README-{hacking,prereq} 2021-10-30 16:28:25 -07:00
Paul Eggert
1753012b8d cp: revert unnecessary FreeBSD workaround
That was a false alarm due to a bug in FreeBSD 9.1 truss;
see Pádraig Brady’s report (Bug#51433#29).
* src/copy.c (lseek_copy, infer_scantype): Don’t bother checking
whether lseek returned -1.  This doesn’t entirely revert the
previous change, as it keeps the code simplification of the
previous change while reverting the check for -1.
2021-10-30 10:04:54 -07:00
Paul Eggert
a9e31457bf cp: defend better against FreeBSD 9.1 zfs bug
Problem reported by Pádraig Brady (Bug#51433#14).
* src/copy.c (lseek_copy, infer_scantype): Report an error if
lseek with SEEK_DATA or SEEK_HOLE returns less than -1,
as this is an lseek bug.
2021-10-29 18:23:54 -07:00
Pádraig Brady
f60a3981c3 doc: say that printf(1) is preferred over echo(1)
* src/echo.c (usage): Say printf(1) is preferred
due to being more standard and robust.
* man/echo.x [SEE ALSO]: Reference printf(1).
* doc/coreutils.texi (echo invocation): Mention in the
summary that echo is not robust when outputting
any string, and that printf is preferred.
Also expand on the examples showing how to
output a single '-n' string.
Addresses https://bugs.gnu.org/51311
2021-10-22 15:12:33 +01:00
Pádraig Brady
13af84d09a doc: timeout --kill-after: clarify disabled timeouts
* doc/coreutils.texi (timeout invocation): Clarify
that -k is ignored if either its duration or the
main timeout duration is 0.
Addresses https://bugs.gnu.org/51128
2021-10-12 14:47:44 +01:00
Pádraig Brady
0750fcdf34 timeout: ensure --foreground -k exits with status 137
* src/timeout.c (main): Propagate the killed status from the child.
* doc/coreutils.texi (timeout invocation): Remove the
description of the --foreground specific handling of SIGKILL,
now that it's consistent with the default mode of operation.
* tests/misc/timeout.sh: Add a test case.
* NEWS: Mention the change in behavior.
Fixes https://bugs.gnu.org/51135
2021-10-12 14:32:57 +01:00
Pádraig Brady
d085678bd6 doc: timeout --foreground: add clarification on exit status
* doc/coreutils.texi (timeout invocation): Add detail on
how --foreground allows timeout(1) to use more standard
exit status as the uncatchable SIGKILL is not sent to itself.
Fixes https://bugs.gnu.org/51135
2021-10-11 22:15:52 +01:00
Paul Eggert
6cafb122fa sort: fix unlikely bug when '\377' < 0
* gl/lib/strintcmp.c (strintcmp): Don’t assume that the input
cannot contain ((char) -1), as this equals '\377' when char is
signed (assuming 8-bit char).
* src/sort.c (decimal_point): Now char, to make it clear
that it’s always in char range now.
(NON_CHAR): New constant.
(traverse_raw_number): Return char not unsigned char;
this is simpler and could be faster.  All callers changed.
(main): Do not convert decimal_point and thousands_sep to
unsigned char, as this can mishandle comparisons on
machines where char is signed and the input data contains
((char) -1).  Use NON_CHAR, not -1, as an out-of-range value for
thousands_sep.
2021-10-10 16:06:28 -07:00
Paul Eggert
5b43b8e9ce build: update gnulib submodule to latest 2021-10-02 18:55:01 -07:00
Paul Eggert
b31a6a09ad maint: switch to C11-style _Noreturn
Use C11-style _Noreturn instead of the old ATTRIBUTE_NORETURN
macro.  This pacifies clang on OpenBSD 6.9, which otherwise
complains "'noreturn' function does return" in some places.
* gl/lib/randread.c, src/system.h (ATTRIBUTE_NORETURN):
Remove.  All uses either removed as GCC no longer needs them, or
changed to C11-style _Noreturn since Gnulib arranges for _Noreturn
globally nowadays.
2021-10-02 18:44:21 -07:00
Paul Eggert
4cfd48481d ls: port to OpenBSD
Problem reported by Brian Callahan (Bug#50972).
* src/ls.c (decode_switches): Don’t assume __GNUC_PREREQ.
2021-10-02 18:08:33 -07:00
Pádraig Brady
0475ce9f84 doc: adjust ls --zero option order in texinfo
* doc/coreutils.texi (ls invocation - general output formatting):
The option ordering was not changed when the option was renamed
from --null to --zero.
2021-09-26 13:48:03 +01:00
Pádraig Brady
61c81ffaac tests: cp/sparse-perf: make more robust and add zfs comments
* init.cfg (seek_data_capable_): Add a timeout to ensure failure for
slow lseek(...SEEK_DATA) calls (even if that syscall isn't interrupted).
* tests/cp/sparse-perf.sh: Run the SEEK_DATA check on the
1TiB empty file to exclude both FreeBSD 9.1 which takes 35s,
and ZFS which requires a delay of about 5s between file creation
and use of SEEK_DATA to correctly determine it's empty (return ENXIO).
Also remove the stat size checks as they invalidate the test
due to cp never writing data due to it being always zeros,
and thus converted to holes in the output.
2021-09-25 22:40:01 +01:00
Pádraig Brady
e8b56ebd53 chmod: fix exit status when ignoring symlinks
* src/chmod.c: Reorder enum so CH_NOT_APPLIED
can be treated as a non error.
* tests/chmod/ignore-symlink.sh: A new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/50784
2021-09-24 23:42:20 +01:00
Pádraig Brady
6f38c4b279 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-09-24 13:58:11 +01:00
842 changed files with 4846 additions and 3877 deletions

View File

@@ -68,7 +68,7 @@ When sending messages to coreutils@gnu.org or bug-coreutils@gnu.org :
<!--
Copyright (C) 2017-2021 Free Software Foundation, Inc.
Copyright (C) 2017-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -88,7 +88,7 @@ in this matter.
<!--
Copyright (C) 2017-2021 Free Software Foundation, Inc.
Copyright (C) 2017-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

1
.gitignore vendored
View File

@@ -106,6 +106,7 @@
/lib/sys/
/lib/termios.h
/lib/time.h
/lib/unictype
/lib/unistd.h
/lib/unistr
/lib/unistr.h

View File

@@ -1 +1 @@
8.32
9.0

View File

@@ -1,6 +1,6 @@
# Suppress valgrind diagnostics we don't care about.
# Copyright (C) 2003-2021 Free Software Foundation, Inc.
# Copyright (C) 2003-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -617,7 +617,7 @@ and root only tests, is to follow these steps (requires lcov to be installed):
xdg-open doc/coverage/index.html
========================================================================
Copyright (C) 2009-2021 Free Software Foundation, Inc.
Copyright (C) 2009-2022 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or

View File

@@ -1,6 +1,6 @@
# Make coreutils. -*-Makefile-*-
# Copyright (C) 1990-2021 Free Software Foundation, Inc.
# Copyright (C) 1990-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -93,7 +93,7 @@ dist-hook: gen-ChangeLog
$(AM_V_at)touch $(distdir)/doc/constants.texi \
$(distdir)/doc/coreutils.info
gen_start_ver = 8.25
gen_start_ver = 8.27
.PHONY: gen-ChangeLog
gen-ChangeLog:
$(AM_V_GEN)if test -d .git; then \

133
NEWS
View File

@@ -1,5 +1,134 @@
GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release 9.1 (2022-04-15) [stable]
** Bug fixes
chmod -R no longer exits with error status when encountering symlinks.
All files would be processed correctly, but the exit status was incorrect.
[bug introduced in coreutils-9.0]
If 'cp -Z A B' checks B's status and some other process then removes B,
cp no longer creates B with a too-generous SELinux security context
before adjusting it to the correct value.
[bug introduced in coreutils-8.17]
'cp --preserve=ownership A B' no longer ignores the umask when creating B.
Also, 'cp --preserve-xattr A B' is less likely to temporarily chmod u+w B.
[bug introduced in coreutils-6.7]
On macOS, 'cp A B' no longer miscopies when A is in an APFS file system
and B is in some other file system.
[bug introduced in coreutils-9.0]
On macOS, fmt no longer corrupts multi-byte characters
by misdetecting their component bytes as spaces.
[This bug was present in "the beginning".]
'id xyz' now uses the name 'xyz' to determine groups, instead of xyz's uid.
[bug introduced in coreutils-8.22]
'ls -v' and 'sort -V' no longer mishandle corner cases like "a..a" vs "a.+"
or lines containing NULs. Their behavior now matches the documentation
for file names like ".m4" that consist entirely of an extension,
and the documentation has been clarified for unusual cases.
[bug introduced in coreutils-7.0]
On macOS, 'mv A B' no longer fails with "Operation not supported"
when A and B are in the same tmpfs file system.
[bug introduced in coreutils-9.0]
'mv -T --backup=numbered A B/' no longer miscalculates the backup number
for B when A is a directory, possibly inflooping.
[bug introduced in coreutils-6.3]
** Changes in behavior
cat now uses the copy_file_range syscall if available, when doing
simple copies between regular files. This may be more efficient, by avoiding
user space copies, and possibly employing copy offloading or reflinking.
chown and chroot now warn about usages like "chown root.root f",
which have the nonstandard and long-obsolete "." separator that
causes problems on platforms where user names contain ".".
Applications should use ":" instead of ".".
cksum no longer allows abbreviated algorithm names,
so that forward compatibility and robustness is improved.
date +'%-N' now suppresses excess trailing digits, instead of always
padding them with zeros to 9 digits. It uses clock_getres and
clock_gettime to infer the clock resolution.
dd conv=fsync now synchronizes output even after a write error,
and similarly for dd conv=fdatasync.
dd now counts bytes instead of blocks if a block count ends in "B".
For example, 'dd count=100KiB' now copies 100 KiB of data, not
102,400 blocks of data. The flags count_bytes, skip_bytes and
seek_bytes are therefore obsolescent and are no longer documented,
though they still work.
ls no longer colors files with capabilities by default, as file-based
capabilties are very rarely used, and lookup increases processing per file by
about 30%. It's best to use getcap [-r] to identify files with capabilities.
ls no longer tries to automount files, reverting to the behavior
before the statx() call was introduced in coreutils-8.32.
stat no longer tries to automount files by default, reverting to the
behavior before the statx() call was introduced in coreutils-8.32.
Only `stat --cached=never` will continue to automount files.
timeout --foreground --kill-after=... will now exit with status 137
if the kill signal was sent, which is consistent with the behavior
when the --foreground option is not specified. This allows users to
distinguish if the command was more forcefully terminated.
** New Features
dd now supports the aliases iseek=N for skip=N, and oseek=N for seek=N,
like FreeBSD and other operating systems.
dircolors takes a new --print-ls-colors option to display LS_COLORS
entries, on separate lines, colored according to the entry color code.
dircolors will now also match COLORTERM in addition to TERM environment
variables. The default config will apply colors with any COLORTERM set.
** Improvements
cp, mv, and install now use openat-like syscalls when copying to a directory.
This avoids some race conditions and should be more efficient.
On macOS, cp creates a copy-on-write clone if source and destination
are regular files on the same APFS file system, the destination does
not already exist, and cp is preserving mode and timestamps (e.g.,
'cp -p', 'cp -a').
The new 'date' option --resolution outputs the timestamp resolution.
With conv=fdatasync or conv=fsync, dd status=progress now reports
any extra final progress just before synchronizing output data,
since synchronizing can take a long time.
printf now supports printing the numeric value of multi-byte characters.
sort --debug now diagnoses issues with --field-separator characters
that conflict with characters possibly used in numbers.
'tail -f file | filter' now exits on Solaris when filter exits.
root invoked coreutils, that are built and run in single binary mode,
now adjust /proc/$pid/cmdline to be more specific to the utility
being run, rather than using the general "coreutils" binary name.
** Build-related
AIX builds no longer fail because some library functions are not found.
[bug introduced in coreutils-8.32]
* Noteworthy changes in release 9.0 (2021-09-24) [stable]
** Bug fixes
@@ -3016,7 +3145,7 @@ GNU coreutils NEWS -*- outline -*-
install accepts a new option --strip-program to specify the program used to
strip binaries.
ls now colorizes files with capabilities if libcap is available
ls now colors names of files with capabilities if libcap is available.
ls -v now uses filevercmp function as sort predicate (instead of strverscmp)
@@ -5289,7 +5418,7 @@ packages, see ./old/*/NEWS.
========================================================================
Copyright (C) 2001-2021 Free Software Foundation, Inc.
Copyright (C) 2001-2022 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or

2
README
View File

@@ -232,7 +232,7 @@ the address on the last line of --help output.
========================================================================
Copyright (C) 1998-2021 Free Software Foundation, Inc.
Copyright (C) 1998-2022 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or

View File

@@ -1,34 +1,45 @@
-*- outline -*-
Building from a Git repository -*- outline -*-
These notes intend to help people working on the checked-out sources.
These requirements do not apply when building from a distribution tarball.
See also HACKING for more detailed contribution guidelines.
If this package has a file HACKING, please also read that file for
more detailed contribution guidelines.
* Requirements
We've opted to keep only the highest-level sources in the GIT repository.
This eases our maintenance burden, (fewer merges etc.), but imposes more
We've opted to keep only the highest-level sources in the Git repository.
This eases our maintenance burden (fewer merges etc.), but imposes more
requirements on anyone wishing to build from the just-checked-out sources.
Note the requirements to build the released archive are much less and
are just the requirements of the standard ./configure && make procedure.
(The requirements to build from a release are much less and are just
the requirements of the standard './configure && make' procedure.)
Specific development tools and versions will be checked for and listed by
the bootstrap script. See README-prereq for specific notes on obtaining
these prerequisite tools.
Valgrind <http://valgrind.org/> is also highly recommended, if
Valgrind supports your architecture. See also README-valgrind.
Valgrind supports your architecture. See also README-valgrind
(if present).
While building from a just-cloned source tree may require installing a
few prerequisites, later, a plain 'git pull && make' should be sufficient.
few prerequisites, later, a plain 'git pull && make' typically suffices.
* First GIT checkout
* First Git checkout
You can get a copy of the source repository like this:
$ git clone git://git.sv.gnu.org/coreutils
$ cd coreutils
$ git clone git://git.sv.gnu.org/<packagename>
$ cd <packagename>
As an optional step, if you already have a copy of the gnulib git
where '<packagename>' stands for 'coreutils' or whatever other package
you are building.
To use the most-recent Gnulib (as opposed to the Gnulib version that
the package last synchronized to), do this next:
$ git submodule foreach git pull origin master
$ git commit -m 'build: update gnulib submodule to latest' gnulib
As an optional step, if you already have a copy of the Gnulib Git
repository, then you can use it as a reference to reduce download
time and file system space requirements:
@@ -39,20 +50,14 @@ which are extracted from other source packages:
$ ./bootstrap
To use the most-recent gnulib (as opposed to the gnulib version that
the package last synchronized to), do this next:
$ git submodule foreach git pull origin master
$ git commit -m 'build: update gnulib submodule to latest' gnulib
And there you are! Just
$ ./configure --quiet #[--enable-gcc-warnings] [*]
$ ./configure --quiet #[--disable-gcc-warnings] [*]
$ make
$ make check
At this point, there should be no difference between your local copy,
and the GIT master copy:
and the Git master copy:
$ git diff
@@ -60,12 +65,15 @@ should output no difference.
Enjoy!
[*] The --enable-gcc-warnings option is useful only with glibc
and with a very recent version of gcc. You'll probably also have
to use recent system headers. If you configure with this option,
and spot a problem, please be sure to send the report to the bug
reporting address of this package, and not to that of gnulib, even
if the problem seems to originate in a gnulib-provided file.
[*] By default GCC warnings are enabled when building from Git.
If you get warnings with recent GCC and Glibc with default
configure-time options, please report the warnings to the bug
reporting address of this package instead of to bug-gnulib,
even if the problem seems to originate in a Gnulib-provided file.
If you get warnings with other configurations, you can run
'./configure --disable-gcc-warnings' or 'make WERROR_CFLAGS='
to build quietly or verbosely, respectively.
-----
* Submitting patches
@@ -93,7 +101,7 @@ each program. One way to do this is to use vc-dwim
-----
Copyright (C) 2002-2021 Free Software Foundation, Inc.
Copyright (C) 2002-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,65 +1,41 @@
This gives some notes on obtaining the tools required for development.
I.e., the tools checked for by the bootstrap script and include:
These tools can be used by the 'bootstrap' and 'configure' scripts,
as well as by 'make'. They include:
- Autoconf <https://www.gnu.org/software/autoconf/>
- Automake <https://www.gnu.org/software/automake/>
- Bison <https://www.gnu.org/software/bison/>
- Gettext <https://www.gnu.org/software/gettext/>
- Git <https://git-scm.com/>
- Gperf <https://www.gnu.org/software/gperf/>
- Gzip <https://www.gnu.org/software/gzip/>
- Perl <https://www.cpan.org/>
- Rsync <https://rsync.samba.org/>
- Tar <https://www.gnu.org/software/tar/>
- Texinfo <https://www.gnu.org/software/texinfo/>
- Autoconf <https://www.gnu.org/software/autoconf/>
- Automake <https://www.gnu.org/software/automake/>
- Bison <https://www.gnu.org/software/bison/>
- Gettext <https://www.gnu.org/software/gettext/>
- Git <https://git-scm.com/>
- Gperf <https://www.gnu.org/software/gperf/>
- Gzip <https://www.gnu.org/software/gzip/>
- Help2man <https://www.gnu.org/software/help2man/>
- M4 <https://www.gnu.org/software/m4/>
- Make <https://www.gnu.org/software/make/>
- Perl <https://www.cpan.org/>
- Tar <https://www.gnu.org/software/tar/>
- Texinfo <https://www.gnu.org/software/texinfo/>
- Wget <http://www.gnu.org/software/wget/>
- XZ Utils <https://tukaani.org/xz/>
Note please try to install/build official packages for your system.
If these programs are not available use the following instructions
to build them and install the results into a directory that you will
then use when building this package.
It is generally better to use official packages for your system.
If a package is not officially available you can build it from source
and install it into a directory that you can then use to build this
package. If some packages are available but are too old, install the
too-old versions first as they may be needed to build newer versions.
Even if the official version of a package for your system is too old,
please install it, as it may be required to build the newer versions.
The examples below install into $HOME/coreutils/deps/, so if you are
going to follow these instructions, first ensure that your $PATH is
set correctly by running this command:
Here is an example of how to build a program from source. This
example is for Autoconf; a similar approach should work for the other
developer prerequisites. This example assumes Autoconf 2.71; it
should be OK to use a later version of Autoconf, if available.
prefix=$HOME/coreutils/deps
prefix=$HOME/prefix # (or wherever else you choose)
export PATH=$prefix/bin:$PATH
* autoconf *
# Note Autoconf 2.62 or newer is needed to build automake-1.11.2
# but we specify 2.64 here as that's what coreutils requires.
# Please use the latest stable release version as indicated by git tags.
git clone --depth=1 git://git.sv.gnu.org/autoconf.git
cd autoconf
git pull --tags
git checkout v2.64
autoreconf -vi
wget https://ftp.gnu.org/pub/gnu/autoconf/autoconf-2.71.tar.gz
gzip -d <autoconf-2.71.tar.gz | tar xf -
cd autoconf-2.71
./configure --prefix=$prefix
make install
* automake *
# Note help2man is required to build automake fully
git clone git://git.sv.gnu.org/automake.git
cd automake
git checkout v1.11.2
./bootstrap
./configure --prefix=$prefix
make install
This package uses XZ utils (successor to LZMA) to create
a compressed distribution tarball. Using this feature of Automake
requires version 1.10a or newer, as well as the xz program itself.
* xz *
git clone https://git.tukaani.org/xz.git
cd xz
./autogen.sh
./configure --prefix=$prefix
make install
Now you can build this package as described in README-hacking.
Once the prerequisites are installed, you can build this package as
described in README-hacking.

View File

@@ -1,7 +1,7 @@
#! /bin/bash
# Convert this package for use with valgrind.
# Copyright (C) 2002-2021 Free Software Foundation, Inc.
# Copyright (C) 2002-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -641,7 +641,6 @@ Ulrich Hermisson ulrich_hermisson@hotmail.com
Urs Thuermann urs@isnogud.escape.de
Uwe H. Steinfeld usteinfeld@gmx.net
Vesselin Atanasov vesselin@bgnet.bg
Ville Skyttä ville.skytta@iki.fi
Vin Shelton acs@alumni.princeton.edu
Vineet Chadha chadha@acis.ufl.edu
Vitali Lovich vlovich@gmail.com

2
TODO
View File

@@ -143,7 +143,7 @@ pr's use of nstrftime can make it malloc a very large (up to SIZE_MAX) buffer
-----
Copyright (C) 2002-2021 Free Software Foundation, Inc.
Copyright (C) 2002-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

247
bootstrap
View File

@@ -1,10 +1,10 @@
#! /bin/sh
# Print a version string.
scriptversion=2021-04-11.09; # UTC
scriptversion=2022-03-21.01; # UTC
# Bootstrap this package from checked-out sources.
# Copyright (C) 2003-2021 Free Software Foundation, Inc.
# Copyright (C) 2003-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -313,6 +313,116 @@ find_tool ()
eval "export $find_tool_envvar"
}
# Strip blank and comment lines to leave significant entries.
gitignore_entries() {
sed '/^#/d; /^$/d' "$@"
}
# If $STR is not already on a line by itself in $FILE, insert it at the start.
# Entries are inserted at the start of the ignore list to ensure existing
# entries starting with ! are not overridden. Such entries support
# whitelisting exceptions after a more generic blacklist pattern.
insert_if_absent() {
file=$1
str=$2
test -f $file || touch $file
test -r $file || die "Error: failed to read ignore file: $file"
duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
if [ "$duplicate_entries" ] ; then
die "Error: Duplicate entries in $file: " $duplicate_entries
fi
linesold=$(gitignore_entries $file | wc -l)
linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
if [ $linesold != $linesnew ] ; then
{ echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
|| die "insert_if_absent $file $str: failed"
fi
}
# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
# insert_if_absent.
insert_vc_ignore() {
vc_ignore_file="$1"
pattern="$2"
case $vc_ignore_file in
*.gitignore)
# A .gitignore entry that does not start with '/' applies
# recursively to subdirectories, so prepend '/' to every
# .gitignore entry.
pattern=$(echo "$pattern" | sed s,^,/,);;
esac
insert_if_absent "$vc_ignore_file" "$pattern"
}
symlink_to_dir()
{
src=$1/$2
dst=${3-$2}
test -f "$src" && {
# If the destination directory doesn't exist, create it.
# This is required at least for "lib/uniwidth/cjk.h".
dst_dir=$(dirname "$dst")
if ! test -d "$dst_dir"; then
mkdir -p "$dst_dir"
# If we've just created a directory like lib/uniwidth,
# tell version control system(s) it's ignorable.
# FIXME: for now, this does only one level
parent=$(dirname "$dst_dir")
for dot_ig in x $vc_ignore; do
test $dot_ig = x && continue
ig=$parent/$dot_ig
insert_vc_ignore $ig "${dst_dir##*/}"
done
fi
if $copy; then
{
test ! -h "$dst" || {
echo "$me: rm -f $dst" &&
rm -f "$dst"
}
} &&
test -f "$dst" &&
cmp -s "$src" "$dst" || {
echo "$me: cp -fp $src $dst" &&
cp -fp "$src" "$dst"
}
else
# Leave any existing symlink alone, if it already points to the source,
# so that broken build tools that care about symlink times
# aren't confused into doing unnecessary builds. Conversely, if the
# existing symlink's timestamp is older than the source, make it afresh,
# so that broken tools aren't confused into skipping needed builds. See
# <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
test -h "$dst" &&
src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
test "$src_i" = "$dst_i" &&
both_ls=$(ls -dt "$src" "$dst") &&
test "X$both_ls" = "X$dst$nl$src" || {
dot_dots=
case $src in
/*) ;;
*)
case /$dst/ in
*//* | */../* | */./* | /*/*/*/*/*/)
die "invalid symlink calculation: $src -> $dst";;
/*/*/*/*/) dot_dots=../../../;;
/*/*/*/) dot_dots=../../;;
/*/*/) dot_dots=../;;
esac;;
esac
echo "$me: ln -fs $dot_dots$src $dst" &&
ln -fs "$dot_dots$src" "$dst"
}
fi
}
}
# Override the default configuration, if necessary.
# Make sure that bootstrap.conf is sourced from the current directory
# if we were invoked as "sh bootstrap".
@@ -375,47 +485,6 @@ if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
die "Bootstrapping from a non-checked-out distribution is risky."
fi
# Strip blank and comment lines to leave significant entries.
gitignore_entries() {
sed '/^#/d; /^$/d' "$@"
}
# If $STR is not already on a line by itself in $FILE, insert it at the start.
# Entries are inserted at the start of the ignore list to ensure existing
# entries starting with ! are not overridden. Such entries support
# whitelisting exceptions after a more generic blacklist pattern.
insert_if_absent() {
file=$1
str=$2
test -f $file || touch $file
test -r $file || die "Error: failed to read ignore file: $file"
duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
if [ "$duplicate_entries" ] ; then
die "Error: Duplicate entries in $file: " $duplicate_entries
fi
linesold=$(gitignore_entries $file | wc -l)
linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
if [ $linesold != $linesnew ] ; then
{ echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
|| die "insert_if_absent $file $str: failed"
fi
}
# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
# insert_if_absent.
insert_vc_ignore() {
vc_ignore_file="$1"
pattern="$2"
case $vc_ignore_file in
*.gitignore)
# A .gitignore entry that does not start with '/' applies
# recursively to subdirectories, so prepend '/' to every
# .gitignore entry.
pattern=$(echo "$pattern" | sed s,^,/,);;
esac
insert_if_absent "$vc_ignore_file" "$pattern"
}
# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
found_aux_dir=no
grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
@@ -694,9 +763,26 @@ if $use_gnulib; then
shallow=
if test -z "$GNULIB_REVISION"; then
git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
|| cleanup_gnulib
else
git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
mkdir -p "$gnulib_path"
# Only want a shallow checkout of $GNULIB_REVISION, but git does not
# support cloning by commit hash. So attempt a shallow fetch by commit
# hash to minimize the amount of data downloaded and changes needed to
# be processed, which can drastically reduce download and processing
# time for checkout. If the fetch by commit fails, a shallow fetch can
# not be performed because we do not know what the depth of the commit
# is without fetching all commits. So fallback to fetching all commits.
git -C "$gnulib_path" init
git -C "$gnulib_path" remote add origin \
${GNULIB_URL:-$default_gnulib_url}
git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
|| git -C "$gnulib_path" fetch origin \
|| cleanup_gnulib
git -C "$gnulib_path" reset --hard FETCH_HEAD
fi
git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
|| cleanup_gnulib
trap - 1 2 13 15
fi
@@ -813,75 +899,6 @@ case $SKIP_PO in
fi;;
esac
symlink_to_dir()
{
src=$1/$2
dst=${3-$2}
test -f "$src" && {
# If the destination directory doesn't exist, create it.
# This is required at least for "lib/uniwidth/cjk.h".
dst_dir=$(dirname "$dst")
if ! test -d "$dst_dir"; then
mkdir -p "$dst_dir"
# If we've just created a directory like lib/uniwidth,
# tell version control system(s) it's ignorable.
# FIXME: for now, this does only one level
parent=$(dirname "$dst_dir")
for dot_ig in x $vc_ignore; do
test $dot_ig = x && continue
ig=$parent/$dot_ig
insert_vc_ignore $ig "${dst_dir##*/}"
done
fi
if $copy; then
{
test ! -h "$dst" || {
echo "$me: rm -f $dst" &&
rm -f "$dst"
}
} &&
test -f "$dst" &&
cmp -s "$src" "$dst" || {
echo "$me: cp -fp $src $dst" &&
cp -fp "$src" "$dst"
}
else
# Leave any existing symlink alone, if it already points to the source,
# so that broken build tools that care about symlink times
# aren't confused into doing unnecessary builds. Conversely, if the
# existing symlink's timestamp is older than the source, make it afresh,
# so that broken tools aren't confused into skipping needed builds. See
# <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
test -h "$dst" &&
src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
test "$src_i" = "$dst_i" &&
both_ls=$(ls -dt "$src" "$dst") &&
test "X$both_ls" = "X$dst$nl$src" || {
dot_dots=
case $src in
/*) ;;
*)
case /$dst/ in
*//* | */../* | */./* | /*/*/*/*/*/)
die "invalid symlink calculation: $src -> $dst";;
/*/*/*/*/) dot_dots=../../../;;
/*/*/*/) dot_dots=../../;;
/*/*/) dot_dots=../;;
esac;;
esac
echo "$me: ln -fs $dot_dots$src $dst" &&
ln -fs "$dot_dots$src" "$dst"
}
fi
}
}
version_controlled_file() {
parent=$1
file=$2
@@ -1093,7 +1110,7 @@ bootstrap_epilogue
echo "$0: done. Now you can run './configure'."
# Local variables:
# Local Variables:
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"

View File

@@ -1,6 +1,6 @@
# Bootstrap configuration.
# Copyright (C) 2006-2021 Free Software Foundation, Inc.
# Copyright (C) 2006-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -26,13 +26,16 @@ avoided_gnulib_modules='
gnulib_modules="
$avoided_gnulib_modules
acl
alignalloc
alignof
alloca
announce-gen
areadlink-with-size
areadlinkat-with-size
argmatch
argv-iter
assert
attribute
autobuild
backupfile
backup-rename
@@ -79,6 +82,8 @@ gnulib_modules="
faccessat
fadvise
fchdir
fchmodat
fchownat
fclose
fcntl
fcntl-safer
@@ -118,6 +123,7 @@ gnulib_modules="
getpass-gnu
gettext-h
gettime
gettime-res
getugroups
getusershell
git-version-gen
@@ -172,7 +178,9 @@ gnulib_modules="
mkancesdirs
mkdir
mkdir-p
mkdirat
mkfifo
mkfifoat
mknod
mkostemp
mkstemp
@@ -181,7 +189,6 @@ gnulib_modules="
mountlist
mpsort
netinet_in
non-recursive-gnulib-prefix-hack
nproc
nstrftime
obstack
@@ -240,7 +247,6 @@ gnulib_modules="
stat-macros
stat-size
stat-time
statat
stdbool
stdlib-safer
stpcpy
@@ -256,6 +262,7 @@ gnulib_modules="
sys_resource
sys_stat
sys_wait
targetdir
tempname
termios
time_rz
@@ -276,6 +283,7 @@ gnulib_modules="
userspec
utimecmp
utimens
utimensat
vasprintf-posix
vc-list-files
verify
@@ -287,6 +295,7 @@ gnulib_modules="
winsz-ioctl
winsz-termios
write-any-file
xalignalloc
xalloc
xbinary-io
xdectoint
@@ -338,7 +347,7 @@ XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\
'
gnulib_tool_option_extras="--tests-base=gnulib-tests --with-tests --symlink\
--makefile-name=gnulib.mk
--makefile-name=gnulib.mk --automake-subdir
"
# Build prerequisites
@@ -372,9 +381,6 @@ bootstrap_post_import_hook ()
&& chmod a-w $tmp-1 $tmp-2 \
&& mv -f $tmp-1 $m4f && mv -f $tmp-2 $mkf)
# Massage lib/gnulib.mk before using it later in the bootstrapping process.
build-aux/prefix-gnulib-mk --lib-name=$gnulib_name lib/$gnulib_mk
# Regenerate src/single-binary.mk
(mkf=src/single-binary.mk tmp=single-binary.tmp \
&& rm -f $mkf $tmp \

16
cfg.mk
View File

@@ -1,5 +1,5 @@
# Customize maint.mk -*- makefile -*-
# Copyright (C) 2003-2021 Free Software Foundation, Inc.
# Copyright (C) 2003-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -49,7 +49,7 @@ export VERBOSE = yes
# 4914152 9e
export XZ_OPT = -8e
old_NEWS_hash = ad874c61dc38785cb432159b725fc3de
old_NEWS_hash = 612bad626bf28b1847ad0114cb2cd6fe
# Add an exemption for sc_makefile_at_at_check.
_makefile_at_at_check_exceptions = ' && !/^cu_install_prog/ && !/dynamic-dep/'
@@ -192,7 +192,7 @@ sc_prohibit_quotes_notation:
# Files in src/ should quote all strings in error() output, so that
# unexpected input chars like \r etc. don't corrupt the error.
# In edge cases this can be avoided by putting the format string
# on a separate line to the following arguments.
# on a separate line to the arguments, or the arguments in parenthesis.
sc_error_quotes:
@cd $(srcdir)/src && GIT_PAGER= git grep -n 'error *(.*%s.*, [^(]*);$$'\
*.c | grep -v ', q' \
@@ -236,7 +236,7 @@ sc_error_shell_always_quotes:
# to the compiler that it doesn't return.
sc_die_EXIT_FAILURE:
@cd $(srcdir)/src && GIT_PAGER= git grep -E \
'error \(.*_(FAILURE|INVALID)' \
'error \([^?]*EXIT_' \
&& { echo '$(ME): '"Use die() instead of error" 1>&2; \
exit 1; } \
|| :
@@ -441,12 +441,6 @@ sc_prohibit_operator_at_end_of_line:
halt='found operator at end of line' \
$(_sc_search_regexp)
# Don't use "readlink" or "readlinkat" directly
sc_prohibit_readlink:
@prohibit='\<readlink(at)? \(' \
halt='do not use readlink(at); use via xreadlink or areadlink*' \
$(_sc_search_regexp)
# Don't use address of "stat" or "lstat" functions
sc_prohibit_stat_macro_address:
@prohibit='\<l?stat '':|&l?stat\>' \
@@ -839,7 +833,7 @@ exclude_file_name_regexp--sc_bindtextdomain = \
exclude_file_name_regexp--sc_trailing_blank = \
^(tests/pr/|gl/.*\.diff$$|man/help2man)
exclude_file_name_regexp--sc_system_h_headers = \
^src/((die|system|copy|find-mount-point)\.h|make-prime-list\.c)$$
^src/((die|system|copy|chown-core|find-mount-point)\.h|make-prime-list\.c)$$
_src = (crctab|false|lbracket|ls-(dir|ls|vdir)|tac-pipe|uname-(arch|uname))
_gl_src = (xdecto.max|cl-strtold)

View File

@@ -1,7 +1,7 @@
# -*- autoconf -*-
# Process this file with autoconf to produce a configure script.
# Copyright (C) 1991-2021 Free Software Foundation, Inc.
# Copyright (C) 1991-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -64,11 +64,7 @@ gl_INIT
coreutils_MACROS
# The test suite needs to know if we have a working perl.
# FIXME: this is suboptimal. Ideally, we would be able to call gl_PERL
# with an ACTION-IF-NOT-FOUND argument ...
cu_have_perl=yes
case $PERL in *"/missing "*) cu_have_perl=no;; esac
AM_CONDITIONAL([HAVE_PERL], [test $cu_have_perl = yes])
AM_CONDITIONAL([HAVE_PERL], [test "$gl_cv_prog_perl" != no])
# gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
# ------------------------------------------------
@@ -88,6 +84,50 @@ AC_DEFUN([gl_GCC_VERSION_IFELSE],
]
)
AC_ARG_ENABLE([single-binary],
[AS_HELP_STRING([--enable-single-binary=[shebangs|symlinks]],
[Compile all the tools in a single binary, reducing the overall size.
When compiled this way, shebangs (default when enabled) or symlinks are
installed for each tool that points to the single binary.])],
[gl_single_binary=no ;
case $enableval in
yes) gl_single_binary=shebangs ;;
no|shebangs|symlinks) gl_single_binary=$enableval ;;
*) AC_MSG_ERROR([bad value $enableval for single-binary option.
Options are: symlinks, shebangs, no.]) ;;
esac],
[gl_single_binary=no]
)
AC_ARG_ENABLE([single-binary-exceptions],
[AS_HELP_STRING([--enable-single-binary-exceptions=PROG_LIST],
[When used with --enable-single-binary, exclude the PROG_LIST from
it, so these programs are compiled as separated files
(comma-separated, default none))])],
[gl_single_binary_exceptions=$enableval],
[gl_single_binary_exceptions=]
)
if test "$gl_single_binary" = 'symlinks'; then
if ! test "`echo ls | sed \"$program_transform_name\"`" = 'ls'; then
AC_MSG_ERROR([program name transformations are not currently supported
with --enable-single-binary=symlinks.])
fi
fi
AM_CONDITIONAL([SINGLE_BINARY], [test "$gl_single_binary" != no])
AC_ARG_ENABLE([bold-man-page-references],
[AS_HELP_STRING([--disable-bold-man-page-references],
[When generating man pages, do not apply bold style around any
references like name(1) etc.])],
[gl_bold_manpages=yes ;
case $enableval in
no|yes) gl_bold_manpages=$enableval ;;
*) AC_MSG_ERROR([bad value $enableval for bold-man-page-references.
Options are: yes, no.]) ;;
esac],
[gl_bold_manpages=yes]
)
AM_CONDITIONAL([BOLD_MAN_REFS], [test "$gl_bold_manpages" != no])
AC_ARG_ENABLE([gcc-warnings],
[AS_HELP_STRING([--enable-gcc-warnings@<:@=TYPE@:>@],
[control generation of GCC warnings. The TYPE 'no' disables
@@ -150,9 +190,14 @@ if test $gl_gcc_warnings != no; then
nw="$nw -Wmissing-format-attribute" # copy.c
nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
nw="$nw -Winline" # system.h's readdir_ignoring_dot_and_dotdot
nw="$nw -Wsuggest-attribute=format" # warns about copy.c and factor.c
nw="$nw -Wvector-operation-performance" # warns about randperm.c
# Suppress noreturn warnings with single binaries; otherwise
# GCC complains about the renamed 'main' not being declared noreturn
# because 'main_exit' calls 'exit' when linting.
if test "$gl_single_binary" != no; then
nw="$nw -Wsuggest-attribute=noreturn"
fi
# Using -Wstrict-overflow is a pain, but the alternative is worse.
# For an example, see the code that provoked this report:
@@ -224,42 +269,13 @@ if test $gl_gcc_warnings != no; then
nw="$nw -Wstrict-prototypes"
# It's not worth being this picky about test programs.
nw="$nw -Wsuggest-attribute=const"
nw="$nw -Wsuggest-attribute=format"
nw="$nw -Wsuggest-attribute=pure"
gl_MANYWARN_COMPLEMENT([GNULIB_TEST_WARN_CFLAGS],
[$GNULIB_WARN_CFLAGS], [$nw])
AC_SUBST([GNULIB_TEST_WARN_CFLAGS])
fi
AC_ARG_ENABLE([single-binary],
[AS_HELP_STRING([--enable-single-binary=[shebangs|symlinks]],
[Compile all the tools in a single binary, reducing the overall size.
When compiled this way, shebangs (default when enabled) or symlinks are
installed for each tool that points to the single binary.])],
[gl_single_binary=no ;
case $enableval in
yes) gl_single_binary=shebangs ;;
no|shebangs|symlinks) gl_single_binary=$enableval ;;
*) AC_MSG_ERROR([bad value $enableval for single-binary option.
Options are: symlinks, shebangs, no.]) ;;
esac],
[gl_single_binary=no]
)
AC_ARG_ENABLE([single-binary-exceptions],
[AS_HELP_STRING([--enable-single-binary-exceptions=PROG_LIST],
[When used with --enable-single-binary, exclude the PROG_LIST from
it, so these programs are compiled as separated files
(comma-separated, default none))])],
[gl_single_binary_exceptions=$enableval],
[gl_single_binary_exceptions=]
)
if test "$gl_single_binary" = 'symlinks'; then
if ! test "`echo ls | sed \"$program_transform_name\"`" = 'ls'; then
AC_MSG_ERROR([program name transformations are not currently supported
with --enable-single-binary=symlinks.])
fi
fi
AM_CONDITIONAL([SINGLE_BINARY], [test "$gl_single_binary" != no])
AC_FUNC_FORK
optional_bin_progs=
@@ -320,6 +336,9 @@ if test $utils_cv_localtime_cache = yes; then
AC_DEFINE([LOCALTIME_CACHE], [1], [FIXME])
fi
# macOS >= 10.12
AC_CHECK_FUNCS([fclonefileat])
# Assume that if getattrat exists, it's compatible with Solaris 11.
AC_CHECK_FUNCS([getattrat])
if test $ac_cv_func_getattrat = yes; then

View File

@@ -145,7 +145,7 @@
This manual documents version @value{VERSION} of the GNU core
utilities, including the standard programs for text and file manipulation.
Copyright @copyright{} 1994--2021 Free Software Foundation, Inc.
Copyright @copyright{} 1994--2022 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
@@ -300,7 +300,7 @@ Operating on characters
@command{tr}: Translate, squeeze, and/or delete characters
* Character sets:: Specifying sets of characters
* Character arrays:: Specifying arrays of characters
* Translating:: Changing one set of characters to another
* Squeezing and deleting:: Removing characters
@@ -498,9 +498,9 @@ Date input formats
Version sorting order
* Version sort overview::
* Implementation Details::
* Differences from the official Debian Algorithm::
* Advanced Topics::
* Version sort implementation::
* Differences from Debian version sort::
* Advanced version sort topics::
Opening the software toolbox
@@ -3554,7 +3554,8 @@ file once for each repeat.
@item /@var{regexp}/[@var{offset}]
Create an output file containing the current line up to (but not
including) the next line of the input file that contains a match for
@var{regexp}. The optional @var{offset} is an integer.
@var{regexp}. The optional @var{offset} is an integer, that can
be preceded by @samp{+} or @samp{-}.
If it is given, the input up to (but not including) the
matching line plus or minus @var{offset} is put into the output file,
and the line after that begins the next section of input.
@@ -3990,7 +3991,7 @@ Output extra information to stderr, like the checksum implementation being used.
@item --untagged
@opindex --untagged
Output using the original coreutils format used by the other
Output using the original Coreutils format used by the other
standalone checksum utilities like @command{md5sum} for example.
This format has the checksum at the start of the line, and may be
more amenable to further processing by other utilities,
@@ -6887,7 +6888,7 @@ These commands operate on individual characters.
Synopsis:
@example
tr [@var{option}]@dots{} @var{set1} [@var{set2}]
tr [@var{option}]@dots{} @var{string1} [@var{string2}]
@end example
@command{tr} copies standard input to standard output, performing
@@ -6904,9 +6905,11 @@ delete characters,
delete characters, then squeeze repeated characters from the result.
@end itemize
The @var{set1} and (if given) @var{set2} arguments define ordered
sets of characters, referred to below as @var{set1} and @var{set2}. These
sets are the characters of the input that @command{tr} operates on.
The @var{string1} and @var{string2} operands define arrays of
characters @var{array1} and @var{array2}. By default @var{array1}
lists input characters that @command{tr} operates on, and @var{array2}
lists corresponding translations. In some cases the second operand is
omitted.
The program accepts the following options. Also see @ref{Common options}.
Options must precede operands.
@@ -6919,34 +6922,29 @@ Options must precede operands.
@opindex -c
@opindex -C
@opindex --complement
This option replaces @var{set1} with its
complement (all of the characters that are not in @var{set1}).
Currently @command{tr} fully supports only single-byte characters.
Eventually it will support multibyte characters; when it does, the
@option{-C} option will cause it to complement the set of characters,
whereas @option{-c} will cause it to complement the set of values.
This distinction will matter only when some values are not characters,
and this is possible only in locales using multibyte encodings when
the input contains encoding errors.
Instead of @var{array1}, use its complement (all characters not
specified by @var{string1}), in ascending order. Use this option with
caution in multibyte locales where its meaning is not always clear
or portable; see @ref{Character arrays}.
@item -d
@itemx --delete
@opindex -d
@opindex --delete
Delete characters in @var{set1}, do not translate
Delete characters in @var{array1}; do not translate.
@item -s
@itemx --squeeze-repeats
@opindex -s
@opindex --squeeze-repeats
Replace each sequence of a repeated character that is listed in
the last specified @var{set}, with a single occurrence of that character.
the last specified @var{array}, with a single occurrence of that character.
@item -t
@itemx --truncate-set1
@opindex -t
@opindex --truncate-set1
First truncate @var{set1} to length of @var{set2}.
Truncate @var{array1} to the length of @var{array2}.
@end table
@@ -6954,23 +6952,41 @@ First truncate @var{set1} to length of @var{set2}.
@exitstatus
@menu
* Character sets:: Specifying sets of characters.
* Translating:: Changing one set of characters to another.
* Character arrays:: Specifying arrays of characters.
* Translating:: Changing characters to other characters.
* Squeezing and deleting:: Removing characters.
@end menu
@node Character sets
@subsection Specifying sets of characters
@node Character arrays
@subsection Specifying arrays of characters
@cindex specifying sets of characters
@cindex arrays of characters in @command{tr}
The format of the @var{set1} and @var{set2} arguments resembles
the format of regular expressions; however, they are not regular
expressions, only lists of characters. Most characters simply
represent themselves in these strings, but the strings can contain
the shorthands listed below, for convenience. Some of them can be
used only in @var{set1} or @var{set2}, as noted below.
The @var{string1} and @var{string2} operands are not regular
expressions, even though they may look similar. Instead, they
merely represent arrays of characters. As a GNU extension to POSIX,
an empty string operand represents an empty array of characters.
The interpretation of @var{string1} and @var{string2} depends on locale.
GNU @command{tr} fully supports only safe single-byte locales,
where each possible input byte represents a single character.
Unfortunately, this means GNU @command{tr} will not handle commands
like @samp{tr $'\u7530' $'\u68EE'} the way you might expect,
since (assuming a UTF-8 encoding) this is equivalent to
@samp{tr '\347\224\260' '\346\243\256'} and GNU @command{tr} will
simply transliterate all @samp{\347} bytes to @samp{\346} bytes, etc.
POSIX does not clearly specify the behavior of @command{tr} in locales
where characters are represented by byte sequences instead of by
individual bytes, or where data might contain invalid bytes that are
encoding errors. To avoid problems in this area, you can run
@command{tr} in a safe single-byte locale by using a shell command
like @samp{LC_ALL=C tr} instead of plain @command{tr}.
Although most characters simply represent themselves in @var{string1}
and @var{string2}, the strings can contain shorthands listed below,
for convenience. Some shorthands can be used only in @var{string1} or
@var{string2}, as noted below.
@table @asis
@@ -6981,38 +6997,42 @@ The following backslash escape sequences are recognized:
@table @samp
@item \a
Control-G.
Bell (BEL, Control-G).
@item \b
Control-H.
Backspace (BS, Control-H).
@item \f
Control-L.
Form feed (FF, Control-L).
@item \n
Control-J.
Newline (LF, Control-J).
@item \r
Control-M.
Carriage return (CR, Control-M).
@item \t
Control-I.
Tab (HT, Control-I).
@item \v
Control-K.
Vertical tab (VT, Control-K).
@item \@var{ooo}
The 8-bit character with the value given by @var{ooo}, which is 1 to 3
octal digits. Note that @samp{\400} is interpreted as the two-byte
sequence, @samp{\040} @samp{0}.
The eight-bit byte with the value given by @var{ooo}, which is the longest
sequence of one to three octal digits following the backslash.
For portability, @var{ooo} should represent a value that fits in eight bits.
As a GNU extension to POSIX, if the value would not fit, then only the
first two digits of @var{ooo} are used, e.g., @samp{\400}
is equivalent to @samp{\0400} and represents a two-byte sequence.
@item \\
A backslash.
@end table
While a backslash followed by a character not listed above is
interpreted as that character, the backslash also effectively
removes any special significance, so it is useful to escape
@samp{[}, @samp{]}, @samp{*}, and @samp{-}.
It is an error if no character follows an unescaped backslash.
As a GNU extension, a backslash followed by a character not listed
above is interpreted as that character, removing any special
significance; this can be used to escape the characters
@samp{[} and @samp{-} when they would otherwise be special.
@item Ranges
@cindex ranges
The notation @samp{@var{m}-@var{n}} expands to all of the characters
The notation @samp{@var{m}-@var{n}} expands to the characters
from @var{m} through @var{n}, in ascending order. @var{m} should
collate before @var{n}; if it doesn't, an error results. As an example,
not collate after @var{n}; if it does, an error results. As an example,
@samp{0-9} is the same as @samp{0123456789}.
GNU @command{tr} does not support the System V syntax that uses square
@@ -7022,38 +7042,37 @@ to themselves. However, they should be avoided because they sometimes
behave unexpectedly. For example, @samp{tr -d '[0-9]'} deletes brackets
as well as digits.
Many historically common and even accepted uses of ranges are not
Many historically common and even accepted uses of ranges are not fully
portable. For example, on EBCDIC hosts using the @samp{A-Z}
range will not do what most would expect because @samp{A} through @samp{Z}
are not contiguous as they are in ASCII@.
If you can rely on a POSIX compliant version of @command{tr}, then
the best way to work around this is to use character classes (see below).
One way to work around this is to use character classes (see below).
Otherwise, it is most portable (and most ugly) to enumerate the members
of the ranges.
@item Repeated characters
@cindex repeated characters
The notation @samp{[@var{c}*@var{n}]} in @var{set2} expands to @var{n}
The notation @samp{[@var{c}*@var{n}]} in @var{string2} expands to @var{n}
copies of character @var{c}. Thus, @samp{[y*6]} is the same as
@samp{yyyyyy}. The notation @samp{[@var{c}*]} in @var{string2} expands
to as many copies of @var{c} as are needed to make @var{set2} as long as
@var{set1}. If @var{n} begins with @samp{0}, it is interpreted in
octal, otherwise in decimal.
to as many copies of @var{c} as are needed to make @var{array2} as long as
@var{array1}. If @var{n} begins with @samp{0}, it is interpreted in
octal, otherwise in decimal. A zero-valued @var{n} is treated as if
it were absent.
@item Character classes
@cindex character classes
The notation @samp{[:@var{class}:]} expands to all of the characters in
the (predefined) class @var{class}. The characters expand in no
particular order, except for the @code{upper} and @code{lower} classes,
which expand in ascending order. When the @option{--delete} (@option{-d})
The notation @samp{[:@var{class}:]} expands to all characters in
the (predefined) class @var{class}. When the @option{--delete} (@option{-d})
and @option{--squeeze-repeats} (@option{-s}) options are both given, any
character class can be used in @var{set2}. Otherwise, only the
character class can be used in @var{string2}. Otherwise, only the
character classes @code{lower} and @code{upper} are accepted in
@var{set2}, and then only if the corresponding character class
@var{string2}, and then only if the corresponding character class
(@code{upper} and @code{lower}, respectively) is specified in the same
relative position in @var{set1}. Doing this specifies case conversion.
relative position in @var{string1}. Doing this specifies case conversion.
Except for case conversion, a class's characters appear in no particular order.
The class names are given below; an error results when an invalid class
name is given.
@@ -7099,10 +7118,13 @@ Hexadecimal digits.
@item Equivalence classes
@cindex equivalence classes
The syntax @samp{[=@var{c}=]} expands to all of the characters that are
equivalent to @var{c}, in no particular order. Equivalence classes are
a relatively recent invention intended to support non-English alphabets.
But there seems to be no standard way to define them or determine their
The syntax @samp{[=@var{c}=]} expands to all characters equivalent to
@var{c}, in no particular order. These equivalence classes are
allowed in @var{string2} only when @option{--delete} (@option{-d}) and
@option{--squeeze-repeats} @option{-s} are both given.
Although equivalence classes are intended to support non-English alphabets,
there seems to be no standard way to define them or determine their
contents. Therefore, they are not fully implemented in GNU @command{tr};
each character's equivalence class consists only of that character,
which is of no particular use.
@@ -7115,13 +7137,14 @@ which is of no particular use.
@cindex translating characters
@command{tr} performs translation when @var{set1} and @var{set2} are
@command{tr} performs translation when @var{string1} and @var{string2} are
both given and the @option{--delete} (@option{-d}) option is not given.
@command{tr} translates each character of its input that is in @var{set1}
to the corresponding character in @var{set2}. Characters not in
@var{set1} are passed through unchanged. When a character appears more
than once in @var{set1} and the corresponding characters in @var{set2}
are not all the same, only the final one is used. For example, these
@command{tr} translates each character of its input that is in @var{array1}
to the corresponding character in @var{array2}. Characters not in
@var{array1} are passed through unchanged.
As a GNU extension to POSIX, when a character appears more than once
in @var{array1}, only the final instance is used. For example, these
two commands are equivalent:
@example
@@ -7139,17 +7162,17 @@ tr '[:lower:]' '[:upper:]'
@end example
@noindent
But note that using ranges like @code{a-z} above is not portable.
However, ranges like @code{a-z} are not portable outside the C locale.
When @command{tr} is performing translation, @var{set1} and @var{set2}
typically have the same length. If @var{set1} is shorter than
@var{set2}, the extra characters at the end of @var{set2} are ignored.
When @command{tr} is performing translation, @var{array1} and @var{array2}
typically have the same length. If @var{array1} is shorter than
@var{array2}, the extra characters at the end of @var{array2} are ignored.
On the other hand, making @var{set1} longer than @var{set2} is not
On the other hand, making @var{array1} longer than @var{array2} is not
portable; POSIX says that the result is undefined. In this situation,
BSD @command{tr} pads @var{set2} to the length of @var{set1} by repeating
the last character of @var{set2} as many times as necessary. System V
@command{tr} truncates @var{set1} to the length of @var{set2}.
BSD @command{tr} pads @var{array2} to the length of @var{array1} by repeating
the last character of @var{array2} as many times as necessary. System V
@command{tr} truncates @var{array1} to the length of @var{array2}.
By default, GNU @command{tr} handles this case like BSD @command{tr}.
When the @option{--truncate-set1} (@option{-t}) option is given,
@@ -7165,13 +7188,12 @@ tr -cs A-Za-z0-9 '\012'
@noindent
because it converts only zero bytes (the first element in the
complement of @var{set1}), rather than all non-alphanumerics, to
complement of @var{array1}), rather than all non-alphanumerics, to
newlines.
@noindent
By the way, the above idiom is not portable because it uses ranges, and
it assumes that the octal code for newline is 012.
Assuming a POSIX compliant @command{tr}, here is a better
it assumes that the octal code for newline is 012. Here is a better
way to write it:
@example
@@ -7187,20 +7209,20 @@ tr -cs '[:alnum:]' '[\n*]'
@cindex removing characters
When given just the @option{--delete} (@option{-d}) option, @command{tr}
removes any input characters that are in @var{set1}.
removes any input characters that are in @var{array1}.
When given just the @option{--squeeze-repeats} (@option{-s}) option
and not translating, @command{tr} replaces each input sequence of a
repeated character that is in @var{set1} with a single occurrence of
repeated character that is in @var{array1} with a single occurrence of
that character.
When given both @option{--delete} and @option{--squeeze-repeats}, @command{tr}
first performs any deletions using @var{set1}, then squeezes repeats
from any remaining characters using @var{set2}.
first performs any deletions using @var{array1}, then squeezes repeats
from any remaining characters using @var{array2}.
The @option{--squeeze-repeats} option may also be used when translating,
in which case @command{tr} first performs translation, then squeezes
repeats from any remaining characters using @var{set2}.
repeats from any remaining characters using @var{array2}.
Here are some examples to illustrate various combinations of options:
@@ -7224,7 +7246,7 @@ tr -cs '[:alnum:]' '[\n*]'
@item
Convert each sequence of repeated newlines to a single newline.
I.e., delete blank lines:
I.e., delete empty lines:
@example
tr -s '\n'
@@ -7278,16 +7300,6 @@ Or you can use @samp{--} to terminate option processing:
tr -d -- -axM
@end example
More generally, use the character class notation @code{[=c=]}
with @samp{-} (or any other character) in place of the @samp{c}:
@example
tr -d '[=-=]axM'
@end example
Note how single quotes are used in the above example to protect the
square brackets from interpretation by a shell.
@end itemize
@@ -8109,7 +8121,7 @@ may be omitted, or one of:
@end itemize
Specifying @option{--color} and no @var{when} is equivalent to
@option{--color=always}.
If piping a colorized listing through a pager like @command{less},
If piping a colored listing through a pager like @command{less},
use the pager's @option{-R} option to pass the color codes to the terminal.
@vindex LS_COLORS
@@ -8238,14 +8250,6 @@ List files horizontally, with as many as will fit on each line,
separated by @samp{, } (a comma and a space),
and with no other information.
@item --zero
@opindex --zero
@outputNUL
This option is incompatible with the @option{--dired} (@option{-D}) option.
This option also implies the options @option{--show-control-chars},
@option{-1}, @option{--color=none}, and
@option{--quoting-style=literal} (@option{-N}).
@item -p
@itemx --indicator-style=slash
@opindex -p
@@ -8287,6 +8291,14 @@ is 80. With a @var{cols} value of @samp{0}, there is no limit on
the length of the output line, and that single output line will
be delimited with spaces, not tabs.
@item --zero
@opindex --zero
@outputNUL
This option is incompatible with the @option{--dired} (@option{-D}) option.
This option also implies the options @option{--show-control-chars},
@option{-1}, @option{--color=none}, and
@option{--quoting-style=literal} (@option{-N}).
@end table
@@ -8624,6 +8636,12 @@ Print the (compiled-in) default color configuration database. This
output is itself a valid configuration file, and is fairly descriptive
of the possibilities.
@item --print-ls-colors
@opindex --print-ls-colors
@cindex printing ls colors
Print the LS_COLORS entries on separate lines,
each colored as per the color they represent.
@end table
@exitstatus
@@ -9148,9 +9166,8 @@ option, and overrides the @option{--preserve=all} and @option{-a} options.
@pindex dd
@cindex converting while copying a file
@command{dd} copies a file (from standard input to standard output, by
default) with a changeable I/O block size, while optionally performing
conversions on it. Synopses:
@command{dd} copies input to output with a changeable I/O block size,
while optionally performing conversions on the data. Synopses:
@example
dd [@var{operand}]@dots{}
@@ -9158,7 +9175,43 @@ dd @var{option}
@end example
The only options are @option{--help} and @option{--version}.
@xref{Common options}. @command{dd} accepts the following operands,
@xref{Common options}.
By default, @command{dd} copies standard input to standard output.
To copy, @command{dd} repeatedly does the following steps in order:
@enumerate
@item
Read an input block.
@item
If converting via @samp{sync}, pad as needed to meet the input block size.
Pad with spaces if converting via @samp{block} or @samp{unblock}, NUL
bytes otherwise.
@item
If @samp{bs=} is given and no conversion mentioned in steps (4) or (5)
is given, output the data as a single block and skip all remaining steps.
@item
If the @samp{swab} conversion is given, swap each pair of input bytes.
If the input data length is odd, preserve the last input byte
(since there is nothing to swap it with).
@item
If any of the conversions @samp{swab}, @samp{block}, @samp{unblock},
@samp{lcase}, @samp{ucase}, @samp{ascii}, @samp{ebcdic} and @samp{ibm}
are given, do these conversions. These conversions operate
independently of input blocking, and might deal with records that span
block boundaries.
@item
Aggregate the resulting data into output blocks of the specified size,
and output each output block in turn. Do not pad the last output block;
it can be shorter than usual.
@end enumerate
@command{dd} accepts the following operands,
whose syntax was inspired by the DD (data definition) statement of
OS/360 JCL.
@@ -9171,8 +9224,7 @@ Read from @var{file} instead of standard input.
@item of=@var{file}
@opindex of
Write to @var{file} instead of standard output. Unless
@samp{conv=notrunc} is given, @command{dd} truncates @var{file} to zero
bytes (or the size specified with @samp{seek=}).
@samp{conv=notrunc} is given, truncate @var{file} before writing it.
@item ibs=@var{bytes}
@opindex ibs
@@ -9212,28 +9264,37 @@ When converting variable-length records to fixed-length ones
use @var{bytes} as the fixed record length.
@item skip=@var{n}
@itemx iseek=@var{n}
@opindex skip
@opindex iseek
Skip @var{n} @samp{ibs}-byte blocks in the input file before copying.
If @samp{iflag=skip_bytes} is specified, @var{n} is interpreted
If @var{n} ends in the letter @samp{B}, interpret @var{n}
as a byte count rather than a block count.
(@samp{B} and the @samp{iseek=} spelling are GNU extensions to POSIX.)
@item seek=@var{n}
@itemx oseek=@var{n}
@opindex seek
Skip @var{n} @samp{obs}-byte blocks in the output file before copying.
if @samp{oflag=seek_bytes} is specified, @var{n} is interpreted
@opindex oseek
Skip @var{n} @samp{obs}-byte blocks in the output file before
truncating or copying.
If @var{n} ends in the letter @samp{B}, interpret @var{n}
as a byte count rather than a block count.
(@samp{B} and the @samp{oseek=} spelling are GNU extensions to POSIX.)
@item count=@var{n}
@opindex count
Copy @var{n} @samp{ibs}-byte blocks from the input file, instead
of everything until the end of the file.
if @samp{iflag=count_bytes} is specified, @var{n} is interpreted
as a byte count rather than a block count.
Note if the input may return short reads as could be the case
If @var{n} ends in the letter @samp{B},
interpret @var{n} as a byte count rather than a block count;
this is a GNU extension to POSIX.
If short reads occur, as could be the case
when reading from a pipe for example, @samp{iflag=fullblock}
will ensure that @samp{count=} corresponds to complete input blocks
rather than the traditional POSIX specified behavior of counting
input read operations.
ensures that @samp{count=} counts complete input blocks
rather than input read operations.
As an extension to POSIX, @samp{count=0} copies zero blocks
instead of copying all blocks.
@item status=@var{level}
@opindex status
@@ -9279,6 +9340,8 @@ An additional line like @samp{1 truncated record} or @samp{10
truncated records} is output after the @samp{records out} line if
@samp{conv=block} processing truncated one or more input records.
The @samp{status=} operand is a GNU extension to POSIX.
@item conv=@var{conversion}[,@var{conversion}]@dots{}
@opindex conv
Convert the file as specified by the @var{conversion} argument(s).
@@ -9326,6 +9389,8 @@ Remove any trailing spaces in each @samp{cbs}-sized input block,
and append a newline.
The @samp{block} and @samp{unblock} conversions are mutually exclusive.
If you use either of these conversions, you should also use the
@samp{cbs=} operand.
@item lcase
@opindex lcase@r{, converting to}
@@ -9351,12 +9416,12 @@ Similarly, when the output is a device rather than a file,
NUL input blocks are not copied, and therefore this conversion
is most useful with virtual or pre zeroed devices.
The @samp{sparse} conversion is a GNU extension to POSIX.
@item swab
@opindex swab @r{(byte-swapping)}
@cindex byte-swapping
Swap every pair of input bytes. GNU @command{dd}, unlike others, works
when an odd number of bytes are read---the last byte is simply copied
(since there is nothing to swap it with).
Swap every pair of input bytes.
@item sync
@opindex sync @r{(padding with ASCII NULs)}
@@ -9381,7 +9446,8 @@ output file itself.
@cindex creating output file, avoiding
Do not create the output file; the output file must already exist.
The @samp{excl} and @samp{nocreat} conversions are mutually exclusive.
The @samp{excl} and @samp{nocreat} conversions are mutually exclusive,
and are GNU extensions to POSIX.
@item notrunc
@opindex notrunc
@@ -9396,14 +9462,18 @@ Continue after read errors.
@item fdatasync
@opindex fdatasync
@cindex synchronized data writes, before finishing
Synchronize output data just before finishing. This forces a physical
write of output data.
Synchronize output data just before finishing,
even if there were write errors.
This forces a physical write of output data.
This conversion is a GNU extension to POSIX.
@item fsync
@opindex fsync
@cindex synchronized data and metadata writes, before finishing
Synchronize output data and metadata just before finishing. This
forces a physical write of output data and metadata.
Synchronize output data and metadata just before finishing,
even if there were write errors.
This forces a physical write of output data and metadata.
This conversion is a GNU extension to POSIX.
@end table
@@ -9417,8 +9487,7 @@ argument(s). (No spaces around any comma(s).)
Access the output file using the flags specified by the @var{flag}
argument(s). (No spaces around any comma(s).)
Here are the flags. Not every flag is supported on every operating
system.
Here are the flags.
@table @samp
@@ -9559,30 +9628,10 @@ as they may return short reads. In that case,
this flag is needed to ensure that a @samp{count=} argument is
interpreted as a block count rather than a count of read operations.
@item count_bytes
@opindex count_bytes
Interpret the @samp{count=} operand as a byte count,
rather than a block count, which allows specifying
a length that is not a multiple of the I/O block size.
This flag can be used only with @code{iflag}.
@item skip_bytes
@opindex skip_bytes
Interpret the @samp{skip=} operand as a byte count,
rather than a block count, which allows specifying
an offset that is not a multiple of the I/O block size.
This flag can be used only with @code{iflag}.
@item seek_bytes
@opindex seek_bytes
Interpret the @samp{seek=} operand as a byte count,
rather than a block count, which allows specifying
an offset that is not a multiple of the I/O block size.
This flag can be used only with @code{oflag}.
@end table
These flags are not supported on all systems, and @samp{dd} rejects
These flags are all GNU extensions to POSIX.
They are not supported on all systems, and @samp{dd} rejects
attempts to use them when they are not supported. When reading from
standard input or writing to standard output, the @samp{nofollow} and
@samp{noctty} flags should not be specified, and the other flags
@@ -9591,34 +9640,42 @@ affected file descriptors, even after @command{dd} exits.
@end table
The behavior of @command{dd} is unspecified if operands other than
@samp{conv=}, @samp{iflag=}, @samp{oflag=}, and @samp{status=} are
specified more than once.
@cindex multipliers after numbers
The numeric-valued strings above (@var{n} and @var{bytes})
are unsigned decimal integers that
can be followed by a multiplier: @samp{b}=512, @samp{c}=1,
@samp{w}=2, @samp{x@var{m}}=@var{m}, or any of the
standard block size suffixes like @samp{k}=1024 (@pxref{Block size}).
These multipliers are GNU extensions to POSIX, except that
POSIX allows @var{bytes} to be followed by @samp{k}, @samp{b}, and
@samp{x@var{m}}.
Block sizes (i.e., specified by @var{bytes} strings) must be nonzero.
Any block size you specify via @samp{bs=}, @samp{ibs=}, @samp{obs=}, @samp{cbs=}
should not be too large---values larger than a few megabytes
are generally wasteful or (as in the gigabyte..exabyte case) downright
counterproductive or error-inducing.
To process data that is at an offset or size that is not a
multiple of the I/O@ block size, you can use the @samp{skip_bytes},
@samp{seek_bytes} and @samp{count_bytes} flags. Alternatively
the traditional method of separate @command{dd} invocations can be used.
To process data with offset or size that is not a multiple of the I/O
block size, you can use a numeric string @var{n} that ends in the
letter @samp{B}.
For example, the following shell commands copy data
in 512 KiB blocks between a flash drive and a tape, but do not save
or restore a 1 MiB area at the start of the flash drive:
in 1 MiB blocks between a flash drive and a tape, but do not save
or restore a 512-byte area at the start of the flash drive:
@example
flash=/dev/sda
tape=/dev/st0
# Copy all but the initial 1 MiB from flash to tape.
(dd bs=1M skip=1 count=0 && dd bs=512k) <$flash >$tape
# Copy all but the initial 512 bytes from flash to tape.
dd if=$flash iseek=512B bs=1MiB of=$tape
# Copy from tape back to flash, leaving initial 1 MiB alone.
(dd bs=1M seek=1 count=0 && dd bs=512k) <$tape >$flash
# Copy from tape back to flash, leaving initial 512 bytes alone.
dd if=$tape bs=1MiB of=$flash oseek=512B
@end example
@cindex ddrescue
@@ -9739,8 +9796,8 @@ The program accepts the following options. Also see @ref{Common options}.
@itemx --compare
@opindex -C
@opindex --compare
Compare each pair of source and destination files, and if the destination has
identical content and any specified owner, group, permissions, and possibly
Compare content of source and destination files, and if there would be no
change to the destination content, owner, group, permissions, and possibly
SELinux context, then do not modify the destination at all.
Note this option is best used in conjunction with @option{--user},
@option{--group} and @option{--mode} options, lest @command{install}
@@ -11261,7 +11318,8 @@ or group ID, then you may specify it with a leading @samp{+}.
Some older scripts may still use @samp{.} in place of the @samp{:} separator.
POSIX 1003.1-2001 (@pxref{Standards conformance}) does not
require support for that, but for backward compatibility GNU
@command{chown} supports @samp{.} so long as no ambiguity results.
@command{chown} supports @samp{.} so long as no ambiguity results,
although it issues a warning and support may be removed in future versions.
New scripts should avoid the use of @samp{.} because it is not
portable, and because it has undesirable results if the entire
@var{owner@samp{.}group} happens to identify a user whose name
@@ -11609,7 +11667,7 @@ The program accepts the following options. Also see @ref{Common options}.
@opindex -c
@opindex --changes
Verbosely describe the action for each @var{file} whose permissions
actually changes.
actually change.
@item -f
@itemx --silent
@@ -12550,6 +12608,7 @@ Always read the already cached attributes if available.
@item never
Always sychronize with the latest file system attributes.
This also mounts automounted files.
@item default
Leave the caching behavior to the underlying file system.
@@ -12896,6 +12955,13 @@ echo [@var{option}]@dots{} [@var{string}]@dots{}
@mayConflictWithShellBuiltIn{echo}
Due to historical and backwards compatibility reasons, certain bare option-like
strings cannot be passed to @command{echo} as non-option arguments.
It is therefore not advisable to use @command{echo} for printing unknown or
variable arguments. The @command{printf} command is recommended as a more
portable and flexible replacement for tasks historically performed by
@command{echo}. @xref{printf invocation}.
The program accepts the following options. Also see @ref{Common options}.
Options must precede operands, and the normally-special argument
@samp{--} has no special meaning and is treated like any other
@@ -12961,13 +13027,15 @@ If the @env{POSIXLY_CORRECT} environment variable is set, then when
option-like arguments instead of treating them as options. For
example, @code{echo -ne hello} outputs @samp{-ne hello} instead of
plain @samp{hello}. Also backslash escapes are always enabled.
Note to echo the string @samp{-n}, one of the characters
can be escaped in either octal or hexadecimal representation.
For example, @code{echo -e '\x2dn'}.
POSIX does not require support for any options, and says
that the behavior of @command{echo} is implementation-defined if any
@var{string} contains a backslash or if the first argument is
@option{-n}. Portable programs can use the @command{printf} command
if they need to omit trailing newlines or output control characters or
backslashes. @xref{printf invocation}.
@var{string} contains a backslash or if the first argument is @option{-n}.
Portable programs should use the @command{printf} command instead.
@xref{printf invocation}.
@exitstatus
@@ -13383,7 +13451,7 @@ True if @var{file} exists and has its @dfn{sticky} bit set.
@item -r @var{file}
@opindex -r
@cindex readable file check
True if @var{file} exists and read permission is granted.
True if @var{file} exists and the user has read access.
@item -u @var{file}
@opindex -u
@@ -13393,12 +13461,12 @@ True if @var{file} exists and has its set-user-ID bit set.
@item -w @var{file}
@opindex -w
@cindex writable file check
True if @var{file} exists and write permission is granted.
True if @var{file} exists and the user has write access.
@item -x @var{file}
@opindex -x
@cindex executable file check
True if @var{file} exists and execute permission is granted
True if @var{file} exists and the user has execute access
(or search permission, if it is a directory).
@item -O @var{file}
@@ -13910,11 +13978,11 @@ If a file being written to does not already exist, it is created. If a
file being written to already exists, the data it previously contained
is overwritten unless the @option{-a} option is used.
In previous versions of GNU coreutils (v5.3.0 - v8.23), a @var{file} of @samp{-}
In previous versions of GNU Coreutils (v5.3.0 -- v8.23),
a @var{file} of @samp{-}
caused @command{tee} to send another copy of input to standard output.
However, as the interleaved output was not very useful, @command{tee} now
conforms to POSIX which explicitly mandates it to treat @samp{-} as a file
with such name.
conforms to POSIX and treats @samp{-} as a file name.
The program accepts the following options. Also see @ref{Common options}.
@@ -15967,6 +16035,11 @@ date [-u|--utc|--universal] @c this avoids a newline in the output
[ MMDDhhmm[[CC]YY][.ss] ]
@end example
The @command{date} command displays the date and time.
With the @option{--set} (@option{-s}) option, or with
@samp{MMDDhhmm[[CC]YY][.ss]},
it sets the date and time.
@vindex LC_TIME
Invoking @command{date} with no @var{format} argument is equivalent to invoking
it with a default format that depends on the @env{LC_TIME} locale category.
@@ -16218,6 +16291,12 @@ The following optional flags can appear after the @samp{%}:
(hyphen) Do not pad the field; useful if the output is intended for
human consumption.
This is a GNU extension.
As a special case, @samp{%-N} outputs only enough trailing digits to
not lose information, assuming that the timestamp's resolution is the
same as the current hardware clock. For example, if the hardware
clock resolution is 1 microsecond, @samp{%s.%-N} outputs something
like @samp{1640890100.395710}.
@item _
(underscore) Pad with spaces; useful if you need a fixed
number of characters in the output, but zeros are too distracting.
@@ -16294,17 +16373,18 @@ modifiers are GNU extensions.
@cindex time setting
@cindex appropriate privileges
If given an argument that does not start with @samp{+}, @command{date} sets
the system clock to the date and time specified by that argument (as
described below). You must have appropriate privileges to set the
system clock. Note for changes to persist across a reboot, the
You must have appropriate privileges to set the
system clock. For changes to persist across a reboot, the
hardware clock may need to be updated from the system clock, which
might not happen automatically on your system.
The argument must consist entirely of digits, which have the following
meaning:
To set the clock, you can use the @option{--set} (@option{-s}) option
(@pxref{Options for date}). To set the clock without using GNU
extensions, you can give @command{date} an argument of the form
@samp{MMDDhhmm[[CC]YY][.ss]} where each two-letter
component stands for two digits with the following meanings:
@table @samp
@table @var
@item MM
month
@item DD
@@ -16334,6 +16414,7 @@ relative to Universal Time rather than to the local time zone.
@cindex options for @command{date}
The program accepts the following options. Also see @ref{Common options}.
Except for @option{-u}, these options are all GNU extensions to POSIX.
@table @samp
@@ -16421,6 +16502,19 @@ for the @option{--date} (@option{-d}) and @option{--file}
Display the date and time of the last modification of @var{file},
instead of the current date and time.
@item --resolution
@opindex --resolution
Display the timestamp resolution instead of the time.
Current clock timestamps that are output by @command{date}
are integer multiples of the timestamp resolution.
With this option, the format defaults to @samp{%s.%N}.
For example, if the clock resolution is 1 millsecond,
the output is:
@example
0.001000000
@end example
@item -R
@itemx --rfc-email
@opindex -R
@@ -16449,7 +16543,8 @@ For compatibility with older versions of @command{date},
Display the date using a format specified by
@uref{https://tools.ietf.org/search/rfc3339, Internet
RFC 3339}. This is like @option{--iso-8601}, except that a space rather
than a @samp{T} separates dates from times.
than a @samp{T} separates dates from times, and a period rather than
a comma separates seconds from subseconds.
@dateParseNote
The argument @var{timespec} specifies how much of the time to include.
@@ -18273,8 +18368,9 @@ The specified @var{duration} starts from the point in time when
@command{timeout} sends the initial signal to @var{command}, i.e.,
not from the beginning when the @var{command} is started.
This option has no effect if @command{timeout}'s duration is 0 which
disables the associated timeout.
This option has no effect if either the main @var{duration}
of the @command{timeout} command, or the @var{duration} specified
to this option, is 0.
This option may be useful if the selected signal did not kill the @var{command},
either because the signal was blocked or ignored, or if the @var{command} takes
@@ -18321,7 +18417,7 @@ Exit status:
the exit status of @var{command} otherwise
@end display
In case of the @samp{KILL(9)} signal, @command{timeout} returns with
In the case of the @samp{KILL(9)} signal, @command{timeout} returns with
exit status 137, regardless of whether that signal is sent to @var{command}
or to @command{timeout} itself, i.e., these cases cannot be distinguished.
In the latter case, the @var{command} process may still be alive after

View File

@@ -414,7 +414,7 @@ The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
@uref{https://www.gnu.org/copyleft/}.
@uref{https://www.gnu.org/licenses/}.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this

View File

@@ -1,7 +1,7 @@
# Make coreutils documentation. -*-Makefile-*-
# This is included by the top-level Makefile.am.
# Copyright (C) 1995-2021 Free Software Foundation, Inc.
# Copyright (C) 1995-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
@c File mode bits
@c Copyright (C) 1994--2021 Free Software Foundation, Inc.
@c Copyright (C) 1994--2022 Free Software Foundation, Inc.
@c Permission is granted to copy, distribute and/or modify this document
@c under the terms of the GNU Free Documentation License, Version 1.3 or

View File

@@ -1,6 +1,6 @@
@c GNU Version-sort ordering documentation
@c Copyright (C) 2019--2021 Free Software Foundation, Inc.
@c Copyright (C) 2019--2022 Free Software Foundation, Inc.
@c Permission is granted to copy, distribute and/or modify this document
@c under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -19,18 +19,17 @@
@node Version sort overview
@section Version sort overview
@dfn{version sort} ordering (and similarly, @dfn{natural sort}
ordering) is a method to sort items such as file names and lines of
text in an order that feels more natural to people, when the text
@dfn{Version sort} puts items such as file names and lines of
text in an order that feels natural to people, when the text
contains a mixture of letters and digits.
Standard sorting usually does not produce the order that one expects
Lexicographic sorting usually does not produce the order that one expects
because comparisons are made on a character-by-character basis.
Compare the sorting of the following items:
@example
Alphabetical sort: Version Sort:
Lexicographic sort: Version Sort:
a1 a1
a120 a2
@@ -38,18 +37,19 @@ a13 a13
a2 a120
@end example
version sort functionality in GNU coreutils is available in the @samp{ls -v},
@samp{ls --sort=version}, @samp{sort -V}, @samp{sort --version-sort} commands.
Version sort functionality in GNU Coreutils is available in the @samp{ls -v},
@samp{ls --sort=version}, @samp{sort -V}, and
@samp{sort --version-sort} commands.
@node Using version sort in GNU coreutils
@subsection Using version sort in GNU coreutils
@node Using version sort in GNU Coreutils
@subsection Using version sort in GNU Coreutils
Two GNU coreutils programs use version sort: @command{ls} and @command{sort}.
Two GNU Coreutils programs use version sort: @command{ls} and @command{sort}.
To list files in version sort order, use @command{ls}
with @option{-v} or @option{--sort=version} options:
with the @option{-v} or @option{--sort=version} option:
@example
default sort: version sort:
@@ -64,7 +64,7 @@ a2 a100
@end example
To sort text files in version sort order, use @command{sort} with
the @option{-V} option:
the @option{-V} or @option{--version-sort} option:
@example
$ cat input
@@ -74,7 +74,7 @@ b1
b20
alphabetical order: version sort order:
lexicographic order: version sort order:
$ sort input $ sort -V input
b1 b1
@@ -83,71 +83,71 @@ b20 b11
b3 b20
@end example
To sort a specific column in a file use @option{-k/--key} with @samp{V}
ordering option:
To sort a specific field in a file, use @option{-k/--key} with
@samp{V} type sorting, which is often combined with @samp{b} to
ignore leading blanks in the field:
@example
$ cat input2
1000 b3 apples
100 b3 apples
2000 b11 oranges
3000 b1 potatoes
4000 b20 bananas
$ sort -k2V,2 input2
$ sort -k 2bV,2 input2
3000 b1 potatoes
1000 b3 apples
100 b3 apples
2000 b11 oranges
4000 b20 bananas
@end example
@node Origin of version sort and differences from natural sort
@subsection Origin of version sort and differences from natural sort
@node Version sort and natural sort
@subsection Version sort and natural sort
In GNU coreutils, the name @dfn{version sort} was chosen because it is based
In GNU Coreutils, the name @dfn{version sort} was chosen because it is based
on Debian GNU/Linux's algorithm of sorting packages' versions.
Its goal is to answer the question
``which package is newer, @file{firefox-60.7.2} or @file{firefox-60.12.3} ?''
Its goal is to answer questions like
``Which package is newer, @file{firefox-60.7.2} or @file{firefox-60.12.3}?''
In coreutils this algorithm was slightly modified to work on more
In Coreutils this algorithm was slightly modified to work on more
general input such as textual strings and file names
(see @ref{Differences from the official Debian Algorithm}).
(see @ref{Differences from Debian version sort}).
In other contexts, such as other programs and other programming
languages, a similar sorting functionality is called
@uref{https://en.wikipedia.org/wiki/Natural_sort_order,natural sort}.
@node Correct/Incorrect ordering and Expected/Unexpected results
@subsection Correct/Incorrect ordering and Expected/Unexpected results
@node Variations in version sort order
@subsection Variations in version sort order
Currently there is no standard for version/natural sort ordering.
Currently there is no standard for version sort.
That is: there is no one correct way or universally agreed-upon way to
order items. Each program and each programming language can decide its
own ordering algorithm and call it 'natural sort' (or other various
names).
own ordering algorithm and call it ``version sort'', ``natural sort'',
or other names.
See @ref{Other version/natural sort implementations} for many examples of
differing sorting possibilities, each with its own rules and variations.
If you do suspect a bug in coreutils' implementation of version-sort,
see @ref{Reporting bugs or incorrect results} on how to report them.
If you find a bug in the Coreutils implementation of version-sort, please
report it. @xref{Reporting version sort bugs}.
@node Implementation Details
@section Implementation Details
@node Version sort implementation
@section Version sort implementation
GNU coreutils' version sort algorithm is based on
GNU Coreutils version sort is based on the ``upstream version''
part of
@uref{https://www.debian.org/doc/debian-policy/ch-controlfields.html#version,
Debian's versioning scheme}, specifically on the "upstream version"
part.
Debian's versioning scheme}.
This section describes the ordering rules.
This section describes the GNU Coreutils sort ordering rules.
The next section (@ref{Differences from the official Debian
Algorithm}) describes some differences between GNU coreutils
implementation and Debian's official algorithm.
The next section (@ref{Differences from Debian version
sort}) describes some differences between GNU Coreutils
and Debian version sort.
@node Version-sort ordering rules
@@ -161,33 +161,40 @@ The strings are compared from left to right.
@item
First the initial part of each string consisting entirely of non-digit
characters is determined.
bytes is determined.
@enumerate
@enumerate A
@item
These two parts (one of which may be empty) are compared lexically.
These two parts (either of which may be empty) are compared lexically.
If a difference is found it is returned.
@item
The lexical comparison is a comparison of ASCII values modified so that:
The lexical comparison is a lexicographic comparison of byte strings,
except that:
@enumerate
@enumerate a
@item
all the letters sort earlier than all the non-letters and
ASCII letters sort before other bytes.
@item
so that a tilde sorts before anything, even the end of a part.
A tilde sorts before anything, even an empty string.
@end enumerate
@end enumerate
@item
Then the initial part of the remainder of each string which consists
entirely of digit characters is determined. The numerical values of
Then the initial part of the remainder of each string that contains
all the leading digits is determined. The numerical values represented by
these two parts are compared, and any difference found is returned as
the result of the comparison.
@enumerate
@enumerate A
@item
For these purposes an empty string (which can only occur at the end of
one or both version strings being compared) counts as zero.
@item
Because the numerical value is used, non-identical strings can compare
equal. For example, @samp{123} compares equal to @samp{00123}, and
the empty string compares equal to @samp{0}.
@end enumerate
@item
@@ -202,8 +209,8 @@ down to the following parts, and the parts compared respectively from
each string:
@example
foo @r{vs} foo @r{(rule 2, non-digits characters)}
07 @r{vs} 7 @r{(rule 3, digits characters)}
foo @r{vs} foo @r{(rule 2, non-digits)}
07 @r{vs} 7 @r{(rule 3, digits)}
. @r{vs} a. @r{(rule 2)}
7 @r{vs} 7 @r{(rule 3)}
z @r{vs} z @r{(rule 2)}
@@ -213,23 +220,23 @@ Comparison flow based on above algorithm:
@enumerate
@item
The first parts (@code{foo}) are identical in both strings.
The first parts (@samp{foo}) are identical.
@item
The second parts (@code{07} and @code{7}) are compared numerically,
and are identical.
The second parts (@samp{07} and @samp{7}) are compared numerically,
and compare equal.
@item
The third parts (@samp{@code{.}} vs @samp{@code{a.}}) are compared
lexically by ASCII value (rule 2.2).
The third parts (@samp{.} vs @samp{a.}) are compared
lexically by ASCII value (rule 2.B).
@item
The first character of the first string (@samp{@code{.}}) is compared
to the first character of the second string (@samp{@code{a}}).
The first byte of the first string (@samp{.}) is compared
to the first byte of the second string (@samp{a}).
@item
Rule 2.2.1 dictates that "all letters sorts earlier than all non-letters".
Hence, @samp{@code{a}} comes before @samp{@code{.}}.
Rule 2.B.a says letters sorts before non-letters.
Hence, @samp{a} comes before @samp{.}.
@item
The returned result is that @file{foo7a.7z} comes before @file{foo07.7z}.
@@ -241,14 +248,13 @@ Result when using sort:
$ cat input3
foo07.7z
foo7a.7z
$ sort -V input3
foo7a.7z
foo07.7z
@end example
See @ref{Differences from the official Debian Algorithm} for
additional rules that extend the Debian algorithm in coreutils.
See @ref{Differences from Debian version sort} for
additional rules that extend the Debian algorithm in Coreutils.
@node Version sort is not the same as numeric sort
@@ -266,8 +272,6 @@ $ cat input4
8.100
8.49
Numerical Sort: Version Sort:
$ sort -n input4 $ sort -V input4
@@ -281,64 +285,63 @@ $ sort -n input4 $ sort -V input4
@end example
Numeric sort (@samp{sort -n}) treats the entire string as a single numeric
value, and compares it to other values. For example, @code{8.1}, @code{8.10} and
@code{8.100} are numerically equivalent, and are ordered together. Similarly,
@code{8.49} is numerically smaller than @code{8.5}, and appears before first.
value, and compares it to other values. For example, @samp{8.1}, @samp{8.10} and
@samp{8.100} are numerically equivalent, and are ordered together. Similarly,
@samp{8.49} is numerically less than @samp{8.5}, and appears before first.
Version sort (@samp{sort -V}) first breaks down the string into digits and
non-digits parts, and only then compares each part (see annotated
example in Version-sort ordering rules).
Version sort (@samp{sort -V}) first breaks down the string into digit and
non-digit parts, and only then compares each part (see annotated
example in @ref{Version-sort ordering rules}).
Comparing the string @code{8.1} to @code{8.01}, first the
@samp{@code{8}} characters are compared (and are identical), then the
dots (@samp{@code{.}}) are compared and are identical, and lastly the
remaining digits are compared numerically (@code{1} and @code{01}) -
which are numerically equivalent. Hence, @code{8.01} and @code{8.1}
Comparing the string @samp{8.1} to @samp{8.01}, first the
@samp{8}s are compared (and are identical), then the
dots (@samp{.}) are compared and are identical, and lastly the
remaining digits are compared numerically (@samp{1} and @samp{01}) -
which are numerically equal. Hence, @samp{8.01} and @samp{8.1}
are grouped together.
Similarly, comparing @code{8.5} to @code{8.49} - the @samp{@code{8}}
and @samp{@code{.}} parts are identical, then the numeric values @code{5} and
@code{49} are compared. The resulting @code{5} appears before @code{49}.
Similarly, comparing @samp{8.5} to @samp{8.49} -- the @samp{8}
and @samp{.} parts are identical, then the numeric values @samp{5} and
@samp{49} are compared. The resulting @samp{5} appears before @samp{49}.
This sorting order (where @code{8.5} comes before @code{8.49}) is common when
This sorting order (where @samp{8.5} comes before @samp{8.49}) is common when
assigning versions to computer programs (while perhaps not intuitive
or 'natural' for people).
or ``natural'' for people).
@node Punctuation Characters
@subsection Punctuation Characters
@node Version sort punctuation
@subsection Version sort punctuation
Punctuation characters are sorted by ASCII order (rule 2.2).
Punctuation is sorted by ASCII order (rule 2.B).
@example
$ touch 1.0.5_src.tar.gz 1.0_src.tar.gz
$ touch 1.0.5_src.tar.gz 1.0_src.tar.gz
$ ls -v -1
1.0.5_src.tar.gz
1.0_src.tar.gz
@end example
Why is @file{1.0.5_src.tar.gz} listed before @file{1.0_src.tar.gz} ?
Why is @file{1.0.5_src.tar.gz} listed before @file{1.0_src.tar.gz}?
Based on the @ref{Version-sort ordering rules,algorithm,algorithm}
above, the strings are broken down into the following parts:
Based on the version-sort ordering rules, the strings are broken down
into the following parts:
@example
1 @r{vs} 1 @r{(rule 3, all digit characters)}
. @r{vs} . @r{(rule 2, all non-digit characters)}
1 @r{vs} 1 @r{(rule 3, all digits)}
. @r{vs} . @r{(rule 2, all non-digits)}
0 @r{vs} 0 @r{(rule 3)}
. @r{vs} _src.tar.gz @r{(rule 2)}
5 @r{vs} empty string @r{(no more character in the file name)}
5 @r{vs} empty string @r{(no more bytes in the file name)}
_src.tar.gz @r{vs} empty string
@end example
The fourth parts (@samp{@code{.}} and @code{_src.tar.gz}) are compared
lexically by ASCII order. The character @samp{@code{.}} (ASCII value 46) is
smaller than @samp{@code{_}} (ASCII value 95) - and should be listed before it.
The fourth parts (@samp{.} and @samp{_src.tar.gz}) are compared
lexically by ASCII order. The @samp{.} (ASCII value 46) is
less than @samp{_} (ASCII value 95) -- and should be listed before it.
Hence, @file{1.0.5_src.tar.gz} is listed first.
If a different character appears instead of the underscore (for
example, percent sign @samp{@code{%}} ASCII value 37, which is smaller
If a different byte appears instead of the underscore (for
example, percent sign @samp{%} ASCII value 37, which is less
than dot's ASCII value of 46), that file will be listed first:
@example
@@ -347,55 +350,52 @@ $ touch 1.0.5_src.tar.gz 1.0%zzzzz.gz
1.0.5_src.tar.gz
@end example
The same reasoning applies to the following example: The character
@samp{@code{.}} has ASCII value 46, and is smaller than slash
character @samp{@code{/}} ASCII value 47:
The same reasoning applies to the following example, as @samp{.} with
ASCII value 46 is less than @samp{/} with ASCII value 47:
@example
$ cat input5
3.0/
3.0.5
$ sort -V input5
3.0.5
3.0/
@end example
@node Punctuation Characters vs letters
@subsection Punctuation Characters vs letters
@node Punctuation vs letters
@subsection Punctuation vs letters
Rule 2.2.1 dictates that letters sorts earlier than all non-letters
(after breaking down a string to digits and non-digits parts).
Rule 2.B.a says letters sort before non-letters
(after breaking down a string to digit and non-digit parts).
@example
$ cat input6
a%
az
$ sort -V input6
az
a%
@end example
The input strings consist entirely of non-digits, and based on the
above algorithm have only one part, all non-digit characters
(@samp{@code{a%}} vs @samp{@code{az}}).
above algorithm have only one part, all non-digits
(@samp{a%} vs @samp{az}).
Each part is then compared lexically,
character-by-character. @samp{@code{a}} compares identically in both
byte-by-byte; @samp{a} compares identically in both
strings.
Rule 2.2.1 dictates that letters (@samp{@code{z}}) sorts earlier than all
non-letters (@samp{@code{%}}) - hence @samp{@code{az}} appears first (despite
@samp{@code{z}} having ASCII value of 122, much bigger than @samp{@code{%}}
Rule 2.B.a says a letter like @samp{z} sorts before
a non-letter like @samp{%} -- hence @samp{az} appears first (despite
@samp{z} having ASCII value of 122, much larger than @samp{%}
with ASCII value 37).
@node Tilde @samp{~} character
@subsection Tilde @samp{~} character
@node The tilde @samp{~}
@subsection The tilde @samp{~}
Rule 2.2.2 dictates that tilde character @samp{@code{~}} (ASCII 126) sorts
before all other non-digit characters, including an empty part.
Rule 2.B.b says the tilde @samp{~} (ASCII 126) sorts
before other bytes, and before an empty string.
@example
$ cat input7
@@ -404,7 +404,6 @@ $ cat input7
1.2
1~
~
$ sort -V input7
~
1~
@@ -414,42 +413,42 @@ $ sort -V input7
@end example
The sorting algorithm starts by breaking down the string into
non-digits (rule 2) and digits parts (rule 3).
non-digit (rule 2) and digit parts (rule 3).
In the above input file, only the last line in the input file starts
with a non-digit (@samp{@code{~}}). This is the first part. All other lines
in the input file start with a digit - their first non-digit part is
with a non-digit (@samp{~}). This is the first part. All other lines
in the input file start with a digit -- their first non-digit part is
empty.
Based on rule 2.2.2, tilde @samp{@code{~}} sorts before all other non-digits
including the empty part - hence it comes before all other strings,
Based on rule 2.B.b, tilde @samp{~} sorts before other bytes
and before the empty string -- hence it comes before all other strings,
and is listed first in the sorted output.
The remaining lines (@code{1}, @code{1%}, @code{1.2}, @code{1~})
The remaining lines (@samp{1}, @samp{1%}, @samp{1.2}, @samp{1~})
follow similar logic: The digit part is extracted (1 for all strings)
and compares identical. The following extracted parts for the remaining
input lines are: empty part, @code{%}, @code{.}, @code{~}.
and compares equal. The following extracted parts for the remaining
input lines are: empty part, @samp{%}, @samp{.}, @samp{~}.
Tilde sorts before all others, hence the line @code{1~} appears next.
Tilde sorts before all others, hence the line @samp{1~} appears next.
The remaining lines (@code{1}, @code{1%}, @code{1.2}) are sorted based
The remaining lines (@samp{1}, @samp{1%}, @samp{1.2}) are sorted based
on previously explained rules.
@node Version sort ignores locale
@subsection Version sort uses ASCII order, ignores locale, unicode characters
@subsection Version sort ignores locale
In version sort, unicode characters are compared byte-by-byte according
to their binary representation, ignoring their unicode value or the
In version sort, Unicode characters are compared byte-by-byte according
to their binary representation, ignoring their Unicode value or the
current locale.
Most commonly, unicode characters (e.g. Greek Small Letter Alpha
U+03B1 @samp{α}) are encoded as UTF-8 bytes (e.g. @samp{α} is encoded as UTF-8
sequence @code{0xCE 0xB1}). The encoding will be compared byte-by-byte,
e.g. first @code{0xCE} (decimal value 206) then @code{0xB1} (decimal value 177).
Most commonly, Unicode characters are encoded as UTF-8 bytes; for
example, GREEK SMALL LETTER ALPHA (U+03B1, @samp{α}) is encoded as the
UTF-8 sequence @samp{0xCE 0xB1}). The encoding is compared
byte-by-byte, e.g., first @samp{0xCE} (decimal value 206) then
@samp{0xB1} (decimal value 177).
@example
$ touch aa az "a%" "aα"
$ touch aa az "a%" "aα"
$ ls -1 -v
aa
az
@@ -457,32 +456,32 @@ a%
aα
@end example
Ignoring the first letter (@code{a}) which is identical in all
Ignoring the first letter (@samp{a}) which is identical in all
strings, the compared values are:
@samp{@code{a}} and @samp{@code{z}} are letters, and sort earlier than
all other non-digit characters.
@samp{a} and @samp{z} are letters, and sort before
all other non-digits.
Then, percent sign @samp{@code{%}} (ASCII value 37) is compared to the
first byte of the UTF-8 sequence of @samp{@code{α}}, which is 0xCE or 206). The
value 37 is smaller, hence @samp{@code{a%}} is listed before @samp{@code{aα}}.
Then, percent sign @samp{%} (ASCII value 37) is compared to the
first byte of the UTF-8 sequence of @samp{α}, which is 0xCE or 206). The
value 37 is smaller, hence @samp{a%} is listed before @samp{aα}.
@node Differences from the official Debian Algorithm
@section Differences from the official Debian Algorithm
@node Differences from Debian version sort
@section Differences from Debian version sort
The GNU coreutils' version sort algorithm differs slightly from the
GNU Coreutils version sort differs slightly from the
official Debian algorithm, in order to accommodate more general usage
and file name listing.
@node Minus/Hyphen and Colon characters
@subsection Minus/Hyphen @samp{-} and Colon @samp{:} characters
@node Hyphen-minus and colon
@subsection Hyphen-minus @samp{-} and colon @samp{:}
In Debian's version string syntax the version consists of three parts:
@example
[epoch:]upstream_version[-debian_revision]
@end example
The @code{epoch} and @code{debian_revision} parts are optional.
The @samp{epoch} and @samp{debian_revision} parts are optional.
Example of such version strings:
@@ -495,62 +494,62 @@ Example of such version strings:
2:1.19.2-1+deb9u5
@end example
If the @code{debian_revision part} is not present,
hyphen characters @samp{-} are not allowed.
If the @samp{debian_revision part} is not present,
hyphens @samp{-} are not allowed.
If epoch is not present, colons @samp{:} are not allowed.
If these parts are present, hyphen and/or colons can appear only once
in valid Debian version strings.
In GNU coreutils, such restrictions are not reasonable (a file name can
In GNU Coreutils, such restrictions are not reasonable (a file name can
have many hyphens, a line of text can have many colons).
As a result, in GNU coreutils hyphens and colons are treated exactly
like all other punctuation characters (i.e., they are sorted after
letters. See Punctuation Characters above).
As a result, in GNU Coreutils hyphens and colons are treated exactly
like all other punctuation, i.e., they are sorted after
letters. @xref{Version sort punctuation}.
In Debian, these characters are treated differently than in coreutils:
In Debian, these characters are treated differently than in Coreutils:
a version string with hyphen will sort before similar strings without
hyphens.
Compare:
@example
$ touch abb ab-cd
$ touch 1ab-cd 1abb
$ ls -v -1
abb
ab-cd
1abb
1ab-cd
$ if dpkg --compare-versions 1abb lt 1ab-cd
> then echo sorted
> else echo out of order
> fi
out of order
@end example
With Debian's @command{dpkg} they will be listed as @code{ab-cd} first and
@code{abb} second.
For further details, see @ref{Comparing two strings using Debian's
algorithm} and @uref{https://bugs.gnu.org/35939,GNU Bug 35939}.
For further technical details see @uref{https://bugs.gnu.org/35939,bug35939}.
@node Special priority in GNU Coreutils version sort
@subsection Special priority in GNU Coreutils version sort
@node Additional hard-coded priorities in GNU coreutils' version sort
@subsection Additional hard-coded priorities in GNU coreutils' version sort
In GNU coreutils' version sort algorithm, the following items have
special priority and sort earlier than all other characters (listed in
order);
In GNU Coreutils version sort, the following items have
special priority and sort before all other strings (listed in order):
@enumerate
@item The empty string
@item The string @samp{@code{.}} (a single dot character, ASCII 46)
@item The string @samp{.} (a single dot, ASCII 46)
@item The string @samp{@code{..}} (two dot characters)
@item The string @samp{..} (two dots)
@item Strings start with a dot (@samp{@code{.}}) sort earlier than
strings starting with any other characters.
@item Strings starting with dot (@samp{.}) sort before
strings starting with any other byte.
@end enumerate
Example:
@example
$ printf "%s\n" a "" b "." c ".." ".d20" ".d3" | sort -V
$ printf '%s\n' a "" b "." c ".." ".d20" ".d3" | sort -V
.
..
.d3
@@ -561,7 +560,7 @@ c
@end example
These priorities make perfect sense for @samp{ls -v}: The special
files dot @samp{@code{.}} and dot-dot @samp{@code{..}} will be listed
files dot @samp{.} and dot-dot @samp{..} will be listed
first, followed by any hidden files (files starting with a dot),
followed by non-hidden files.
@@ -572,71 +571,76 @@ program, the ordering rules are the same.
@node Special handling of file extensions
@subsection Special handling of file extensions
GNU coreutils' version sort algorithm implements specialized handling
of file extensions (or strings that look like file names with
extensions).
GNU Coreutils version sort implements specialized handling
of strings that look like file names with extensions.
This enables slightly more natural ordering of file
names.
This nuanced implementation enables slightly more natural ordering of files.
The additional rules are:
The following additional rules apply when comparing two strings where
both begin with non-@samp{.}. They also apply when comparing two
strings where both begin with @samp{.} but neither is @samp{.} or @samp{..}.
@enumerate
@item
A suffix (i.e., a file extension) is defined as: a dot, followed by a
letter or tilde, followed by one or more letters, digits, or tildes
(possibly repeated more than once), until the end of the string
(technically, matching the regular expression
@code{(\.[A-Za-z~][A-Za-z0-9~]*)*}).
A suffix (i.e., a file extension) is defined as: a dot, followed by an
ASCII letter or tilde, followed by zero or more ASCII letters, digits,
or tildes; all repeated zero or more times, and ending at string end.
This is equivalent to matching the extended regular expression
@code{(\.[A-Za-z~][A-Za-z0-9~]*)*$} in the C locale.
@item
If the strings contains suffixes, the suffixes are temporarily
removed, and the strings are compared without them (using the
@ref{Version-sort ordering rules,algorithm,algorithm} above).
The suffixes are temporarily removed, and the strings are compared
without them, using version sort (see @ref{Version-sort ordering
rules}) without special priority (see @ref{Special priority in GNU
Coreutils version sort}).
@item
If the suffix-less strings are identical, the suffix is restored and
the entire strings are compared.
If the suffix-less strings do not compare equal, this comparison
result is used and the suffixes are effectively ignored.
@item
If the non-suffixed strings differ, the result is returned and the
suffix is effectively ignored.
If the suffix-less strings compare equal, the suffixes are restored
and the entire strings are compared using version sort.
@end enumerate
Examples for rule 1:
@itemize
@item
@code{hello-8.txt}: the suffix is @code{.txt}
@samp{hello-8.txt}: the suffix is @samp{.txt}
@item
@code{hello-8.2.txt}: the suffix is @code{.txt}
(@samp{@code{.2}} is not included because the dot is not followed by a letter)
@samp{hello-8.2.txt}: the suffix is @samp{.txt}
(@samp{.2} is not included because the dot is not followed by a letter)
@item
@code{hello-8.0.12.tar.gz}: the suffix is @code{.tar.gz} (@samp{@code{.0.12}}
@samp{hello-8.0.12.tar.gz}: the suffix is @samp{.tar.gz} (@samp{.0.12}
is not included)
@item
@code{hello-8.2}: no suffix (suffix is an empty string)
@samp{hello-8.2}: no suffix (suffix is an empty string)
@item
@code{hello.foobar65}: the suffix is @code{.foobar65}
@samp{hello.foobar65}: the suffix is @samp{.foobar65}
@item
@code{gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2}: the suffix is
@code{.fc9.tar.bz2} (@code{.7rc2} is not included as it begins with a digit)
@samp{gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2}: the suffix is
@samp{.fc9.tar.bz2} (@samp{.7rc2} is not included as it begins with a digit)
@item
@samp{.autom4te.cfg}: the suffix is the entire string.
@end itemize
Examples for rule 2:
@itemize
@item
Comparing @code{hello-8.txt} to @code{hello-8.2.12.txt}, the
@code{.txt} suffix is temporarily removed from both strings.
Comparing @samp{hello-8.txt} to @samp{hello-8.2.12.txt}, the
@samp{.txt} suffix is temporarily removed from both strings.
@item
Comparing @code{foo-10.3.tar.gz} to @code{foo-10.tar.xz}, the suffixes
@code{.tar.gz} and @code{.tar.xz} are temporarily removed from the
Comparing @samp{foo-10.3.tar.gz} to @samp{foo-10.tar.xz}, the suffixes
@samp{.tar.gz} and @samp{.tar.xz} are temporarily removed from the
strings.
@end itemize
@@ -644,10 +648,10 @@ Example for rule 3:
@itemize
@item
Comparing @code{hello.foobar65} to @code{hello.foobar4}, the suffixes
(@code{.foobar65} and @code{.foobar4}) are temporarily removed. The
remaining strings are identical (@code{hello}). The suffixes are then
restored, and the entire strings are compared (@code{hello.foobar4} comes
Comparing @samp{hello.foobar65} to @samp{hello.foobar4}, the suffixes
(@samp{.foobar65} and @samp{.foobar4}) are temporarily removed. The
remaining strings are identical (@samp{hello}). The suffixes are then
restored, and the entire strings are compared (@samp{hello.foobar4} comes
first).
@end itemize
@@ -655,10 +659,10 @@ Examples for rule 4:
@itemize
@item
When comparing the strings @code{hello-8.2.txt} and @code{hello-8.10.txt}, the
suffixes (@code{.txt}) are temporarily removed. The remaining strings
(@code{hello-8.2} and @code{hello-8.10}) are compared as previously described
(@code{hello-8.2} comes first).
When comparing the strings @samp{hello-8.2.txt} and @samp{hello-8.10.txt}, the
suffixes (@samp{.txt}) are temporarily removed. The remaining strings
(@samp{hello-8.2} and @samp{hello-8.10}) are compared as previously described
(@samp{hello-8.2} comes first).
@slanted{(In this case the suffix removal algorithm
does not have a noticeable effect on the resulting order.)}
@end itemize
@@ -671,15 +675,15 @@ Without the suffix-removal algorithm, the strings will be broken down
to the following parts:
@example
hello- @r{vs} hello- @r{(rule 2, all non-digit characters)}
8 @r{vs} 8 @r{(rule 3, all digit characters)}
hello- @r{vs} hello- @r{(rule 2, all non-digits)}
8 @r{vs} 8 @r{(rule 3, all digits)}
.txt @r{vs} . @r{(rule 2)}
empty @r{vs} 2
empty @r{vs} .txt
@end example
The comparison of the third parts (@samp{@code{.}} vs
@samp{@code{.txt}}) will determine that the shorter string comes first -
The comparison of the third parts (@samp{.} vs
@samp{.txt}) will determine that the shorter string comes first -
resulting in @file{hello-8.2.txt} appearing first.
Indeed this is the order in which Debian's @command{dpkg} compares the strings.
@@ -687,17 +691,17 @@ Indeed this is the order in which Debian's @command{dpkg} compares the strings.
A more natural result is that @file{hello-8.txt} should come before
@file{hello-8.2.txt}, and this is where the suffix-removal comes into play:
The suffixes (@code{.txt}) are removed, and the remaining strings are
The suffixes (@samp{.txt}) are removed, and the remaining strings are
broken down into the following parts:
@example
hello- @r{vs} hello- @r{(rule 2, all non-digit characters)}
8 @r{vs} 8 @r{(rule 3, all digit characters)}
hello- @r{vs} hello- @r{(rule 2, all non-digits)}
8 @r{vs} 8 @r{(rule 3, all digits)}
empty @r{vs} . @r{(rule 2)}
empty @r{vs} 2
@end example
As empty strings sort before non-empty strings, the result is @code{hello-8}
As empty strings sort before non-empty strings, the result is @samp{hello-8}
being first.
A real-world example would be listing files such as:
@@ -714,10 +718,6 @@ because the sorting code is shared between the @command{ls} and @command{sort}
program, the ordering rules are the same.
@node Advanced Topics
@section Advanced Topics
@node Comparing two strings using Debian's algorithm
@subsection Comparing two strings using Debian's algorithm
@@ -730,13 +730,14 @@ following snippet to your shell command-prompt):
@example
compver() @{
dpkg --compare-versions "$1" lt "$2" \
&& printf "%s\n" "$1" "$2" \
|| printf "%s\n" "$2" "$1" ; \
if dpkg --compare-versions "$1" lt "$2"
then printf '%s\n' "$1" "$2"
else printf '%s\n' "$2" "$1"
fi
@}
@end example
Then compare two strings by calling compver:
Then compare two strings by calling @command{compver}:
@example
$ compver 8.49 8.5
@@ -754,7 +755,6 @@ dpkg: warning: version 'foo7a.7z' has bad syntax:
version number does not start with digit
foo7a.7z
foo07.7z
$ compver "3.0/" "3.0.5"
dpkg: warning: version '3.0/' has bad syntax:
invalid character in version number
@@ -763,11 +763,11 @@ dpkg: warning: version '3.0/' has bad syntax:
@end example
To illustrate the different handling of hyphens between Debian and
coreutils' algorithms (see
@ref{Minus/Hyphen and Colon characters}):
Coreutils algorithms (see
@ref{Hyphen-minus and colon}):
@example
$ compver abb ab-cd 2>/dev/null $ printf "abb\nab-cd\n" | sort -V
$ compver abb ab-cd 2>/dev/null $ printf 'abb\nab-cd\n' | sort -V
ab-cd abb
abb ab-cd
@end example
@@ -779,30 +779,32 @@ handling of file extensions}):
$ compver hello-8.txt hello-8.2.txt 2>/dev/null
hello-8.2.txt
hello-8.txt
$ printf "%s\n" hello-8.txt hello-8.2.txt | sort -V
$ printf '%s\n' hello-8.txt hello-8.2.txt | sort -V
hello-8.txt
hello-8.2.txt
@end example
@node Advanced version sort topics
@section Advanced Topics
@node Reporting bugs or incorrect results
@subsection Reporting bugs or incorrect results
If you suspect a bug in GNU coreutils' version sort (i.e., in the
@node Reporting version sort bugs
@subsection Reporting version sort bugs
If you suspect a bug in GNU Coreutils version sort (i.e., in the
output of @samp{ls -v} or @samp{sort -V}), please first check the following:
@enumerate
@item
Is the result consistent with Debian's own ordering (using @command{dpkg}, see
@ref{Comparing two strings using Debian's algorithm}) ? If it is, then this
is not a bug - please do not report it.
@ref{Comparing two strings using Debian's algorithm})? If it is, then this
is not a bug -- please do not report it.
@item
If the result differs from Debian's, is it explained by one of the
sections in @ref{Differences from the official Debian Algorithm}? If it is,
then this is not a bug - please do not report it.
sections in @ref{Differences from Debian version sort}? If it is,
then this is not a bug -- please do not report it.
@item
If you have a question about specific ordering which is not explained
@@ -833,7 +835,7 @@ Natural Sorting variants in
Python's @uref{https://pypi.org/project/natsort/,natsort package}
(includes detailed description of their sorting rules:
@uref{https://natsort.readthedocs.io/en/master/howitworks.html,
natsort - how it works}).
natsort -- how it works}).
@item
Ruby's @uref{https://github.com/github/version_sorter,version_sorter}.
@@ -855,16 +857,16 @@ NodeJS's @uref{https://www.npmjs.com/package/natural-sort,natural-sort package}.
@item
In zsh, the
@uref{http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers,
glob modifier} @code{*(n)} will expand to files in natural sort order.
glob modifier} @samp{*(n)} will expand to files in natural sort order.
@item
When writing @code{C} programs, the GNU libc library (@code{glibc})
When writing C programs, the GNU libc library (@samp{glibc})
provides the
@uref{http://man7.org/linux/man-pages/man3/strverscmp.3.html,
strvercmp(3)} function to compare two strings, and
@uref{http://man7.org/linux/man-pages/man3/versionsort.3.html,versionsort(3)}
function to compare two directory entries (despite the names, they are
not identical to GNU coreutils' version sort ordering).
not identical to GNU Coreutils version sort ordering).
@item
Using Debian's sorting algorithm in:
@@ -882,8 +884,8 @@ deb-version-compare}.
@end itemize
@node Related Source code
@subsection Related Source code
@node Related source code
@subsection Related source code
@itemize
@@ -899,7 +901,7 @@ Debian's code which performs the @code{upstream_version} comparison:
version.c}.
@item
GNULIB code (used by GNU coreutils) which performs the version comparison:
Gnulib code (used by GNU Coreutils) which performs the version comparison:
@uref{https://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/filevercmp.c,
filevercmp.c}.
@end itemize

View File

@@ -1,6 +1,6 @@
/* buffer-lcm.c - compute a good buffer size for dealing with two files
Copyright (C) 2002-2021 Free Software Foundation, Inc.
Copyright (C) 2002-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* Convert string to double in the current locale, falling back on the C locale.
Copyright 2019-2021 Free Software Foundation, Inc.
Copyright 2019-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,2 +1,4 @@
double cl_strtod (char const *, char **restrict);
long double cl_strtold (char const *, char **restrict);
double cl_strtod (char const *, char **restrict)
_GL_ATTRIBUTE_NONNULL ((1));
long double cl_strtold (char const *, char **restrict)
_GL_ATTRIBUTE_NONNULL ((1));

View File

@@ -1,5 +1,5 @@
/* Declare an access pattern hint for files.
Copyright (C) 2010-2021 Free Software Foundation, Inc.
Copyright (C) 2010-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
/* Declare an access pattern hint for files.
Copyright (C) 2010-2021 Free Software Foundation, Inc.
Copyright (C) 2010-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* Invoke open, but return either a desired file descriptor or -1.
Copyright (C) 2005-2021 Free Software Foundation, Inc.
Copyright (C) 2005-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* Invoke open, but return either a desired file descriptor or -1.
Copyright (C) 2005-2021 Free Software Foundation, Inc.
Copyright (C) 2005-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,4 +19,4 @@
#include <sys/types.h>
int fd_reopen (int, char const *, int, mode_t);
int fd_reopen (int, char const *, int, mode_t) _GL_ATTRIBUTE_NONNULL ();

View File

@@ -1,6 +1,6 @@
/* Barebones heap implementation supporting only insert and pop.
Copyright (C) 2010-2021 Free Software Foundation, Inc.
Copyright (C) 2010-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -118,7 +118,7 @@ heapify_down (void **array, size_t count, size_t initial,
{
size_t child = 2 * parent;
if (child < count && compare (array[child], array[child+1]) < 0)
if (child < count && compare (array[child], array[child + 1]) < 0)
child++;
if (compare (array[child], element) <= 0)
@@ -141,9 +141,9 @@ heapify_up (void **array, size_t count,
size_t k = count;
void *new_element = array[k];
while (k != 1 && compare (array[k/2], new_element) <= 0)
while (k != 1 && compare (array[k / 2], new_element) <= 0)
{
array[k] = array[k/2];
array[k] = array[k / 2];
k /= 2;
}

View File

@@ -1,6 +1,6 @@
/* Barebones heap implementation supporting only insert and pop.
Copyright (C) 2010-2021 Free Software Foundation, Inc.
Copyright (C) 2010-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,7 +20,13 @@
#include <stddef.h>
struct heap *heap_alloc (int (*) (void const *, void const *), size_t);
void heap_free (struct heap *);
int heap_insert (struct heap *heap, void *item);
void *heap_remove_top (struct heap *heap);
struct heap;
void heap_free (struct heap *) _GL_ATTRIBUTE_NONNULL ();
struct heap *heap_alloc (int (*) (void const *, void const *), size_t)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (heap_free, 1)
_GL_ATTRIBUTE_RETURNS_NONNULL;
int heap_insert (struct heap *heap, void *item) _GL_ATTRIBUTE_NONNULL ();
void *heap_remove_top (struct heap *heap) _GL_ATTRIBUTE_NONNULL ();

View File

@@ -1,5 +1,5 @@
/* Align/Truncate a string in a given screen width
Copyright (C) 2009-2021 Free Software Foundation, Inc.
Copyright (C) 2009-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
#include <config.h>
#include "mbsalign.h"
#include "minmax.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -28,10 +30,6 @@
#include <wchar.h>
#include <wctype.h>
#ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
/* Replace non printable chars.
Note \t and \n etc. are non printable.
Return 1 if replacement made, 0 otherwise. */
@@ -84,8 +82,8 @@ wc_truncate (wchar_t *wc, size_t width)
is always added to DEST.
A pointer to the terminating NUL is returned. */
static char*
mbs_align_pad (char *dest, const char* dest_end, size_t n_spaces)
static char *
mbs_align_pad (char *dest, char const *dest_end, size_t n_spaces)
{
/* FIXME: Should we pad with "figure space" (\u2007)
if non ascii data present? */

View File

@@ -1,5 +1,5 @@
/* Align/Truncate a string in a given screen width
Copyright (C) 2009-2021 Free Software Foundation, Inc.
Copyright (C) 2009-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,6 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <stddef.h>
#include <stdlib.h>
typedef enum { MBS_ALIGN_LEFT, MBS_ALIGN_RIGHT, MBS_ALIGN_CENTER } mbs_align_t;
@@ -53,7 +54,10 @@ enum {
size_t
mbsalign (char const *src, char *dest, size_t dest_size,
size_t *width, mbs_align_t align, int flags);
size_t *width, mbs_align_t align, int flags)
_GL_ATTRIBUTE_NONNULL ();
char *
ambsalign (char const *src, size_t *width, mbs_align_t align, int flags);
ambsalign (char const *src, size_t *width, mbs_align_t align, int flags)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
_GL_ATTRIBUTE_NONNULL ();

View File

@@ -1,6 +1,6 @@
/* Bob Jenkins's cryptographic random number generators, ISAAC and ISAAC64.
Copyright (C) 1999-2021 Free Software Foundation, Inc.
Copyright (C) 1999-2022 Free Software Foundation, Inc.
Copyright (C) 1997, 1998, 1999 Colin Plumb.
This program is free software: you can redistribute it and/or modify

View File

@@ -1,6 +1,6 @@
/* Bob Jenkins's cryptographic random number generators, ISAAC and ISAAC64.
Copyright (C) 1999-2021 Free Software Foundation, Inc.
Copyright (C) 1999-2022 Free Software Foundation, Inc.
Copyright (C) 1997, 1998, 1999 Colin Plumb.
This program is free software: you can redistribute it and/or modify
@@ -59,7 +59,8 @@ struct isaac_state
isaac_word a, b, c; /* Extra variables */
};
void isaac_seed (struct isaac_state *);
void isaac_refill (struct isaac_state *, isaac_word[ISAAC_WORDS]);
void isaac_seed (struct isaac_state *) _GL_ATTRIBUTE_NONNULL ();
void isaac_refill (struct isaac_state *, isaac_word[ISAAC_WORDS])
_GL_ATTRIBUTE_NONNULL ();
#endif

View File

@@ -1,6 +1,6 @@
/* Generate random integers.
Copyright (C) 2006-2021 Free Software Foundation, Inc.
Copyright (C) 2006-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* Generate random integers.
Copyright (C) 2006-2021 Free Software Foundation, Inc.
Copyright (C) 2006-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -32,11 +32,17 @@ typedef uintmax_t randint;
struct randint_source;
struct randint_source *randint_new (struct randread_source *);
struct randint_source *randint_all_new (char const *, size_t);
void randint_free (struct randint_source *) _GL_ATTRIBUTE_NONNULL ();
int randint_all_free (struct randint_source *) _GL_ATTRIBUTE_NONNULL ();
struct randint_source *randint_new (struct randread_source *)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (randint_free, 1)
_GL_ATTRIBUTE_NONNULL () _GL_ATTRIBUTE_RETURNS_NONNULL;
struct randint_source *randint_all_new (char const *, size_t)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (randint_all_free, 1);
struct randread_source *randint_get_source (struct randint_source const *)
_GL_ATTRIBUTE_PURE;
randint randint_genmax (struct randint_source *, randint genmax);
_GL_ATTRIBUTE_NONNULL () _GL_ATTRIBUTE_PURE;
randint randint_genmax (struct randint_source *, randint genmax)
_GL_ATTRIBUTE_NONNULL ();
/* Consume random data from *S to generate a random number in the range
0 .. CHOICES-1. CHOICES must be nonzero. */
@@ -46,7 +52,4 @@ randint_choose (struct randint_source *s, randint choices)
return randint_genmax (s, choices - 1);
}
void randint_free (struct randint_source *);
int randint_all_free (struct randint_source *);
#endif

View File

@@ -1,6 +1,6 @@
/* Generate random permutations.
Copyright (C) 2006-2021 Free Software Foundation, Inc.
Copyright (C) 2006-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <stdlib.h>
#include "attribute.h"
#include "count-leading-zeros.h"
#include "hash.h"
#include "verify.h"
@@ -32,7 +33,7 @@
/* Return the floor of the log base 2 of N. If N is zero, return -1. */
static int _GL_ATTRIBUTE_CONST
ATTRIBUTE_CONST static int
floor_lg (size_t n)
{
verify (SIZE_WIDTH <= ULLONG_WIDTH);
@@ -117,7 +118,7 @@ sparse_new (size_t size_hint)
index I in array V. */
static void
sparse_swap (sparse_map *sv, size_t* v, size_t i, size_t j)
sparse_swap (sparse_map *sv, size_t *v, size_t i, size_t j)
{
struct sparse_ent_ *v1 = hash_remove (sv, &(struct sparse_ent_) {i,0});
struct sparse_ent_ *v2 = hash_remove (sv, &(struct sparse_ent_) {j,0});

View File

@@ -1,4 +1,6 @@
#include "randint.h"
#include <stddef.h>
#include <stdlib.h>
size_t randperm_bound (size_t, size_t) _GL_ATTRIBUTE_CONST;
size_t *randperm_new (struct randint_source *, size_t, size_t);
size_t *randperm_new (struct randint_source *, size_t, size_t)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;

View File

@@ -1,6 +1,6 @@
/* Generate buffers of random data.
Copyright (C) 2006-2021 Free Software Foundation, Inc.
Copyright (C) 2006-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,25 +40,12 @@
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "minmax.h"
#include "rand-isaac.h"
#include "stdio-safer.h"
#include "unlocked-io.h"
#include "xalloc.h"
#ifndef __attribute__
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
# define __attribute__(x) /* empty */
# endif
#endif
#ifndef ATTRIBUTE_NORETURN
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
#endif
#ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#if _STRING_ARCH_unaligned || _STRING_INLINE_unaligned
# define ALIGNED_POINTER(ptr, type) true
#else
@@ -115,7 +102,7 @@ struct randread_source
/* The default error handler. */
static void ATTRIBUTE_NORETURN
static void
randread_error (void const *file_name)
{
if (file_name)
@@ -156,6 +143,17 @@ get_nonce (void *buffer, size_t bufsize)
return true;
}
/* Body of randread_free, broken out to pacify gcc -Wmismatched-dealloc. */
static int
randread_free_body (struct randread_source *s)
{
FILE *source = s->source;
explicit_bzero (s, sizeof *s);
free (s);
return source ? fclose (source) : 0;
}
/* Create and initialize a random data source from NAME, or use a
reasonable default source if NAME is null. BYTES_BOUND is an upper
bound on the number of bytes that will be needed. If zero, it is a
@@ -192,7 +190,7 @@ randread_new (char const *name, size_t bytes_bound)
MIN (sizeof s->buf.isaac.state.m, bytes_bound)))
{
int e = errno;
randread_free (s);
randread_free_body (s);
errno = e;
return NULL;
}
@@ -313,8 +311,5 @@ randread (struct randread_source *s, void *buf, size_t size)
int
randread_free (struct randread_source *s)
{
FILE *source = s->source;
explicit_bzero (s, sizeof *s);
free (s);
return (source ? fclose (source) : 0);
return randread_free_body (s);
}

View File

@@ -1,6 +1,6 @@
/* Generate buffers of random data.
Copyright (C) 2006-2021 Free Software Foundation, Inc.
Copyright (C) 2006-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,10 +24,14 @@
struct randread_source;
struct randread_source *randread_new (char const *, size_t);
void randread (struct randread_source *, void *, size_t);
void randread_set_handler (struct randread_source *, void (*) (void const *));
void randread_set_handler_arg (struct randread_source *, void const *);
int randread_free (struct randread_source *);
int randread_free (struct randread_source *) _GL_ATTRIBUTE_NONNULL ();
struct randread_source *randread_new (char const *, size_t)
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (randread_free, 1);
void randread (struct randread_source *, void *, size_t)
_GL_ATTRIBUTE_NONNULL ();
void randread_set_handler (struct randread_source *, void (*) (void const *))
_GL_ATTRIBUTE_NONNULL ();
void randread_set_handler_arg (struct randread_source *, void const *)
_GL_ATTRIBUTE_NONNULL ((1));
#endif

View File

@@ -1,5 +1,5 @@
/* root-dev-ino.c -- get the device and inode numbers for '/'.
Copyright (C) 2003-2021 Free Software Foundation, Inc.
Copyright (C) 2003-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* Root device and inode number checking.
Copyright (C) 2003-2021 Free Software Foundation, Inc.
Copyright (C) 2003-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@
# include "same-inode.h"
struct dev_ino *
get_root_dev_ino (struct dev_ino *root_d_i);
get_root_dev_ino (struct dev_ino *root_d_i) _GL_ATTRIBUTE_NONNULL ();
/* These macros are common to the programs that support the
--preserve-root and --no-preserve-root options. */

View File

@@ -1,5 +1,5 @@
/* Include and determine availability of smack routines
Copyright (C) 2013-2021 Free Software Foundation, Inc.
Copyright (C) 2013-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* Compare integer strings.
Copyright (C) 2005-2021 Free Software Foundation, Inc.
Copyright (C) 2005-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,6 +21,8 @@
#include "strnumcmp-in.h"
#include <limits.h>
/* Compare strings A and B as integers without explicitly converting
them to machine numbers, to avoid overflow problems and perhaps
improve performance. */
@@ -28,5 +30,5 @@
int
strintcmp (char const *a, char const *b)
{
return numcompare (a, b, -1, -1);
return numcompare (a, b, CHAR_MAX + 1, CHAR_MAX + 1);
}

View File

@@ -1,6 +1,6 @@
/* Compare numeric strings. This is an internal include file.
Copyright (C) 1988-2021 Free Software Foundation, Inc.
Copyright (C) 1988-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -106,8 +106,8 @@ fraccompare (char const *a, char const *b, char decimal_point)
/* Compare strings A and B as numbers without explicitly converting
them to machine numbers, to avoid overflow problems and perhaps
improve performance. DECIMAL_POINT is the decimal point and
THOUSANDS_SEP the thousands separator. A DECIMAL_POINT of -1
causes comparisons to act as if there is no decimal point
THOUSANDS_SEP the thousands separator. A DECIMAL_POINT outside
'char' range causes comparisons to act as if there is no decimal point
character, and likewise for THOUSANDS_SEP. */
static inline int _GL_ATTRIBUTE_PURE

View File

@@ -1,6 +1,6 @@
/* Compare numeric strings.
Copyright (C) 2005-2021 Free Software Foundation, Inc.
Copyright (C) 2005-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
/* Externally-visible name for numcompare. */
int _GL_ATTRIBUTE_PURE
int
strnumcmp (char const *a, char const *b,
int decimal_point, int thousands_sep)
{

View File

@@ -1,2 +1,4 @@
int strintcmp (char const *, char const *) _GL_ATTRIBUTE_PURE;
int strnumcmp (char const *, char const *, int, int);
int strintcmp (char const *, char const *)
_GL_ATTRIBUTE_NONNULL () _GL_ATTRIBUTE_PURE;
int strnumcmp (char const *, char const *, int, int)
_GL_ATTRIBUTE_NONNULL () _GL_ATTRIBUTE_PURE;

118
gl/lib/targetdir.c Normal file
View File

@@ -0,0 +1,118 @@
/* Target directory operands for coreutils
Copyright 2004-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define TARGETDIR_INLINE _GL_EXTERN_INLINE
#include <targetdir.h>
#include <attribute.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef O_PATH
enum { O_PATHSEARCH = O_PATH };
#else
enum { O_PATHSEARCH = O_SEARCH };
#endif
/* Must F designate the working directory? */
ATTRIBUTE_PURE static bool
must_be_working_directory (char const *f)
{
/* Return true for ".", "./.", ".///./", etc. */
while (*f++ == '.')
{
if (*f != '/')
return !*f;
while (*++f == '/')
continue;
if (!*f)
return true;
}
return false;
}
/* Return a file descriptor open to FILE, for use in openat.
As an optimization, return AT_FDCWD if FILE must be the working directory.
As a side effect, possibly set *ST to the file's status.
Fail and set errno if FILE is not a directory.
On failure return -2 if AT_FDCWD is -1, -1 otherwise. */
int
target_directory_operand (char const *file, struct stat *st)
{
if (must_be_working_directory (file))
return AT_FDCWD;
int fd = -1;
int try_to_open = 1;
int stat_result;
/* On old systems without O_DIRECTORY, like Solaris 10, check with
stat first lest we try to open a fifo for example and hang. */
if (!O_DIRECTORY)
{
stat_result = stat (file, st);
if (stat_result == 0)
{
try_to_open = S_ISDIR (st->st_mode);
errno = ENOTDIR;
}
else
{
/* On EOVERFLOW failure, give up on checking, as there is no
easy way to check. This should be rare. */
try_to_open = errno == EOVERFLOW;
}
}
if (try_to_open)
{
fd = open (file, O_PATHSEARCH | O_DIRECTORY);
/* On platforms lacking O_PATH, using O_SEARCH | O_DIRECTORY to
open an overly-protected non-directory can fail with either
EACCES or ENOTDIR. Prefer ENOTDIR as it makes for better
diagnostics. */
if (O_PATHSEARCH == O_SEARCH && fd < 0 && errno == EACCES)
errno = (((O_DIRECTORY ? stat (file, st) : stat_result) == 0
&& !S_ISDIR (st->st_mode))
? ENOTDIR : EACCES);
}
if (!O_DIRECTORY && 0 <= fd)
{
/* On old systems like Solaris 10 double check type,
to ensure we've opened a directory. */
int err;
if (fstat (fd, st) == 0
? !S_ISDIR (st->st_mode) && (err = ENOTDIR, true)
: (err = errno) != EOVERFLOW)
{
close (fd);
errno = err;
fd = -1;
}
}
return fd - (AT_FDCWD == -1 && fd < 0);
}

44
gl/lib/targetdir.h Normal file
View File

@@ -0,0 +1,44 @@
/* Target directory operands for coreutils
Copyright 2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <fcntl.h>
#include <stdbool.h>
#include <sys/stat.h>
#ifndef _GL_INLINE_HEADER_BEGIN
# error "Please include config.h first."
#endif
_GL_INLINE_HEADER_BEGIN
#ifndef TARGETDIR_INLINE
# define TARGETDIR_INLINE _GL_INLINE
#endif
/* Return a file descriptor open to FILE, for use in openat.
As an optimization, return AT_FDCWD if FILE must be the working directory.
As a side effect, possibly set *ST to the file's status.
Fail and set errno if FILE is not a directory.
On failure return -2 if AT_FDCWD is -1, -1 otherwise. */
extern int target_directory_operand (char const *file, struct stat *st);
/* Return true if FD represents success for target_directory_operand. */
TARGETDIR_INLINE _GL_ATTRIBUTE_PURE bool
target_dirfd_valid (int fd)
{
return fd != -1 - (AT_FDCWD == -1);
}
_GL_INLINE_HEADER_END

View File

@@ -1,6 +1,6 @@
/* Convert decimal strings with bounds checking and exit on error.
Copyright (C) 2014-2021 Free Software Foundation, Inc.
Copyright (C) 2014-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,10 +21,12 @@
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include "error.h"
#include "quote.h"
#include "verify.h"
#include "xstrtol.h"
/* Parse numeric string N_STR of base BASE, and return the value.
@@ -48,10 +50,10 @@ __xnumtoint (char const *n_str, int base, __xdectoint_t min, __xdectoint_t max,
s_err = LONGINT_OVERFLOW;
/* Use have the INT range as a heuristic to distinguish
type overflow rather than other min/max limits. */
if (tnum > INT_MAX/2)
if (tnum > INT_MAX / 2)
errno = EOVERFLOW;
#if __xdectoint_signed
else if (tnum < INT_MIN/2)
else if (tnum < INT_MIN / 2)
errno = EOVERFLOW;
#endif
else
@@ -68,6 +70,7 @@ __xnumtoint (char const *n_str, int base, __xdectoint_t min, __xdectoint_t max,
/* EINVAL error message is redundant in this context. */
error (err_exit ? err_exit : EXIT_FAILURE, errno == EINVAL ? 0 : errno,
"%s: %s", err, quote (n_str));
assume (false);
}
return tnum;

View File

@@ -1,6 +1,6 @@
/* Convert decimal strings with bounds checking and exit on error.
Copyright (C) 2014-2021 Free Software Foundation, Inc.
Copyright (C) 2014-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -22,10 +22,12 @@
# define _DECLARE_XDECTOINT(name, type) \
type name (char const *n_str, type min, type max, \
char const *suffixes, char const *err, int err_exit);
char const *suffixes, char const *err, int err_exit) \
_GL_ATTRIBUTE_NONNULL ((1, 5));
# define _DECLARE_XNUMTOINT(name, type) \
type name (char const *n_str, int base, type min, type max, \
char const *suffixes, char const *err, int err_exit);
char const *suffixes, char const *err, int err_exit) \
_GL_ATTRIBUTE_NONNULL ((1, 6));
_DECLARE_XDECTOINT (xdectoimax, intmax_t)
_DECLARE_XDECTOINT (xdectoumax, uintmax_t)

View File

@@ -1,6 +1,6 @@
/* xfts.c -- a wrapper for fts_open
Copyright (C) 2003-2021 Free Software Foundation, Inc.
Copyright (C) 2003-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -3,8 +3,10 @@
FTS *
xfts_open (char * const *, int options,
int (*) (const FTSENT **, const FTSENT **));
int (*) (const FTSENT **, const FTSENT **))
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (fts_close, 1)
_GL_ATTRIBUTE_NONNULL ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
bool
cycle_warning_required (FTS const *fts, FTSENT const *ent)
_GL_ATTRIBUTE_PURE;
_GL_ATTRIBUTE_NONNULL () _GL_ATTRIBUTE_PURE;

View File

@@ -6,6 +6,7 @@ lib/mbsalign.c
lib/mbsalign.h
Depends-on:
minmax
wchar
wctype
wcwidth

View File

@@ -14,6 +14,7 @@ inline
fopen-safer
getrandom
quote
minmax
stdalign
stdbool
stdint

25
gl/modules/targetdir Normal file
View File

@@ -0,0 +1,25 @@
Description:
Target directory operands
Files:
lib/targetdir.c
lib/targetdir.h
Depends-on:
attribute
fcntl-h
stdbool
configure.ac:
Makefile.am:
lib_SOURCES += targetdir.c targetdir.h
Include:
"targetdir.h"
License:
GPL
Maintainer:
all

View File

@@ -11,6 +11,8 @@ Depends-on:
error
errno
quote
stdbool
verify
xstrtoimax
xstrtoumax

View File

@@ -1,5 +1,5 @@
/* Test that fadvise works as advertised.
Copyright (C) 2010-2021 Free Software Foundation, Inc.
Copyright (C) 2010-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
/* Test that mbsalign works as advertised.
Copyright (C) 2010-2021 Free Software Foundation, Inc.
Copyright (C) 2010-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* Test the ISAAC or ISAAC64 pseudorandom number generator.
Copyright (C) 2010-2021 Free Software Foundation, Inc.
Copyright (C) 2010-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

2
gnulib

Submodule gnulib updated: 9aca7b6733...58c597d13b

View File

@@ -1,6 +1,6 @@
# This file is sourced by init.sh, *before* its initialization.
# Copyright (C) 2010-2021 Free Software Foundation, Inc.
# Copyright (C) 2010-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -384,6 +384,7 @@ rwx_to_mode_()
# with a space.
stty_reversible_init_()
{
require_perl_
# Pad start with one space for the first option to match in query function.
stty_reversible_=' '$(perl -lne '/^ *{"(.*?)",.*\bREV\b/ and print $1' \
"$abs_top_srcdir"/src/stty.c | tr '\n' ' ')
@@ -540,7 +541,14 @@ seek_data_capable_()
warn_ 'seek_data_capable_: python missing: assuming not SEEK_DATA capable'
return 1
fi
$PYTHON_ "$abs_srcdir"/tests/seek-data-capable "$@"
# Use timeout if available to skip cases where SEEK_DATA takes a long time.
# We saw FreeBSD 9.1 take 35s to return from SEEK_DATA for a 1TiB empty file.
# Note lseek() is uninterruptible on FreeBSD 9.1, but it does eventually
# return, and the timeout will ensure a failure return from the process.
timeout --version >/dev/null && TIMEOUT_='timeout 10'
$TIMEOUT_ $PYTHON_ "$abs_srcdir"/tests/seek-data-capable "$@"
}
# Skip the current test if "." lacks d_type support.

View File

@@ -1,7 +1,7 @@
#!/bin/sh
# Exercise chdir-long's sample main program.
# Copyright (C) 2005-2021 Free Software Foundation, Inc.
# Copyright (C) 2005-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
# boottime.m4 serial 4
# Determine whether this system has infrastructure for obtaining the boot time.
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
# Copyright (C) 1996-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
#serial 27
# Check declarations for this package.
dnl Copyright (C) 1997-2021 Free Software Foundation, Inc.
dnl Copyright (C) 1997-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,

View File

@@ -1,5 +1,5 @@
#serial 2
dnl Copyright (C) 2007-2021 Free Software Foundation, Inc.
dnl Copyright (C) 2007-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

View File

@@ -2,7 +2,7 @@
dnl Misc type-related macros for coreutils.
# Copyright (C) 1998-2021 Free Software Foundation, Inc.
# Copyright (C) 1998-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -7,7 +7,7 @@ m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl
# directory of the coreutils package.
# Copyright (C) 1998-2021 Free Software Foundation, Inc.
# Copyright (C) 1998-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
# stat-prog.m4 serial 7
# Record the prerequisites of src/stat.c from the coreutils package.
# Copyright (C) 2002-2021 Free Software Foundation, Inc.
# Copyright (C) 2002-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
# xattr.m4 - check for Extended Attributes (Linux)
# serial 4
# Copyright (C) 2003-2021 Free Software Foundation, Inc.
# Copyright (C) 2003-2022 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 2018-2021 Free Software Foundation, Inc.
'\" Copyright (C) 2018-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2021 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2021 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2021 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2021 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.

View File

@@ -2,3 +2,5 @@
echo \- display a line of text
[DESCRIPTION]
.\" Add any additional description here
[SEE ALSO]
printf(1)

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2021 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
@@ -54,7 +54,7 @@ sh \-c 'env \-\-default-signal=PIPE seq inf | head \-n1'
.PP
[NOTES]
POSIX's exec(2) pages says:
POSIX's exec(3p) pages says:
.RS
"many existing applications wrongly assume that they start with certain
signals set to the default action and/or unblocked.... Therefore, it is best

View File

@@ -78,6 +78,7 @@ Usage: %s [OPTION]... EXECUTABLE
-p, --info-page=TEXT name of Texinfo manual
-N, --no-info suppress pointer to Texinfo manual
-l, --libtool exclude the `lt-' from the program name
-b, --bold-refs apply bold style to references
--help print this help, then exit
--version print version number, then exit
@@ -99,7 +100,7 @@ my $help_option = '--help';
my $version_option = '--version';
my $discard_stderr = 1;
my ($opt_name, @opt_include, $opt_output, $opt_info, $opt_no_info, $opt_libtool,
$version_text);
$opt_bold_refs, $version_text);
my %opt_def = (
'n|name=s' => \$opt_name,
@@ -113,6 +114,7 @@ my %opt_def = (
'p|info-page=s' => \$opt_info,
'N|no-info' => \$opt_no_info,
'l|libtool' => \$opt_libtool,
'b|bold-refs' => \$opt_bold_refs,
'help' => sub { print $help_info; exit },
'version' => sub { print $version_info; exit },
'h|help-option=s' => \$help_option,
@@ -714,6 +716,13 @@ for my $sect (@pre, (grep !$filter{$_}, @sections), @post)
for ($include{$sect})
{
# Add bold style around referenced pages.
if ($opt_bold_refs)
{
# This will ignore entries already marked up (with \)
s/(^|\s|,)([\[\w\x83]+)\(([1-9][[:lower:]]?)\)/$1\\fB$2\\fP($3)/g;
}
# Replace leading dot, apostrophe, backslash and hyphen
# tokens.
s/\x80/\\&./g;

View File

@@ -1,7 +1,7 @@
# Make coreutils man pages. -*-Makefile-*-
# This is included by the top-level Makefile.am.
# Copyright (C) 2002-2021 Free Software Foundation, Inc.
# Copyright (C) 2002-2022 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -24,7 +24,10 @@ run_help2man = $(SHELL) $(srcdir)/man/dummy-man
else
## Graceful degradation for systems lacking perl.
if HAVE_PERL
run_help2man = $(PERL) -- $(srcdir)/man/help2man
if BOLD_MAN_REFS
help2man_OPTS=--bold-refs
endif
run_help2man = $(PERL) -- $(srcdir)/man/help2man $(help2man_OPTS)
else
run_help2man = $(SHELL) $(srcdir)/man/dummy-man
endif

View File

@@ -2,3 +2,5 @@
ls \- list directory contents
[DESCRIPTION]
.\" Add any additional description here
[SEE ALSO]
dircolors(1)

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2021 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 2009-2021 Free Software Foundation, Inc.
'\" Copyright (C) 2009-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.

View File

@@ -1,3 +1,8 @@
'\" Copyright (C) 1998-2022 Free Software Foundation, Inc.
'\"
'\" This is free software. You may redistribute copies of it under the terms
'\" of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
'\" There is NO WARRANTY, to the extent permitted by law.
[NAME]
test \- check file types and compare values
[SYNOPSIS]
@@ -17,3 +22,5 @@ test \- check file types and compare values
.I OPTION
[DESCRIPTION]
.\" Add any additional description here
[SEE ALSO]
access(2)

View File

@@ -2,3 +2,12 @@
tr \- translate or delete characters
[DESCRIPTION]
.\" Add any additional description here
[BUGS]
.PP
Full support is available only for safe single-byte locales,
in which every possible input byte represents a single character.
The C locale is safe in GNU systems, so you can avoid this issue
in the shell by running
.B "LC_ALL=C tr"
instead of plain
.BR tr .

View File

@@ -1,5 +1,5 @@
# List of files which contain translatable strings.
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
# Copyright (C) 1996-2022 Free Software Foundation, Inc.
# These are nominally temporary...
lib/argmatch.c

View File

@@ -164,7 +164,7 @@ By adding the directory to your $PATH, older versions can be easily used:
========================================================================
Copyright (C) 2019-2021 Free Software Foundation, Inc.
Copyright (C) 2019-2022 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or

View File

@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (C) 2019-2021 Free Software Foundation, Inc.
# Copyright (C) 2019-2022 Free Software Foundation, Inc.
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright

View File

@@ -14,7 +14,7 @@ $editor = "vi" if $? != 0 or $editor =~ /^\s*\z/;
# Keywords allowed before the colon on the first line of a commit message:
# program names and a few general category names.
my @valid = qw(
arch b2sum base32 base64 basenc nbasename cat chcon chgrp chmod chown
arch b2sum base32 base64 basenc basename cat chcon chgrp chmod chown
chroot cksum comm cp csplit cut date dd df dir dircolors dirname du echo
env expand expr factor false fmt fold groups head hostid hostname id
install join kill link ln logname ls md5sum mkdir mkfifo mknod mktemp
@@ -87,7 +87,7 @@ sub check_msg($$)
my ($log_file, $line_ref) = @_;
local *LOG;
open LOG, '<', $log_file
open LOG, '<:utf8', $log_file
or return "failed to open for reading: $!";
@$line_ref = <LOG>;
close LOG;
@@ -117,10 +117,12 @@ sub check_msg($$)
and return 'second line must be empty';
# Limit line length to allow for the ChangeLog's leading TAB.
my $max_len = 72;
foreach my $line (@line)
{
72 < length $line && $line =~ /^[^#]/
and return 'line longer than 72';
my $len = length $line;
$max_len < $len && $line =~ /^[^#]/
and return "line length ($len) greater than than max: $max_len";
}
my $buf = join ("\n", @line) . "\n";
@@ -149,6 +151,7 @@ sub check_msg($$)
$err eq ''
and last;
$err = "$ME: $err\n";
-t STDOUT or die $err;
warn $err;
# Insert the diagnostic as a comment on the first line of $log_file.
rewrite $log_file, $err, \@line;

View File

@@ -1,5 +1,5 @@
/* basename -- strip directory and suffix from file names
Copyright (C) 1990-2021 Free Software Foundation, Inc.
Copyright (C) 1990-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
/* Base64, base32, and similar encoding/decoding strings or files.
Copyright (C) 2004-2021 Free Software Foundation, Inc.
Copyright (C) 2004-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -175,13 +175,13 @@ from any other non-alphabet bytes in the encoded stream.\n"),
exit (status);
}
#define ENC_BLOCKSIZE (1024*3*10)
#define ENC_BLOCKSIZE (1024 * 3 * 10)
#if BASE_TYPE == 32
# define BASE_LENGTH BASE32_LENGTH
/* Note that increasing this may decrease performance if --ignore-garbage
is used, because of the memmove operation below. */
# define DEC_BLOCKSIZE (1024*5)
# define DEC_BLOCKSIZE (1024 * 5)
/* Ensure that BLOCKSIZE is a multiple of 5 and 8. */
verify (ENC_BLOCKSIZE % 40 == 0); /* So padding chars only on last block. */
@@ -196,7 +196,7 @@ verify (DEC_BLOCKSIZE % 40 == 0); /* So complete encoded blocks are used. */
# define BASE_LENGTH BASE64_LENGTH
/* Note that increasing this may decrease performance if --ignore-garbage
is used, because of the memmove operation below. */
# define DEC_BLOCKSIZE (1024*3)
# define DEC_BLOCKSIZE (1024 * 3)
/* Ensure that BLOCKSIZE is a multiple of 3 and 4. */
verify (ENC_BLOCKSIZE % 12 == 0); /* So padding chars only on last block. */
@@ -310,7 +310,7 @@ base64url_encode (char const *restrict in, idx_t inlen,
{
base64_encode (in, inlen, out, outlen);
/* translate 62nd and 63rd characters */
char* p = out;
char *p = out;
while (outlen--)
{
if (*p == '+')
@@ -346,7 +346,7 @@ base64url_decode_ctx_wrapper (struct base_decode_context *ctx,
/* translate 62nd and 63rd characters */
idx_t i = inlen;
char* p = ctx->inbuf;
char *p = ctx->inbuf;
while (i--)
{
if (*p == '+' || *p == '/')
@@ -395,7 +395,7 @@ base32_decode_ctx_wrapper (struct base_decode_context *ctx,
/* ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
to
0123456789ABCDEFGHIJKLMNOPQRSTUV */
static const char base32_norm_to_hex[32+9] = {
static const char base32_norm_to_hex[32 + 9] = {
/*0x32, 0x33, 0x34, 0x35, 0x36, 0x37, */
'Q', 'R', 'S', 'T', 'U', 'V',
@@ -417,7 +417,7 @@ static const char base32_norm_to_hex[32+9] = {
/* 0123456789ABCDEFGHIJKLMNOPQRSTUV
to
ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 */
static const char base32_hex_to_norm[32+9] = {
static const char base32_hex_to_norm[32 + 9] = {
/* from: 0x30 .. 0x39 ('0' to '9') */
/* to:*/ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
@@ -581,7 +581,7 @@ static int
z85_length (int len)
{
/* Z85 does not allow padding, so no need to round to highest integer. */
int outlen = (len*5)/4;
int outlen = (len * 5) / 4;
return outlen;
}
@@ -949,8 +949,22 @@ wrap_write (char const *buffer, idx_t len,
}
}
static void
do_encode (FILE *in, FILE *out, idx_t wrap_column)
static _Noreturn void
finish_and_exit (FILE *in, char const *infile)
{
if (fclose (in) != 0)
{
if (STREQ (infile, "-"))
die (EXIT_FAILURE, errno, _("closing standard input"));
else
die (EXIT_FAILURE, errno, "%s", quotef (infile));
}
exit (EXIT_SUCCESS);
}
static _Noreturn void
do_encode (FILE *in, char const *infile, FILE *out, idx_t wrap_column)
{
idx_t current_column = 0;
char *inbuf, *outbuf;
@@ -990,12 +1004,11 @@ do_encode (FILE *in, FILE *out, idx_t wrap_column)
if (ferror (in))
die (EXIT_FAILURE, errno, _("read error"));
IF_LINT (free (inbuf));
IF_LINT (free (outbuf));
finish_and_exit (in, infile);
}
static void
do_decode (FILE *in, FILE *out, bool ignore_garbage)
static _Noreturn void
do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
{
char *inbuf, *outbuf;
idx_t sum;
@@ -1057,11 +1070,7 @@ do_decode (FILE *in, FILE *out, bool ignore_garbage)
}
while (!feof (in));
#if BASE_TYPE == 42
IF_LINT (free (ctx.inbuf));
#endif
IF_LINT (free (inbuf));
IF_LINT (free (outbuf));
finish_and_exit (in, infile);
}
int
@@ -1209,7 +1218,7 @@ main (int argc, char **argv)
if (argc - optind > 1)
{
error (0, 0, _("extra operand %s"), quote (argv[optind+1]));
error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
@@ -1233,17 +1242,7 @@ main (int argc, char **argv)
fadvise (input_fh, FADVISE_SEQUENTIAL);
if (decode)
do_decode (input_fh, stdout, ignore_garbage);
do_decode (input_fh, infile, stdout, ignore_garbage);
else
do_encode (input_fh, stdout, wrap_column);
if (fclose (input_fh) == EOF)
{
if (STREQ (infile, "-"))
die (EXIT_FAILURE, errno, _("closing standard input"));
else
die (EXIT_FAILURE, errno, "%s", quotef (infile));
}
return EXIT_SUCCESS;
do_encode (input_fh, infile, stdout, wrap_column);
}

View File

@@ -13,7 +13,8 @@
https://blake2.net.
*/
int blake2b_stream( FILE *stream, void *resstream, size_t outbytes );
int blake2b_stream (FILE *stream, void *resstream, size_t outbytes)
_GL_ATTRIBUTE_NONNULL ((1));
typedef int ( *blake2fn )( FILE *, void *, size_t );
#define BLAKE2S_OUTBYTES 32
#define BLAKE2B_OUTBYTES 64

View File

@@ -18,18 +18,12 @@
#include <stddef.h>
#include <stdint.h>
#ifdef __has_attribute
# if __has_attribute (packed)
# define BLAKE2_PACKED(x) x __attribute__ ((packed))
# endif
#endif
#if !defined BLAKE2_PACKED && defined _MSC_VER
/* Pack a structure if possible. This might save space, and is not
needed for correctness. */
#ifdef _MSC_VER
# define BLAKE2_PACKED(x) __pragma (pack (push, 1)) x __pragma (pack (pop))
#endif
#ifndef BLAKE2_PACKED
/* This should be good enough on other platforms.
If it's not good on yours, please file a bug report. */
# define BLAKE2_PACKED(x) x
#else
# define BLAKE2_PACKED(x) x _GL_ATTRIBUTE_PACKED
#endif
#if defined(__cplusplus)
@@ -145,8 +139,8 @@ extern "C" {
/* Padded structs result in a compile-time error */
enum {
BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES),
BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES)
BLAKE2_DUMMY_1 = 1 / (sizeof (blake2s_param) == BLAKE2S_OUTBYTES),
BLAKE2_DUMMY_2 = 1 / (sizeof (blake2b_param) == BLAKE2B_OUTBYTES)
};
/* Streaming API */
@@ -158,7 +152,8 @@ extern "C" {
int blake2b_init( blake2b_state *S, size_t outlen );
int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
int blake2b_init_param (blake2b_state *S, const blake2b_param *P)
_GL_ATTRIBUTE_NONNULL ();
int blake2b_update( blake2b_state *S, const void *in, size_t inlen );
int blake2b_final( blake2b_state *S, void *out, size_t outlen );

View File

@@ -156,11 +156,11 @@ int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t k
#define G(r,i,a,b,c,d) \
do { \
a = a + b + m[blake2b_sigma[r][2*i+0]]; \
a = a + b + m[blake2b_sigma[r][2 * i + 0]]; \
d = rotr64(d ^ a, 32); \
c = c + d; \
b = rotr64(b ^ c, 24); \
a = a + b + m[blake2b_sigma[r][2*i+1]]; \
a = a + b + m[blake2b_sigma[r][2 * i + 1]]; \
d = rotr64(d ^ a, 16); \
c = c + d; \
b = rotr64(b ^ c, 63); \

229
src/cat.c
View File

@@ -1,5 +1,5 @@
/* cat -- concatenate files and print on the standard output.
Copyright (C) 1988-2021 Free Software Foundation, Inc.
Copyright (C) 1988-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,6 +33,8 @@
#include <sys/ioctl.h>
#include "system.h"
#include "alignalloc.h"
#include "idx.h"
#include "ioblksize.h"
#include "die.h"
#include "error.h"
@@ -140,6 +142,7 @@ next_line_num (void)
*endp-- = '0';
}
while (endp >= line_num_start);
if (line_num_start > line_buf)
*--line_num_start = '1';
else
@@ -148,28 +151,20 @@ next_line_num (void)
line_num_print--;
}
/* Plain cat. Copies the file behind 'input_desc' to STDOUT_FILENO.
/* Plain cat. Copy the file behind 'input_desc' to STDOUT_FILENO.
BUF (of size BUFSIZE) is the I/O buffer, used by reads and writes.
Return true if successful. */
static bool
simple_cat (
/* Pointer to the buffer, used by reads and writes. */
char *buf,
/* Number of characters preferably read or written by each read and write
call. */
size_t bufsize)
simple_cat (char *buf, idx_t bufsize)
{
/* Actual number of characters read, and therefore written. */
size_t n_read;
/* Loop until the end of the file. */
while (true)
{
/* Read a block of input. */
n_read = safe_read (input_desc, buf, bufsize);
size_t n_read = safe_read (input_desc, buf, bufsize);
if (n_read == SAFE_READ_ERROR)
{
error (0, errno, "%s", quotef (infile));
@@ -183,12 +178,8 @@ simple_cat (
/* Write this block out. */
{
/* The following is ok, since we know that 0 < n_read. */
size_t n = n_read;
if (full_write (STDOUT_FILENO, buf, n) != n)
die (EXIT_FAILURE, errno, _("write error"));
}
if (full_write (STDOUT_FILENO, buf, n_read) != n_read)
die (EXIT_FAILURE, errno, _("write error"));
}
}
@@ -199,7 +190,7 @@ simple_cat (
static inline void
write_pending (char *outbuf, char **bpout)
{
size_t n_write = *bpout - outbuf;
idx_t n_write = *bpout - outbuf;
if (0 < n_write)
{
if (full_write (STDOUT_FILENO, outbuf, n_write) != n_write)
@@ -208,7 +199,12 @@ write_pending (char *outbuf, char **bpout)
}
}
/* Cat the file behind INPUT_DESC to the file behind OUTPUT_DESC.
/* Copy the file behind 'input_desc' to STDOUT_FILENO.
Use INBUF and read INSIZE with each call,
and OUTBUF and write OUTSIZE with each call.
(The buffers are a bit larger than the I/O sizes.)
The remaining boolean args say what 'cat' options to use.
Return true if successful.
Called if any option more than -u was specified.
@@ -216,43 +212,13 @@ write_pending (char *outbuf, char **bpout)
an explicit test for buffer end unnecessary. */
static bool
cat (
/* Pointer to the beginning of the input buffer. */
char *inbuf,
/* Number of characters read in each read call. */
size_t insize,
/* Pointer to the beginning of the output buffer. */
char *outbuf,
/* Number of characters written by each write call. */
size_t outsize,
/* Variables that have values according to the specified options. */
bool show_nonprinting,
bool show_tabs,
bool number,
bool number_nonblank,
bool show_ends,
bool squeeze_blank)
cat (char *inbuf, idx_t insize, char *outbuf, idx_t outsize,
bool show_nonprinting, bool show_tabs, bool number, bool number_nonblank,
bool show_ends, bool squeeze_blank)
{
/* Last character read from the input buffer. */
unsigned char ch;
/* Pointer to the next character in the input buffer. */
char *bpin;
/* Pointer to the first non-valid byte in the input buffer, i.e., the
current end of the buffer. */
char *eob;
/* Pointer to the position where the next character shall be written. */
char *bpout;
/* Number of characters read by the last read call. */
size_t n_read;
/* Determines how many consecutive newlines there have been in the
input. 0 newlines makes NEWLINES -1, 1 newline makes NEWLINES 1,
etc. Initially 0 to indicate that we are at the beginning of a
@@ -269,10 +235,15 @@ cat (
/* The inbuf pointers are initialized so that BPIN > EOB, and thereby input
is read immediately. */
eob = inbuf;
bpin = eob + 1;
/* Pointer to the first non-valid byte in the input buffer, i.e., the
current end of the buffer. */
char *eob = inbuf;
bpout = outbuf;
/* Pointer to the next character in the input buffer. */
char *bpin = eob + 1;
/* Pointer to the position where the next character shall be written. */
char *bpout = outbuf;
while (true)
{
@@ -283,7 +254,7 @@ cat (
if (outbuf + outsize <= bpout)
{
char *wp = outbuf;
size_t remaining_bytes;
idx_t remaining_bytes;
do
{
if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
@@ -342,7 +313,7 @@ cat (
/* Read more input into INBUF. */
n_read = safe_read (input_desc, inbuf, insize);
size_t n_read = safe_read (input_desc, inbuf, insize);
if (n_read == SAFE_READ_ERROR)
{
error (0, errno, "%s", quotef (infile));
@@ -528,38 +499,45 @@ cat (
}
}
/* Copy data from input to output using copy_file_range if possible.
Return 1 if successful, 0 if ordinary read+write should be tried,
-1 if a serious problem has been diagnosed. */
static int
copy_cat (void)
{
/* Copy at most COPY_MAX bytes at a time; this is min
(SSIZE_MAX, SIZE_MAX) truncated to a value that is
surely aligned well. */
ssize_t copy_max = MIN (SSIZE_MAX, SIZE_MAX) >> 30 << 30;
/* copy_file_range does not support some cases, and it
incorrectly returns 0 when reading from the proc file
system on the Linux kernel through at least 5.6.19 (2020),
so fall back on read+write if the copy_file_range is
unsupported or the input file seems empty. */
for (bool some_copied = false; ; some_copied = true)
switch (copy_file_range (input_desc, NULL, STDOUT_FILENO, NULL,
copy_max, 0))
{
case 0:
return some_copied;
case -1:
if (errno == ENOSYS || is_ENOTSUP (errno) || errno == EINVAL
|| errno == EBADF || errno == EXDEV || errno == ETXTBSY
|| errno == EPERM)
return 0;
error (0, errno, "%s", quotef (infile));
return -1;
}
}
int
main (int argc, char **argv)
{
/* Optimal size of i/o operations of output. */
size_t outsize;
/* Optimal size of i/o operations of input. */
size_t insize;
size_t page_size = getpagesize ();
/* Pointer to the input buffer. */
char *inbuf;
/* Pointer to the output buffer. */
char *outbuf;
bool ok = true;
int c;
/* Index in argv to processed argument. */
int argind;
/* Device number of the output (file or whatever). */
dev_t out_dev;
/* I-node number of the output. */
ino_t out_ino;
/* True if the output is a regular file. */
bool out_isreg;
/* Nonzero if we have ever read standard input. */
bool have_read_stdin = false;
@@ -602,6 +580,7 @@ main (int argc, char **argv)
/* Parse command line options. */
int c;
while ((c = getopt_long (argc, argv, "benstuvAET", long_options, NULL))
!= -1)
{
@@ -666,10 +645,15 @@ main (int argc, char **argv)
if (fstat (STDOUT_FILENO, &stat_buf) < 0)
die (EXIT_FAILURE, errno, _("standard output"));
outsize = io_blksize (stat_buf);
out_dev = stat_buf.st_dev;
out_ino = stat_buf.st_ino;
out_isreg = S_ISREG (stat_buf.st_mode) != 0;
/* Optimal size of i/o operations of output. */
idx_t outsize = io_blksize (stat_buf);
/* Device and I-node number of the output. */
dev_t out_dev = stat_buf.st_dev;
ino_t out_ino = stat_buf.st_ino;
/* True if the output is a regular file. */
bool out_isreg = S_ISREG (stat_buf.st_mode) != 0;
if (! (number || show_ends || squeeze_blank))
{
@@ -677,19 +661,20 @@ main (int argc, char **argv)
xset_binary_mode (STDOUT_FILENO, O_BINARY);
}
/* Check if any of the input files are the same as the output file. */
/* Main loop. */
infile = "-";
argind = optind;
int argind = optind;
bool ok = true;
idx_t page_size = getpagesize ();
do
{
if (argind < argc)
infile = argv[argind];
if (STREQ (infile, "-"))
bool reading_stdin = STREQ (infile, "-");
if (reading_stdin)
{
have_read_stdin = true;
input_desc = STDIN_FILENO;
@@ -713,7 +698,9 @@ main (int argc, char **argv)
ok = false;
goto contin;
}
insize = io_blksize (stat_buf);
/* Optimal size of i/o operations of input. */
idx_t insize = io_blksize (stat_buf);
fdadvise (input_desc, 0, 0, FADVISE_SEQUENTIAL);
@@ -730,23 +717,37 @@ main (int argc, char **argv)
goto contin;
}
/* Pointer to the input buffer. */
char *inbuf;
/* Select which version of 'cat' to use. If any format-oriented
options were given use 'cat'; otherwise use 'simple_cat'. */
options were given use 'cat'; if not, use 'copy_cat' if it
works, 'simple_cat' otherwise. */
if (! (number || show_ends || show_nonprinting
|| show_tabs || squeeze_blank))
{
insize = MAX (insize, outsize);
inbuf = xmalloc (insize + page_size - 1);
ok &= simple_cat (ptr_align (inbuf, page_size), insize);
int copy_cat_status =
out_isreg && S_ISREG (stat_buf.st_mode) ? copy_cat () : 0;
if (copy_cat_status != 0)
{
inbuf = NULL;
ok &= 0 < copy_cat_status;
}
else
{
insize = MAX (insize, outsize);
inbuf = xalignalloc (page_size, insize);
ok &= simple_cat (inbuf, insize);
}
}
else
{
inbuf = xmalloc (insize + 1 + page_size - 1);
/* Allocate, with an extra byte for a newline sentinel. */
inbuf = xalignalloc (page_size, insize + 1);
/* Why are
(OUTSIZE - 1 + INSIZE * 4 + LINE_COUNTER_BUF_LEN + PAGE_SIZE - 1)
(OUTSIZE - 1 + INSIZE * 4 + LINE_COUNTER_BUF_LEN)
bytes allocated for the output buffer?
A test whether output needs to be written is done when the input
@@ -764,24 +765,26 @@ main (int argc, char **argv)
positions.
Align the output buffer to a page size boundary, for efficiency
on some paging implementations, so add PAGE_SIZE - 1 bytes to the
request to make room for the alignment. */
on some paging implementations. */
outbuf = xmalloc (outsize - 1 + insize * 4 + LINE_COUNTER_BUF_LEN
+ page_size - 1);
idx_t bufsize;
if (INT_MULTIPLY_WRAPV (insize, 4, &bufsize)
|| INT_ADD_WRAPV (bufsize, outsize, &bufsize)
|| INT_ADD_WRAPV (bufsize, LINE_COUNTER_BUF_LEN - 1, &bufsize))
xalloc_die ();
char *outbuf = xalignalloc (page_size, bufsize);
ok &= cat (ptr_align (inbuf, page_size), insize,
ptr_align (outbuf, page_size), outsize, show_nonprinting,
ok &= cat (inbuf, insize, outbuf, outsize, show_nonprinting,
show_tabs, number, number_nonblank, show_ends,
squeeze_blank);
free (outbuf);
alignfree (outbuf);
}
free (inbuf);
alignfree (inbuf);
contin:
if (!STREQ (infile, "-") && close (input_desc) < 0)
if (!reading_stdin && close (input_desc) < 0)
{
error (0, errno, "%s", quotef (infile));
ok = false;

View File

@@ -1,5 +1,5 @@
/* chcon -- change security context of files
Copyright (C) 2005-2021 Free Software Foundation, Inc.
Copyright (C) 2005-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@@ -1,5 +1,5 @@
/* chgrp -- change group ownership of files
Copyright (C) 1989-2021 Free Software Foundation, Inc.
Copyright (C) 1989-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -313,7 +313,5 @@ main (int argc, char **argv)
(uid_t) -1, gid,
(uid_t) -1, (gid_t) -1, &chopt);
IF_LINT (chopt_free (&chopt));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@@ -1,5 +1,5 @@
/* chmod -- change permission modes of files
Copyright (C) 1989-2021 Free Software Foundation, Inc.
Copyright (C) 1989-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -44,8 +44,8 @@ struct change_status
enum
{
CH_NO_STAT,
CH_NOT_APPLIED,
CH_FAILED,
CH_NOT_APPLIED,
CH_NO_CHANGE_REQUESTED,
CH_SUCCEEDED
}
@@ -322,7 +322,7 @@ process_file (FTS *fts, FTSENT *ent)
if ( ! recurse)
fts_set (fts, ent, FTS_SKIP);
return CH_NO_CHANGE_REQUESTED <= ch.status;
return CH_NOT_APPLIED <= ch.status;
}
/* Recursively change the modes of the specified FILES (the last entry
@@ -567,7 +567,5 @@ main (int argc, char **argv)
ok = process_files (argv + optind,
FTS_COMFOLLOW | FTS_PHYSICAL | FTS_DEFER_STAT);
IF_LINT (free (change));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@@ -1,5 +1,5 @@
/* chown-core.c -- core functions for changing ownership.
Copyright (C) 2000-2021 Free Software Foundation, Inc.
Copyright (C) 2000-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -73,6 +73,28 @@ chopt_free (struct Chown_option *chopt)
free (chopt->group_name);
}
/* Convert the numeric user-id, UID, to a string stored in xmalloc'd memory,
and return it. Use the decimal representation of the ID. */
static char *
uid_to_str (uid_t uid)
{
char buf[INT_BUFSIZE_BOUND (intmax_t)];
return xstrdup (TYPE_SIGNED (uid_t) ? imaxtostr (uid, buf)
: umaxtostr (uid, buf));
}
/* Convert the numeric group-id, GID, to a string stored in xmalloc'd memory,
and return it. Use the decimal representation of the ID. */
static char *
gid_to_str (gid_t gid)
{
char buf[INT_BUFSIZE_BOUND (intmax_t)];
return xstrdup (TYPE_SIGNED (gid_t) ? imaxtostr (gid, buf)
: umaxtostr (gid, buf));
}
/* Convert the numeric group-id, GID, to a string stored in xmalloc'd memory,
and return it. If there's no corresponding group name, use the decimal
representation of the ID. */
@@ -80,11 +102,8 @@ chopt_free (struct Chown_option *chopt)
extern char *
gid_to_name (gid_t gid)
{
char buf[INT_BUFSIZE_BOUND (intmax_t)];
struct group *grp = getgrgid (gid);
return xstrdup (grp ? grp->gr_name
: TYPE_SIGNED (gid_t) ? imaxtostr (gid, buf)
: umaxtostr (gid, buf));
return grp ? xstrdup (grp->gr_name) : gid_to_str (gid);
}
/* Convert the numeric user-id, UID, to a string stored in xmalloc'd memory,
@@ -94,11 +113,8 @@ gid_to_name (gid_t gid)
extern char *
uid_to_name (uid_t uid)
{
char buf[INT_BUFSIZE_BOUND (intmax_t)];
struct passwd *pwd = getpwuid (uid);
return xstrdup (pwd ? pwd->pw_name
: TYPE_SIGNED (uid_t) ? imaxtostr (uid, buf)
: umaxtostr (uid, buf));
return pwd ? xstrdup (pwd->pw_name) : uid_to_str (uid);
}
/* Allocate a string representing USER and GROUP. */
@@ -484,11 +500,21 @@ change_file_owner (FTS *fts, FTSENT *ent,
: CH_SUCCEEDED);
char *old_usr = file_stats ? uid_to_name (file_stats->st_uid) : NULL;
char *old_grp = file_stats ? gid_to_name (file_stats->st_gid) : NULL;
char *new_usr = chopt->user_name
? chopt->user_name : uid != -1
? uid_to_str (uid) : NULL;
char *new_grp = chopt->group_name
? chopt->group_name : gid != -1
? gid_to_str (gid) : NULL;
describe_change (file_full_name, ch_status,
old_usr, old_grp,
chopt->user_name, chopt->group_name);
new_usr, new_grp);
free (old_usr);
free (old_grp);
if (new_usr != chopt->user_name)
free (new_usr);
if (new_grp != chopt->group_name)
free (new_grp);
}
}

Some files were not shown because too many files have changed in this diff Show More