Compare commits

...

349 Commits
v9.3 ... v9.5

Author SHA1 Message Date
Pádraig Brady
cc8689a07c version 9.5
* NEWS: Record release date.
2024-03-28 14:47:20 +00:00
Bruno Haible
bec53850b7 tests: od: avoid outputting undefined floating point values
od was seen to abort() on glibc on ia64 and m68k with the error:
Fatal glibc error: printf_fp.c:501 (__printf_fp_buffer_1):
assertion failed:
  cy == 1 || (p.frac[p.fracsize - 2] == 0 && p.frac[0] == 0)

* tests/od/od-multiple-t.sh: Avoid outputting long double floats
to avoid undefined behavior. 'float' and 'double' are standardized
by IEEE 754 (except on Linux/m68k) and don't have undefined values.
2024-03-27 12:41:33 +00:00
Pádraig Brady
541b026b11 build: update with gnulib fixes
* gnulib: Update to incorporate gnulib fixes
from Bruno Haible
2024-03-26 21:39:11 +00:00
Pádraig Brady
606f54d157 tests: numfmt: fix false failures on some systems
* tests/misc/numfmt.pl: Verify that printf field width specs
count characters and not bytes before enabling locale tests.
This was seen on FreeBSD 14.0 and Solaris 11 OpenIndiana.
Reported by Bruno Haible
2024-03-26 20:09:35 +00:00
Pádraig Brady
6e2b4769cc ls: avoid ENOENT from readdir() on FreeBSD 14
* src/ls.c (print_dir): readdir() on FreeBSD 14 was
seen to pass ENOENT through.  ENOENT in this context
means "Directory unlinked but still open".
Reported by Bruno Haible with tests/ls/removed-directory.sh
2024-03-26 18:57:32 +00:00
Pádraig Brady
3dc8657648 tests: avoid false failure due to mismatched isblank()
There is a mismatch between isblank() used by tr and c32isblank() now
used by uniq on Solaris 11 OpenIndiana. isblank() was seen to return
true for non breaking space, while c32isblank() returned false.
Interestingly on Solaris, non breaking space is considered a blank
character, and isblank() and c32isblank() honor this in all locales.

* tests/uniq/uniq.pl: Adjust the blank check to use join(1) rather than
tr(1), as join uses the same blank determination routines as uniq(1).
2024-03-26 16:53:09 +00:00
Pádraig Brady
30039cb23a cp: with --no-preserve=mode ensure set-group-ID bits maintained on dirs
This issue was introduced in commit v8.19-145-g24ebca6

* src/copy.c (copy_internal): On systems that don't support ACLs,
the fallback default chmod done on directories should maintain
the set-group-ID, as that's generally auto-set by the system.
* NEWS: Mention the fix.
Reported by Bruno Haible on Alpine (with tests/cp/preserve-mode.sh)
2024-03-25 22:27:15 +00:00
Pádraig Brady
c0f02a8f5b tests: avoid false failure with partial locale info
* tests/misc/numfmt.pl: Some systems with the fr_FR.UTF-8
locale installed, do not have a thousands grouping character defined.
In this case we skip the locale tests which depend on a non empty
grouping character.
2024-03-25 18:40:53 +00:00
Pádraig Brady
a51af43294 tests: avoid triggering obsolete tail option processing
* tests/ls/dired.sh: With 2 options, the latter is taken
as a file name on some systems.  This avoids a false
failure on Solaris and FreeBSD at least.
2024-03-25 13:02:52 +00:00
Pádraig Brady
ecb2fecdf9 tests: remove debugging from a test
* tests/ls/dired.sh: Remove temp debugging output.
2024-03-25 12:22:52 +00:00
Pádraig Brady
4cb2742d70 tests: fix false failure on systems that can chmod symlinks
* tests/chmod/symlinks.sh: The count of adjusted modes was
one more on systems where symlink modes can be adjusted.
Therefore only include the non symlinks in the count.
2024-03-25 12:12:19 +00:00
Pádraig Brady
26fd96a96c doc: fix translation issue in chown/chgrp amalgamation
* src/chown-core.h (emit_from_option_description): The conditional
string composition here caused issues for translators.
Instead move to a more general description ...
(src/chown.c (usage): ... here.
Fixes https://bugs.gnu.org/69985
2024-03-24 20:25:37 +00:00
Pádraig Brady
6259593ac7 doc: fix various translation issues
src/chown.c (usage): Translate parameterized strings.
 src/copy.c (copy_internal): Translate each part of ternary.
* src/cp.c (usage): Fix typo; s/exisiting/existing/.
2024-03-24 19:57:29 +00:00
Pádraig Brady
f77a6352fb test: avoid false failure with setgid directories
* tests/chmod/symlinks.sh: Ensure this new test is immune
to setgid directories by resetting modes with =777 rather than 777.
Also output more debugging in all failure cases.
2024-03-24 19:46:57 +00:00
Pádraig Brady
c45fcb2ed2 tests: avoid false failure on new mv --exchange test
* tests/mv/mv-exchange.sh: Canonicalize different
"operation not supported" messages, so we can ignore correctly.
Reported by Bruno Haible on AIX, NetBSD, and OpenBSD.
2024-03-24 18:32:34 +00:00
Pádraig Brady
e0cce6b62a doc: update THANKS related to env --argv0 option
* THANKS.in: Add Matheus who was central to the env --argv0
addition in commit v9.4-167-g193449b17.
2024-03-24 17:56:36 +00:00
Stephane Chazelas
7ebbeeb03d doc: ls: detail output format for device files
* doc/coreutils.texi (ls invocation): State that device numbers
are output, instead of file size.
2024-03-24 17:52:32 +00:00
Pádraig Brady
7b2064216c doc: remove older ChangeLog items
* Makefile.am: Update the oldest documented version
to 8.31 which is now about 5 years old.
2024-03-23 16:02:52 +00:00
Paul Eggert
5a1d00e450 mv: treat --exchange more like non-exchange
Also, improve quality of diagnostics.
Problems/suggestions by Bernhard Voelker in
<https://bugs.gnu.org/69532#82>.
* src/copy.c (emit_verbose): New arg FORMAT.  All uses changed,
to improve quality of diagnostics when --exchange is used.
(copy_internal): Don’t try to optimize --exchange so much; this
simplifies the code and keeps it closer to the non --exchange case.
2024-03-22 18:39:27 -07:00
Paul Eggert
ff42adb55e cp,ln,mv: improve dir vs nondir diagnostics
* src/copy.c (copy_internal): Simplify logic for copying
from directory to non-directory or vice versa, and always
diagnose with both source and destination file names.
2024-03-22 18:39:27 -07:00
Pádraig Brady
193449b173 env: add -a,--argv0 to set the first argument passed to exec
Using the shell's exec -a feature can be awkward
so add support for setting overriding argv[0].
This gives env full control over the arguments it passes.

* src/env.c: Accept -a,--argv0 and set argv[0] appropriately.
* tests/env/env.sh: Add test cases.
* doc/coreutils.texi (env invocation): Describe -a,--argv0.
* NEWS: Mention the new feature.
2024-03-22 13:12:52 +00:00
Pádraig Brady
91e69cd2d0 doc: pr: give solution to expanding TABs in multicolumn output
* doc/coreutils.texi (pr invocation): Explicitly state that
multicolumn output will convert spaces to TABs, and show that
this can be undone with the `pr -t -e` or `expand` commands.
Suggested by Douglas McIlroy in https://bugs.gnu.org/69807
2024-03-21 15:32:13 +00:00
Paul Eggert
1913bfcf57 doc: clarify mv --exchange
In the manual, say it exchanges all data and metadata.
Suggested by Pádraig Brady in:
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=69532#59
2024-03-20 15:01:07 -07:00
Paul Eggert
5d3fd24f42 mv: new option --exchange
* src/copy.h (struct cp_options): New member 'exchange'.
* src/copy.c (copy_internal): Support the new member.
* src/mv.c (EXCHANGE_OPTION): New constant.
(long_options): Add --exchange.
(usage): Document --exchange.
(main): Support --exchange.
* tests/mv/mv-exchange.sh: New test case.
* tests/local.mk (all_tests): Add it.
2024-03-20 14:40:29 -07:00
Pádraig Brady
425b8a2f53 chmod: fix TOCTOU security issue with symlink replacement
This is an issue with -[H]R mode, where an attacker
may replace a traversed file with a symlink
between where we stat() the file and chmod() the file.

* src/chmod.c (process_file): Remove the first !S_ISLNK guard
as that's now just an optimization, and instead consistently
apply fchmodat() to files/symlinks.  Ensure AT_SYMLINK_NOFOLLOW
is set when traversing in default (-H) mode.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/11108
2024-03-19 23:56:45 +00:00
Pádraig Brady
07a69fc3ba chmod: add support for -h, -H,-L,-P, --dereference options
There have been various requests to add -h to avoid following symlinks
for security reasons.  This wasn't provided previously as chmod(1)
already ignored symlinks unless specified on the command line.
Note chmod defaults to -H mode rather than the chown default of -P,
as usually chown can work directly on symlinks and so defaults
to not traversing those specified on the command line.
Note FreeBSD chmod does default to -P mode, but we retain the -H mode
default also for compatibility with existing chmod behavior.

Adding -HLP will allow chmod to disable traversing CLI symlinks to dirs.
Adding -h will allow to disable following CLI symlinks to files/dirs,
  also operating on all symlinks on systems that support that.
Adding --dereference will be significant with -H (the default).  I.e.
  symlinks to dirs not recursed, but symlinks are dereferenced.
Adding these options will also be consistent with chown(1), chgrp(1),
and chmod(1) on other systems.

Note since chmod(1) currently ignores symlinks by default,
and -h is primarily a mechanism to avoid following symlinks, rather than
for operating on the symlink itself, we make -h try to chmod a symlink,
but ignore ENOTSUP.  In that way we're consistent with chown(1)
where it also ignores ENOTSUP for symlinks, and we don't fail when
trying to be extra secure with command line params.

* doc/coreutils.texi (chmod invocation): Reference the -H,-L,-P
descriptions, and adjust the corresponding macros to say
the default is -H or -P as appropriate.
Add --dereference and -h,--no-dereference descriptions.
* man/chmod.x: Adjust discussion of symlink handling.
* src/chmod.c (main): Accept new options and set
fts flags appropriately.
(process_file): Process / dereference symlinks as necessary.
* src/system.h (emit_symlink_recurse_options): A new function
refactored from chown.c and chmod.c usage().
* tests/chmod/symlinks.sh: New test for the new options.
* tests/local.mk: Reference the new test.
* NEWS: Mention the new feature.
2024-03-19 23:43:53 +00:00
Pádraig Brady
a46f34bb56 maint: basenc: consistently check buffer bounds when encoding
* src/basenc.c (base16_encode, base2msbf_encode, base2lsbf_encode):
Ensure we don't overflow the output buffer, whose length is
passed in the OUTLEN parameter.  This issue was flagged by clang
with -Wunused-but-set-parameter.
2024-03-19 23:43:53 +00:00
Pádraig Brady
bf73a7602a pinky: disable location canonicalization by default
Behave like who(1) in requiring --lookup to enable this
often slow feature.  pinky(1) is supposed to be lightweight after all.

* doc/coreutils.texi (who invocation): Adjust the description to no
longer reference dialup, and be more general about the still significant
delays.
(pinky invocation): Reference the same --lookup description.
* src/pinky.c (main): Accept --lookup to enable DNS lookups.
* NEWS: Mention the change in behavior.
Fixes https://bugs.debian.org/628815
2024-03-19 23:43:53 +00:00
Pádraig Brady
48cd67663d doc: fix stale --dereference info for chown/chgrp
Following v5.2.1-679-g7e29ef8b8 symlinks specified on the command line
no longer induce an error if lchown() is not supported on the system.

* doc/coreutils.texi (chown invocation, chgrp invocation): Adjust
accordingly, and also use a macro to avoid duplication.
* src/chown-core.c: Use our more standard is_ENOTSUP() wrapper
in the code related to this.
2024-03-18 18:40:21 +00:00
Paul Eggert
dda89eb5d3 build: update gnulib submodule to latest 2024-03-16 22:49:45 -07:00
Pádraig Brady
c07a7d999e build: provide a cross-compiling default for 16 bit float checks
* configure.ac: Provide a conservative 16 bit float support default
when cross-compiling, to avoid configure failing in that case.
2024-03-15 11:38:28 +00:00
Grisha Levit
b8d1b00e21 env,kill,timeout: support unnamed signals
Some signals with values less that the max signal number for the system
do not have defined names.  For example, currently on amd64 Linux,
signals 32 and 33 do not have defined names, and Android has a wider
gap of undefined names where it reserves some realtime signals.

Previously the signal listing in env ended up reusing the name
of the last printed valid signal (the repeated HUP below):

    $ env --list-signal-handling true
    HUP        ( 1): IGNORE
    HUP        (32): BLOCK
    HUP        (38): IGNORE

..and the corresponding signal numbers were rejected as operands for the
env, kill, and timeout commands.

This patch removes the requirement that sig2str returns 0 for a signal
number associated with an operand.  This allows unnamed signals to be in
the sets `env' attempts to manipulate when a --*-signal option is used
with no argument, and kill(1) and timeout(1) to send such unnamed
signals.

* src/operand2sig.c (operand2sig): Drop signame argument, accept all
signal numbers <= SIGNUM_BOUND.  All callers updated.
* src/env.c (parse_signal_action_params, reset_signal_handlers)
(parse_block_signal_params, set_signal_proc_mask)
(list_signal_handling): Accept all signal numbers <= SIGNUM_BOUND,
use SIG%d for printing if necessary.
* src/kill.c (list_signals, main): Likewise.
(send_signals): Check errno from kill(3) for bad signo.
* src/timeout.c (main): Update operand2sig call.
* tests/misc/kill.sh: Test listing all signal numbers.
* NEWS: Mention the improvement.
2024-03-13 16:15:35 +00:00
Pádraig Brady
c7f422940a build: add caching for involved configure checks
* configure.ac: Wrap the following with AC_CACHE_VAL,
so that they can be cached / overridden.  We use
the "utils_cv_" prefix as they're coreutils specific overrides.
utils_cv_avx2_intrinsic_exists,
utils_cv_brain_16_bit_supported,
utils_cv_ieee_16_bit_supported,
utils_cv_pclmul_intrinsic_exists,
utils_cv_stdbuf_supported.
2024-03-13 12:31:32 +00:00
Grisha Levit
0cafa1524f build: strengthen 16 bit float support checks
Recent clang provides __bf16 on aarch64 but it is broken.

If built with -O0, the conversion is wrong:

    $ printf '\x3F\x80' | od --end=big -An -tfB | tr -d ' '
    1.875

If built with -O1 or higher, compilation fails:

    fatal error: error in backend:
    Cannot select: 0xb400007a58d29780: f32 = fp_extend 0xb40000...
    0xb40000...: bf16,ch = CopyFromReg 0xb40000..., Register:bf16 %13
    0xb40000...: bf16 = Register %13
    In function: print_bfloat

The latter issue does not cause the existing configure test to fail
because the promotion is optimized out.

* configure.ac: Ensure 16 bit float promotion code does not get
optimized out, and produces an expected result.
2024-03-13 11:49:30 +00:00
Collin Funk
00a34a05f5 maint: prefer minmax.h instead of defining our own
* src/comm.c (min): Remove.
(compare_files): Use MIN which is referenced by system.h.
2024-03-12 20:04:56 +00:00
Ville Skyttä
9a50494875 dircolors: add more archive extensions
* src/dircolors.hin: Add .apk (Alpine Linux/Android package); .drpm
(delta rpm); .egg, .pyz, and .whl (Python related); and .udeb (form of
.deb).
2024-03-12 15:22:01 +00:00
Collin Funk
44c9578a08 doc: add basic documentation for 'pinky'
* doc/coreutils.texi: Add 'pinky' under 'who'.
2024-03-12 14:57:51 +00:00
Pádraig Brady
ab4ffc8503 timeout: fix narrow race in failing to kill processes
* src/timeout.c (main): Block cleanup signals earlier so that cleanup()
is not runnable until monitored_pid is in a deterministic state.
This ensures we always send a termination signal to the child
once it's forked.
* NEWS: Mention the bug fix.
Reported at https://github.com/coreutils/coreutils/issues/82
2024-03-12 14:57:47 +00:00
Pádraig Brady
c1cf5148a1 timeout: fix race where we might kill arbitrary processes
* src/timeout.c (cleanup): Handle the case where monitored_pid
might be -1, which could happen if a signal was received
immediately after a failed fork() call.  In that case it would
send the termination signal to all processes that the timeout
process has permission to send signals too.
* NEWS: Mention the bug fix.
2024-03-11 15:12:36 +00:00
Pádraig Brady
7b92e9fb26 cksum: ensure appropriate "binary" mode with --untagged
* src/digest.c (main): If --binary was enabled with a previous --tag,
then reset the binary mode to auto select if --untagged then specified.
* tests/cksum/cksum-a.sh: Add a test case.
2024-03-06 21:54:02 +00:00
Pádraig Brady
9d8890d872 mv: revert add --swap (-x) option
Since this functionality is recently available
in the exch(1) utility from util-linux,
it was thought best not to complicate mv with it.

This reverts commit 6cd2d5e533
2024-03-05 21:34:00 +00:00
Pádraig Brady
fea833591b cksum: consistently validate --length attributes
* src/digest.c (main): Only validate the last used --length
for being a multiple of 8.
* tests/cksum/b2sum.sh: Add a test case.
Fixes https://bugs.gnu.org/69546
2024-03-04 16:35:27 +00:00
Pádraig Brady
c877c7c1ee doc: fix spellings in NEWS
* NEWS: s/user/uses/; s/exisiting/existing/
2024-03-03 12:27:07 +00:00
Petr Malat
6cd2d5e533 mv: add --swap (-x) option to atomically swap 2 paths
renameat2() syscall allows atomically swapping 2 paths on one
file system. Expose this ability to the user with --swap.

* doc/coreutils.texi: Describe mv --swap option.
* src/mv.c (main): Support --swap.
* tests/mv/mv-swap.sh: Add test for mv -x.
* tests/local.mk: Reference new test.
* NEWS: Mention the new option.
2024-03-03 12:18:45 +00:00
Pádraig Brady
fcfba90d0d cat,cp,mv,dd,install,split: set the default IO size to 256KiB
* src/ioblksize.h: Add updated test results and
increase value from 128KiB to 256KiB, which was last
updated 10 years ago.
* NEWS: Mention the improvement.
2024-02-28 22:26:52 +00:00
lvgenggeng
e397ba1a31 mktemp: fix template diagnostic with --suffix
* src/mktemp.c (main): When --suffix is specified, TEMPLATE
points to the meraged buffer DEST_NAME. As X's in the suffix are
not significant to the generated random characters, the diagnostic
for too few X's should only refer to the template portion.
* tests/misc/mktemp.pl: Adjust accordingly.
* NEWS: Mention the bug fix.
2024-02-27 14:59:33 +00:00
Pádraig Brady
f3bcb59ebd tests: move join tests to their own directory
* tests/misc/join-utf8.sh: Move to tests/join
since there are now multiple join tests.
* tests/misc/join.pl: Likewise.
2024-02-27 14:27:04 +00:00
Pádraig Brady
79c628901d tests: simplify treatment of the $LOCALE_FR_UTF8 variable
* tests/df/problematic-chars.sh: Rely on gnulib setting
this to "none" where not usable.
* tests/misc/sleep.sh: Likewise.
* tests/printf/printf-mb.sh: Likewise.
* tests/printf/printf-quote.sh: Likewise.
* tests/sort/sort-debug-keys.sh: Likewise.
2024-02-27 14:27:04 +00:00
Bruno Haible
f2e70e2d19 join: avoid test failure on systems with no French UTF-8 locale
* tests/misc/join-utf8.sh: Test the value of LOCALE_FR_UTF8 against
'none', not against a missing value.
Fixes https://bugs.gnu.org/69418
2024-02-27 14:26:35 +00:00
Bruno Haible
df5fa309c2 sort: make the startup time optimization effective on glibc < 2.34
* configure.ac: Test where to find the dlopen function. Set LIB_DL.
Use it in the DLOPEN_LIBCRYPTO test.
* src/local.mk (src_sort_LDADD): Add $(LIB_DL).
2024-02-27 13:39:06 +00:00
Pádraig Brady
45411e3fc6 build: improve libcrypto library detection
* configure.ac: Match literal '.' in the file name
to avoid potential mismatches with similarly named libs.
Reported by Andreas Schwab
2024-02-26 19:10:14 +00:00
Aearil
feda512e97 wc: fix -w with breaking space over UCHAR_MAX
* src/wc.c (wc): Fix regression introduced in commit v9.4-48-gf40c6b5cf.
* tests/wc/wc-nbsh.sh: Add test cases for "standard" spaces.
Fixes https://bugs.gnu.org/69369
2024-02-26 17:33:02 +00:00
Pádraig Brady
49912bac28 cp,mv: add --update=none-fail to fail if existing files
* src/cp.c (main): Add support for --update=none-fail to provide the
functionality of diagnosing files in the destination,
and exiting with failure status.
(usage): Mark -n as deprecated.
* src/mv.c: Likewise.
* src/copy.h: Add UPDATE_NONE_FAIL definition.
* src/system.h (emit_update_parameters_note): Add --update=none-fail
description.
* doc/coreutils.texi (cp invocation): Likewise.
Also mention why -n is deprecated.
* tests/mv/update.sh: Add a test case, including precedence
with -n and other --update options.
* tests/cp/cp-i.sh: Verify that --backup and --update=none{,-fail}
are mutually exclusive.
* tests/mv/mv-n.sh: Likewise.
* NEWS: Mention the new feature.
Addresses https://bugs.gnu.org/62572
2024-02-26 17:33:02 +00:00
Pádraig Brady
9907b6f5dc cp,mv: reinstate that -n exits with success if files skipped
* src/cp.c (main): Adjust so that -n will exit success if skipped files.
* src/mv.c (main): Likewise.
* doc/coreutils.texi (cp invocation): Adjust the description of -n.
* src/system.h (emit_update_parameters_note): Adjust --update=none
comparison.
* tests/cp/cp-i.sh: Adjust -n exit status checks.
* tests/mv/mv-n.sh: Likewise.
* NEWS: Mention the change in behavior.
Fixes https://bugs.gnu.org/62572
2024-02-26 17:33:02 +00:00
Pádraig Brady
3bbdb39388 build: fix libcrypto version linked by sort at runtime
One should link the versioned lib at runtime,
and the unversioned lib at build time,
as the unversioned lib may not be installed,
and better couples the binary with the required version.

* configure.ac: Define LIBCRYPTO_SONAME, determined from
the test binary linked with -lcrypto.  Also document
why we use SHA512() in the check, rather than MD5().
* src/sort.c (link_libcrypto): Use the versioned lib in dlopen().
2024-02-26 17:33:02 +00:00
Pádraig Brady
10be42f033 maint: avoid sc_tight_scope failure in sort.c
* cfg.mk: Exclude the ptr_MD5_* symbols added in
commit v9.4-130-g7f57ac2d2, as there is no way
to declare these static given they way they're defined.
2024-02-26 17:33:02 +00:00
Paul Eggert
d9dc02b09a doc: mention -lcrypto change in NEWS 2024-02-25 21:24:04 -08:00
Paul Eggert
7f57ac2d20 sort: dynamically link -lcrypto if -R
This saves time in the usual case, which does not need -lcrypto.
* configure.ac (DLOPEN_LIBCRYPTO): New macro.
* src/sort.c [DLOPEN_LIBCRYPTO && HAVE_OPENSSL_MD5]: New macros
MD5_Init, MD5_Update, MD5_Final.  Include "md5.h" after defining
them.  Include <dlfcn.h>, and define new functions link_failure
and symbol_address.
(link_libcrypto): New function.
(random_md5_state_init): Call it before using crypto functions.
2024-02-25 18:55:16 -08:00
Paul Eggert
9b6c25510b doc: de-“note” the documentation
* doc/coreutils.texi, man/readlink.x, man/runcon.x:
* src/comm.c (usage):
* src/digest.c (usage):
* src/echo.c (usage):
* src/join.c (usage):
* src/ln.c (usage):
* src/rm.c (usage):
* src/stat.c (usage):
* src/system.h (USAGE_BUILTIN_WARNING):
* src/test.c (usage):
* src/touch.c (usage):
* src/uniq.c (usage):
Rewrite to avoid most uses of “Note that” and similar wording.
These circumlocutions are rarely needed, and avoiding them
improves readability and lessens preaching.
2024-02-25 18:55:16 -08:00
Daan De Meyer
a357cfb021 cp: add --keep-directory-symlink option
When recursively copying files into OS trees, it often happens that
some subdirectory of the source directory is a symlink in the target
directory. Currently, cp will fail in that scenario with the error:

"cannot overwrite non-directory %s with directory %s"

However, we'd like cp in this scenario to follow the destination
directory symlink and copy the files into the symlinked directory
instead. Let's support this by adding a new option
--keep-directory-symlink that makes cp follow destination directory
symlinks.

We name the option --keep-directory-symlink to keep consistent with
tar which has the same option with the same effect.

* doc/coreutils.texi (cp invocation): Describe the new option.
* src/copy.h: Add the new setting.
* src/copy.h: Adjust to follow symlinks if setting enabled.
* src/cp.c (usage): Describe the new option.
(main): Accept the new option.
* tests/cp/keep-directory-symlink.sh: A new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the new feature.
2024-02-22 14:37:47 +00:00
Michel Lind
e82af7c2e6 dircolors: update list of archive file extensions
* src/dircolors.hin: Sort archive section by extension.
Treat .crate (Rust archives) as archive files
(they're essentially tar.gz files).
2024-02-19 14:37:22 +00:00
Collin Funk
430663cb35 maint: prefer #include <...> for gnulib substitute headers
* src/shuf.c: Change #include "getopt.h" to #include <getopt.h>.
* src/stat.c: Change #include "getopt.h" to #include <getopt.h>.
* src/system.h: Change #include "error.h" to #include <error.h>.

Copyright-paperwork-exempt: Yes
2024-02-19 14:19:06 +00:00
Pádraig Brady
8e3b0feb1d doc: add '[' to the info index
* doc/coreutils.texi (test invocation): Add '[' to the index.
2024-02-19 14:14:21 +00:00
Paul Eggert
ad4a9d02f5 build: update gnulib submodule to latest 2024-02-18 00:30:00 -08:00
Paul Eggert
01e52b9adc nohup: document GCC bug number
* src/nohup.c: Add GCC bug number to comment.
2024-02-18 00:29:59 -08:00
Paul Eggert
0a33c5384f ls: remove unnecessary pragmas
* src/ls.c (decode_switches): Remove pragmas.  They are no longer
needed to pacify GCC 13.2.1 with --enable-gcc-checking, and there’s
little point keeping them around for older GCC versions.
2024-02-18 00:29:59 -08:00
Paul Eggert
e298046727 maint: update GCC version comment
* src/copy.c: Update comment.
2024-02-18 00:29:59 -08:00
Paul Eggert
0fee70a9ff maint: document fix for GCC bug 109628
* src/fmt.c [14 <= __GNUC__]: Stop using pragma workaround,
as the GCC folks say the bug is no longer present in GCC 14.
2024-02-18 00:29:59 -08:00
Paul Eggert
aed1aa29db maint: remove unneeded suggest-attributes pragmas
* gl/lib/fadvise.c: Remove pragma that works around GCC bug 83559
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83559>.
This bug was fixed in GCC 9, and we needn’t worry about
--enable-gcc-warnings for compilers that old.
* src/test.c: Likewise.
2024-02-18 00:29:59 -08:00
Greg Wooledge
d39c523728 doc: fix typo in shred example
* doc/coreutils.texi (shred invocation): Fix the example
to correctly close file descriptor 3.
* THANKS.in: Remove old email since now recorded in repo history.
Reported at https://bugs.debian.org/1063837
2024-02-17 13:15:51 +00:00
Collin Funk
afa5d70c0d maint: avoid -Wshadow warning under clang
* src/env.c (parse_signal_action_params, parse_signal_block_params):
Rename OPTARG to ARG so that it does not conflict with OPTARG used by
getopt.

Copyright-paperwork-exempt: Yes
2024-02-07 15:34:13 +00:00
Pádraig Brady
f85472082c build: fix od build on clang < 17
* configure.ac: Ensure the compiler can promote 16 bit floating point
types to float, before enabling that code in od.  This was an issue
with clang 16 at least.
* src/od.c: Adjust for the new defines.
* tests/od/od-float.sh: Likewise.  Also port to the dash shell,
whose inbuilt printf doesn't support hex escapes.
2024-02-07 11:13:38 +00:00
Pádraig Brady
76604db7d2 od: support half precision floating point
Rely on compiler support for _Float16 and __bf16
to support -fH and -fB formats respectively.
I.e. IEEE 16 bit, and brain 16 bit floats respectively.
Modern GCC and LLVM compilers support both types.

clang-sect=half-precision-floating-point
https://gcc.gnu.org/onlinedocs/gcc/Half-Precision.html
https://clang.llvm.org/docs/LanguageExtensions.html#$clang-sect
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0192r4.html
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html

This was tested on:
gcc 13, clang 17 x86 (Both types supported)
gcc 7 aarch64 (Only -fH supported)
gcc 13 ppc(be) (Neither supported. Both will be with GCC 14)

* src/od.c: Support -tf2 or -tfH to print IEEE 16 bit floating point,
or -tfB to print Brain 16 bit floating point.
* configure.ac: Check for _Float16 and __bf16 types.
* doc/coreutils.texi (od invocation): Mention the new -f types.
* tests/od/od-float.sh: Add test cases.
* NEWS: Mention the new feature.
Addresses https://bugs.gnu.org/68871
2024-02-05 13:30:45 +00:00
Paul Eggert
6ec1fb46ab seq: say why not ‘x += step’
* src/seq.c (print_numbers): Add comment.
2024-01-28 23:36:17 -08:00
Pádraig Brady
c01ee18934 doc: split -C: test and document a heap overflow
This was introduced in coreutils 9.2 through commit v9.1-184-g40bf1591b,
and was fixed in coreutils 9.5 through commit v9.4-111-gc4c5ed8f4.
This issue has been assigned CVE-2024-0684.

* NEWS: Mention the bug fix.
* tests/split/line-bytes.sh: Add a test case.
Reported by Valentin Metz.
2024-01-18 16:52:36 +00:00
Pádraig Brady
aa50ea55ea tests: make ulimit -v interact better with ASAN
ulimit -v is generally not supported with ASAN, giving errors like:
  "ReserveShadowMemoryRange failed while trying to map 0x... bytes.
   Perhaps you're using ulimit -v"

* tests/cp/link-heap.sh: Mention ASAN as a possible reason for skipping.
* tests/csplit/csplit-heap.sh: Likewise.
* tests/cut/cut-huge-range.sh: Likewise.
* tests/dd/no-allocate.sh: Likewise.
* tests/printf/printf-surprise.sh: Likewise.
* tests/rm/many-dir-entries-vs-OOM.sh: Likewise.
* tests/head/head-c.sh: Only skip the part of the test needing ulimit.
* tests/split/line-bytes.sh: Likewise.
2024-01-17 23:59:49 +00:00
Paul Eggert
c4c5ed8f4e split: do not shrink hold buffer
* src/split.c (line_bytes_split): Do not shrink hold buffer.
If it’s large for this batch it’s likely to be large for the next
batch, and for ‘split’ it’s not worth the complexity/CPU hassle to
shrink it.  Do not assume hold_size can be bufsize.
2024-01-17 12:19:14 -08:00
Sylvestre Ledru
b09dc6306e tests: ls: add a test to verify that '+' is added
* tests/ls/acl.sh: Add a new test.
* tests/local.mk: Reference the new test.
2024-01-10 22:51:13 +00:00
Samuel Tardieu
f07f5b008f maint: add attributes to two functions without side effects
* src/date.c (res_width): This function computes its result solely
from the value of its parameter and qualifies for the const attribute.
* src/tee.c (get_next_out): This function has no side effect and
qualifies for the pure attribute.
* THANKS.in: Remove duplicate now that author has a commit in the repo.

Those two functions were flagged by GCC 12.3.0,
though not by GCC 13.2.1.
2024-01-06 15:42:44 +00:00
Pádraig Brady
a966dcdb69 maint: update all copyright year number ranges
Update to latest gnulib with new copyright year.
Run "make update-copyright" and then...

* gnulib: Update included in this commit as copyright years
are the only change from the previous gnulib commit.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Manually update copyright year,
until we fully sync with gnulib at a later stage.
* tests/sample-test: Adjust to use the single most recent year.
2024-01-01 13:27:23 +00:00
Paul Eggert
752ccef3eb maint: pacify recent clang better
* configure.ac: Clang now seems to have -Wformat-extra-args,
-Wimplicit-const-int-float-conversion, and
-Wtautological-constant-out-of-range-compare on by default,
so disable them even if --enable-gcc-warnings is not used.
Rely on Gnulib’s check for clang rather than rolling our own.
2023-12-31 19:49:26 -08:00
Paul Eggert
a9e4725773 maint: pacify clang -Winclude-next-absolute-path
* gl/lib/xdectoint.c: Use #include <...> instead of #include "...".
2023-12-31 19:49:26 -08:00
Paul Eggert
b8f0502bb1 build: update gnulib submodule to latest 2023-12-31 19:49:26 -08:00
Paul Eggert
8a757c220b ls: omit bad_cast
* src/ls.c (decode_switches): Declare some local vars to be
char const *, not char *, and omit unnecessary bad_cast calls.
2023-12-31 19:49:26 -08:00
Paul Eggert
1f651f4b3d split: omit bad_cast
* src/split.c (infile): Now char const *, not char *.
(main): Omit unnecessary bad_cast calls.
2023-12-31 19:49:26 -08:00
Pádraig Brady
9e67ccd745 sort: fix thousands grouping handling on single byte locales
* gl/lib/strnumcmp-in.h (numcompare): After commit v9.0-8-g6cafb122f,
we need to treat characters as signed to avoid invalid comparisons
between negative integers and unsigned characters.
* NEWS: Mention the bug fix.
2023-12-29 18:04:36 +00:00
Pádraig Brady
76ec516242 tests: numfmt: fix test related to lower case 'k' SI unit
* tests/misc/numfmt.pl: Following on from v9.4-86-g615167cc4,
adjust this test accordingly.  This test was being skipped
on some systems, and so only noticed now.
Reported by Jim Meyering.
2023-12-29 18:04:36 +00:00
Pádraig Brady
ebb985dc41 tests: run locale tests on more systems
* tests/misc/numfmt.pl: Determine the thousands grouping character
in use, rather than skipping locale tests when it's not a space.
For example fr_FR.UTF-8 uses "NARROW NO-BREAK SPACE" as the grouping
char on modern glibc systems at least.
* tests/sort/sort-h-thousands-sep.sh: Likewise.
2023-12-29 18:04:29 +00:00
Pádraig Brady
4dda343663 maint: distribute new header from previous commit
* src/local.mk: Reference the new header, so it's distributed.
2023-12-29 17:51:19 +00:00
Pádraig Brady
9cc8d6ff59 maint: merge chgrp and chown sources
chown is a close superset of chgrp functionality,
so merge sources to avoid unwanted divergence in future.
This removes about 300 lines in chgrp.c

* build-aux/gen-single-binary.sh: Generate new rules for chgrp.
* cfg.mk: Exclude new wrappers.
* po/POTFILES.in: Remove chgrp.c
* src/chgrp.c: Remove.
* src/chown-chgrp.c: New wrapper.
* src/chown-chown.c: Likewise.
* src/chown.c (main): Prepend ':' for chgrp(1).
* src/chown.h: Define both operating modes.
(usage): Adjust depending on utility being called.
* src/coreutils-chgrp.c: Likewise.
* src/local.mk: Reference new wrappers.
2023-12-27 19:51:00 +00:00
Christian Göttsche
98d463ef5d copy,install: avoid unnecessary security context translations
Do not perform SELinux context translation for operations not involving
user input or output.  Context translation converts MCS/MLS labels into
human readable form, which is useful for user facing applications like
ls(1) or the --context=CTX argument of cp(1).

* src/copy.c (set_process_security_ctx): Use raw selinux variants.
* src/install.c (need_copy): Likewise.
(setdefaultfilecon): Likewise.
* src/selinux.c (computecon): Likewise.
(defaultcon): Likewise.
* tests/cp/no-ctx.sh: Add raw variants to preload lib.
* NEWS: Mention the improvement.
2023-12-19 17:34:33 +00:00
Pádraig Brady
343b8d7ba7 build: update gnulib to latest
* gnulib: Primarily to get raw selinux wrappers
2023-12-19 17:18:46 +00:00
Pádraig Brady
c343bee1b5 maint: avoid false positive warning with newer gcc
* src/pr.c (read_line): GCC 13.2.1 can't discern that CHARS
is not used with '\n', so avoid the -Werror=maybe-uninitialized
issue in dev builds.
2023-12-17 17:19:29 +00:00
Pádraig Brady
63e9f1ae61 doc: cp --no-clobber: improve documentation
* doc/coreutils.texi (cp invocation): Reference the related --update
option, like we had already done in mv invocation.
* src/cp.c (usage): State clearly what --no-clobber does,
indicating it's protection focused, rather than being update focused.
2023-12-17 17:19:11 +00:00
Pádraig Brady
da091b3ab3 chgrp: add --from parameter similar to chown
* doc/coreutils.texi (chown invocation): Convert --from option
description to a macro and call from ...
(chgrp description): ... here.
* src/chown-core.h (emit_from_option_description): A new function
refactored from ...
* src/chown.c (usage): ... here, and called from ...
* src/chgrp.c (usage): ... here.
(main): Accept the --from option as chown(1) does.
* po/POTFILES.in: Add chown-core.h as now translated.
* tests/chown/basic.sh: Decouple the root user from id 0.
* tests/chgrp/from.sh: A new test largely based on chown/basic.sh.
* tests/local.mk: Reference the new test.
* NEWS: Mention the new feature.
Suggested by Ed Neville.
2023-12-15 13:19:27 +00:00
Pádraig Brady
0d9547474d maint: remove obsolete AC_PROG_GCC_TRADITIONAL
* configure.ac: Remove obsolete macro call.
Recent autoconf warns that it is obsolete.
AC_PROG_CPP sets up the -traditional-cpp option if required.
GCC ignores -traditional since commit f458d1d5 (2002).
Fixes https://bugs.gnu.org/67756
2023-12-11 17:03:33 +00:00
Pádraig Brady
4de72b7d9f doc: ls: fix regression in -f description
The description of -f regressed in coreutils 9.0

* doc/coreutils.texi (ls invocation): Detail which options
are enabled/disabled with -f.
* src/ls.c (usage): Likewise.
(decode_switches): Update comments.
Fixes https://bugs.gnu.org/67765
2023-12-11 14:37:02 +00:00
Pádraig Brady
49c8dab5b2 maint: add list/obstack.h to .gitignore
Following recent gnulib update
2023-12-11 14:34:46 +00:00
Pádraig Brady
9becda5d93 build: update gnulib submodule to latest
* bootstrap: Copy from latest Gnulib,
to fix --bootstrap-sync with other options.
2023-12-10 19:05:23 +00:00
Pádraig Brady
0ee8b03422 doc: touch: clarify --time description in man page
* src/touch.c (usage): Reorganise the description to be similar to
the format used for the ls --time description, which formats better
when converted to a man page.  Also separate the description
to allow for more granular translations.
Fixes https://bugs.gnu.org/67656
2023-12-06 13:07:43 +00:00
dann frazier
73d119f4f8 tail: fix tailing sysfs files where PAGE_SIZE > BUFSIZ
* src/tail.c (file_lines): Ensure we use a buffer size >= PAGE_SIZE when
searching backwards to avoid seeking within a file,
which on sysfs files is accepted but also returns no data.
* tests/tail/tail-sysfs.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/67490
2023-12-01 23:01:32 +00:00
Pádraig Brady
615167cc4d numfmt: support lowercase 'k' for Kilo and Kibi
For consistency with the "SI" standard, and with other coreutils
which output a lowercase 'k' in "SI" mode.

* src/numfmt.c (suffix_power): Treat 'k' like 'K' on input.
(double_to_human): Output lowercase 'k' in SI mode.
(usage): Adjust accordingly.
* doc/coreutils.texi: Mention 'k' accepted, and printed in SI mode.
* tests/misc/numfmt.pl: Adjust accordingly.
* NEWS: Mention the change in behavior.
Fixes https://bugs.gnu.org/47103
2023-11-27 19:41:49 +00:00
Paul Eggert
74b9d6a6e8 uniq: fix bug with -w in multibyte locales
-w counted bytes not characters, which is wrong in multibyte locales.
This bug exists even in Fedora, which is why the recently-added
test cases from Fedora didn’t catch it.
* src/uniq.c (find_field): New arg PLEN.  All callers changed.
Compute length of field correctly in multi-byte locales.
(different): Don’t worry about check_chars; find_field now does that.
* tests/uniq/uniq.pl: Test for this bug.
2023-11-16 11:37:25 -08:00
Paul Eggert
0ed9d1823a tests: omit inapplicable test code
* tests/misc/join.pl, tests/uniq/uniq.pl:
Remove test for "invalid byte, character or field list" message
that is not generated.
2023-11-16 11:37:25 -08:00
Paul Eggert
77201c506f uniq: change macro to function
* src/uniq.c (swap_lines): New static function, replacing
the old SWAP_LINES macro.  These days this is just as fast.
All uses changed.
2023-11-16 11:37:25 -08:00
Paul Eggert
3bee7c9754 uniq: prefer static init
* src/uniq.c (skip_fields, skip_chars, check_chars, count_occurrences)
(output_unique, output_first_repeated, output_later_repeated)
(delimit_groups): Initialize statically, rather than in ‘main’.
This shrinks the executable a bit.
2023-11-16 11:37:25 -08:00
Paul Eggert
a72b7823b4 uniq: simplify and fix unlikely bug by using bool
* src/uniq.c (enum countmode): Remove this type.
(count_occurrences): New static var, replacing the old countmode,
and of type boolean instead of a two-value enum type that was
confusing (and which caused a hard-to-test bug when the count
exceeded INTMAX_MAX - 1).  All uses changed.
2023-11-16 11:37:25 -08:00
Paul Eggert
a257b63ce7 uniq: prefer signed integers
* src/uniq.c (skip_fields, skip_chars, check_chars, size_opt)
(find_field, different, writeline, check_file, main):
Prefer signed to unsigned integer types, since this allows
for better runtime checking with -fsanitize=undefined.
2023-11-14 23:15:18 -08:00
Paul Eggert
23e26ed972 maint: DECIMAL_DIGIT_ACCUMULATE uses stdckdint.h
* src/system.h: Include <stdckdint.h>, since the new
DECIMAL_DIGIT_ACCUMULATE uses it.
Do not include stdckdint.h from files that also include system.h.
(DECIMAL_DIGIT_ACCUMULATE): Omit last arg, which is no longer needed.
Reimplement by using C23-style stdckdint.h’s ckd_mul and ckd_add,
as that’s more standard and is more likely to generate better code.
2023-11-14 20:38:24 -08:00
Paul Eggert
3e0d7787e6 pinky: fix string size calculation
* src/pinky.c (count_ampersands): Simplify and return idx_t.
(create_fullname): Compute proper destination string size,
basically, by adding (ulen - 1) * ampersands rather than ulen *
(ampersands - 1).  Problem found on CHERI-64.
2023-11-11 00:17:49 -08:00
Paul Eggert
4c15a1b6e6 maint: port randread to FreeBSD 14
* gl/lib/randread.c (POINTER_IS_ALIGNED): Rename from
ALIGNED_POINTER to avoid a collision with <machine/param.h>
on FreeBSD 14.
2023-11-11 00:17:49 -08:00
Paul Eggert
394b29aaff build: update gnulib submodule to latest 2023-11-11 00:17:48 -08:00
Pádraig Brady
7f2c97a241 ls: fix recent regression in size alignment
* src/ls.c (print_long_format): Use correct column width,
introduced due to a copy/paste error in commit v9.4-2-gcbb6dfec5
* tests/ls/size-align.sh: Add a test.
* tests/local.mk: Reference the new test.
Fixes https://bugs.gnu.org/66919
2023-11-03 16:34:38 +00:00
Paul Eggert
56e9acb292 join: fix recently introduced NUL bug
* src/join.c (xfields): Simplify and fix bug with fields
that start with a NUL byte when -t is not used.
* tests/misc/join-utf8.sh: Also test when -t is not used,
and when a field starts with NUL.
2023-10-30 10:49:44 -07:00
Paul Eggert
bd45f0963c maint: pacify ‘make syntax-check’
* tests/misc/join-utf8.sh: Omit fail=0.
Fix framework_failure_ typo.
* tests/misc/join.pl: Change ` to '.
2023-10-30 01:33:19 -07:00
Paul Eggert
ba5017b65a maint: copy join, uniq tests from Fedora
* tests/misc/join.pl, tests/uniq/uniq.pl:
Copy from Fedora 39.  This adds more multi-byte tests.
2023-10-30 01:24:43 -07:00
Paul Eggert
11b01fc21f join,uniq: support multi-byte separators
* NEWS: Mention this.
* bootstrap.conf (gnulib_modules): Remove cu-ctype, as this module
is now more trouble than it’s worth.  All uses removed.
Add skipchars.
* gl/lib/cu-ctype.c, gl/lib/cu-ctype.h, gl/modules/cu-ctype:
Remove.
* gl/lib/skipchars.c, gl/lib/skipchars.h, gl/modules/skipchars:
* tests/misc/join-utf8.sh:
New files.
* src/join.c: Include skipchars.h and mcel.h instead of cu-ctype.h.
(tab): Now mcel_t, not int.  All uses changed.
(output_separator, output_seplen): New static vars.
(eq_tab, newline_or_blank, comma_or_blank): New functions.
(xfields, prfields, prjoin, add_field_list, main):
Support multi-byte characters.
* src/numfmt.c: Include ctype.h, skipchars.h.
Do not include cu-ctype.h.
(newline_or_blank): New function.
(next_field): Support multi-byte characters.
* src/sort.c: Include ctype.h instead of cu-ctype.h.
(inittables): Open-code field_sep since it no longer exists.
‘sort’ is not multi-byte safe yet, but when it is this code
will need revamping anyway.
* src/uniq.c: Include mcel.h and skipchars.h instead of cu-ctype.h.
(newline_or_blank): New function.
(find_field): Support multi-byte characters.
* tests/local.mk (all_tests): Add tests/misc/join-utf8.sh
2023-10-30 00:58:04 -07:00
Paul Eggert
2709bea0f4 test: allow non-blank white space in numbers
* src/test.c (find_int): Use isspace, not isblank,
for compatibility with how strtol works, which
is how most other shells do this.
2023-10-30 00:58:04 -07:00
Paul Eggert
a3ce33c106 stdbuf: port to oddball toupper
* src/stdbuf.c: Do not include ctype.h.
(set_libstdbuf_options): Use c_toupper, not toupper,
since the C locale is intended here.
2023-10-30 00:58:04 -07:00
Paul Eggert
8d60cd8ad6 dircolors: assume C-locale spaces
* src/dircolors.c: Include c-ctype.h, not ctype.h.
(parse_line): Use c_isspace, not isspace, as the .dircolors
file format (which does not seem to be documented!) appears
to be ASCII.
2023-10-30 00:58:04 -07:00
Paul Eggert
5602342a16 maint: port to oddball tolower
* src/digest.c (hex_equal): Work even in oddball locales
where tolower does not work as expected on ASCII letters.
2023-10-30 00:58:04 -07:00
Paul Eggert
4edb14d20f maint: include ctype.h selectively
Include ctype.h only in files that need it.  Many of its uses
are incorrect, as they assume single-byte locales.  The idea is
to remove the incorrect uses later, when there is time.
* src/chroot.c, src/csplit.c, src/dd.c, src/digest.c, src/dircolors.c:
* src/expand-common.c, src/expand.c, src/fmt.c, src/fold.c, src/ls.c:
* src/od.c, src/pinky.c, src/pr.c, src/ptx.c, src/seq.c:
* src/set-fields.c, src/split.c, src/stdbuf.c, src/test.c:
* src/tr.c, src/truncate.c, src/unexpand.c, src/wc.c:
Include ctype.h.
* src/system.h: Do not include ctype.h.

include ctype.h.o
2023-10-30 00:58:04 -07:00
Paul Eggert
684e810ae2 maint: move field_sep into separate module
This is so that we don’t need to have every source file
include ctype.h.
* bootstrap.conf (gnulib_modules): Add cu-ctype.
* gl/lib/cu-ctype.c, gl/lib/cu-ctype.h, gl/modules/cu-ctype:
New files.
* src/join.c, src/numfmt.c, src/sort.c, src/uniq.c:
Include cu-ctype.h, for field_sep.
* src/system.h (field_sep): Remove; now supplied by cu-ctype.
2023-10-30 00:58:04 -07:00
Paul Eggert
2f3d9524bb digest: omit unnecessary b2sum includes
* src/blake2/b2sum.c: Do not include string.h, errno.h,
ctype.h, unistd.h, getopt.h.
2023-10-30 00:58:03 -07:00
Paul Eggert
0292a5678a maint: prefer c_isxdigit when that is the intent
* src/digest.c (valid_digits, split_3):
* src/echo.c (main):
* src/printf.c (print_esc):
* src/ptx.c (unescape_string):
* src/stat.c (print_it):
When the code is supposed to support only POSIX-locale hex digits,
use c_isxdigit rather than isxdigit.  Include c-ctype.h as needed.
This defends against oddball locales where isxdigit != c_isxdigit.
2023-10-30 00:58:03 -07:00
Pádraig Brady
f7e25d5bb5 maint: fix syntax check issue
* src/basenc.c: Fix preprocessor indentation.
2023-10-28 13:13:50 +01:00
Pádraig Brady
8c735f6585 base32,base64: disallow non-canonical encodings
This will make decoding more resilient to corruption
whether due to transmission errors or nefarious adjustment.
See https://eprint.iacr.org/2022/361.pdf

* gnulib: Update to commit 3f463202bd enforcing canonical encoding.
* tests/basenc/base64.pl: Add test cases, and adjust existing cases.
* NEWS: Mention the change in behavior.
2023-10-28 13:13:34 +01:00
Paul Eggert
60bd7bad9d basenc: fix unlikely locale issue; tune
This sped up ‘basenc -d --base16’ by 60% on my old platform,
AMD Phenom II X4 910e, Fedora 38.
* src/basenc.c (struct base16_decode_context): Simplify by
omitting have_nibble.  ‘nibble’ is now negative if it’s missing.
All uses changed.
(B16): New macro, inspired by ../lib/base64.c.
(base16_to_int): New static var, likewise.
(isubase16): Reimplement using base16_to_int, since isxdigit is
not guaranteed to succeed on the chars we want when the locale is
oddball.
(base16_decode_ctx): Tune by using base16_to_int and by
2023-10-25 15:09:27 -07:00
Paul Eggert
dcc1514d9a basenc: tweak checks to use unsigned char
This tends to generate better code, at least on x86-64,
because callers are just as fast and callees can avoid a conversion.
* src/basenc.c: The following renamings also change the arg type
from char to unsigned char.  All uses changed.
(isubase): Rename from isbase.
(isubase64url): Rename from isbase64url.
(isubase32hex): Rename from isbase32hex.
(isubase16): Rename from isbase16.
(isuz85): Rename from isz85.
(isubase2): Rename from isbase2.

2023-10-24  Paul Eggert  <eggert@cs.ucla.edu>

* src/basenc.c (struct base16_decode_context):
Simplify by storing -1 for missing nibbles.  All uses changed.
2023-10-25 15:09:27 -07:00
Paul Eggert
f4a59d453e build: update gnulib submodule to latest 2023-10-25 15:09:27 -07:00
Pádraig Brady
5f538c27a1 basenc: --base16: also allow lower case with --ignore-garbage
* src/basenc.c (isbase16): Also return true for lower case.
* tests/basenc/basenc.pl: Add a test case.
Reported by Paul Eggert.
2023-10-25 14:04:00 +01:00
Pádraig Brady
d733f2ec26 basenc: --base16: support lower case hex digits
* src/basenc.c (base16_decode_ctx): Convert to uppercase
before converting from hex.
* tests/basenc/basenc.pl: Add a test case.
* NEWS: Mention the change in behavior.
Addresses https://bugs.gnu.org/66698
2023-10-23 14:04:38 +01:00
Pádraig Brady
2e0dcd87bf doc: fix RFC references
* doc/coreutils.texi: Adjust RFC URLs as the original
now give 404 errors.
2023-10-23 12:29:03 +01:00
Pádraig Brady
caa716803a tests: move all basenc tests to their own directory
* tests/misc/base64.pl: Move to tests/basenc/base64.pl
* tests/misc/basenc.pl: Move to tests/basenc/basenc.pl
* tests/local.mk: Adjust accordingly
2023-10-06 18:22:35 +01:00
Pádraig Brady
378dc38f48 basenc: auto pad base32 and base64 inputs when decoding
Padding of encoded data is useful in cases where
base64 encoded data is concatenated / streamed.
I.e. where there are padding chars _within_ the stream.
In other cases padding is optional and can be inferred.
Note we continue to treat partial padding as invalid,
as that would be indicative of truncation.

* src/basenc.c (do_decode): Auto pad the end of the input.
* NEWS: Mention the change in behavior.
* tests/misc/base64.pl: Adjust to not fail for missing padding.
Addresses https://bugs.gnu.org/66265
2023-10-06 18:21:12 +01:00
Paul Eggert
a2434d3e58 sort: improve --help
Problem reported by Jorge Stolfi (bug#66253).
* src/sort.c (usage): Suggest looking at the manual for -n details.
2023-09-28 18:03:34 -07:00
Pádraig Brady
0c46704832 doc: rm --help: mention that '.' or '..' are rejected
* src/rm.c (usage): State that '.' or '..' are rejected.
2023-09-25 15:26:31 +01:00
Paul Eggert
de4e704273 wc: pacify ‘make syntax-check’
* src/wc_avx2.c (wc_lines_avx2): Explicitly make it ‘extern’.
Not sure why this is needed.
2023-09-23 17:20:26 -07:00
Paul Eggert
2245a95806 wc: distribute src/wc.h
* src/local.mk (noinst_HEADERS): Add src/wc.h.
2023-09-23 17:20:25 -07:00
Paul Eggert
f40c6b5cf2 wc: goto considered harmful
* src/wc.c: Do not include assure.h.  Replace the only
use of ‘assure’ with ‘unreachable’ which is good enough.
(wc, main): Remove labels and gotos.  This doesn’t affect
performance in any way I can measure, and makes the code
a bit easier to follow.
2023-09-23 17:07:52 -07:00
Paul Eggert
6b8b1f9e77 wc: prefer signed integers
Prefer signed to unsigned integers, to make it easier to catch
integer overflow errors.
* src/wc.c: Do not include safe-read.
(total_lines_overflow, total_words_overflow, total_chars_overflow)
(total_bytes_overflow): Now bool, not uintmax_t.  All uses changed.
(max_line_length): Now intmax_t, not uintmax_t.  All uses changed.
The total_... vars are still uintmax_t because overflow into them
is checked.
(page_size): Now idx_t, not size_t.
(wc_lines, wc, get_input_fstatus, compute_number_width, main):
Prefer signed to unsigned ints where either should do.
(wc_lines, wc): Use read rather than safe_read, since we don’t
need safe_read’s checks for huge buffers.
(wc): Redo call to mbrtoc32 to lessen the number of comparisons
against its returned value.  Do this partly by keeping a pointer
to the end of the buffer rather than a count.  Simplify
overflow-checking code.
(compute_number_width): Check for integer overflow.
Don’t assume size_t fits into unsigned long.
* src/wc.h (struct wc_lines): Prefer signed integers.
* src/wc_avx2.c: Do not include safe-read.h.
(wc_lines_avx2): Prefer signed integers.  Use read, not safe_read.
2023-09-23 17:07:52 -07:00
Paul Eggert
8d41285fe4 wc: improve avx2 API
* src/wc.c: Use "#include <...>" for files not in the current dir.
Include "wc.h" instead of declaring wc_lines_avx2 by hand.
(wc_lines): New API, with no file name (no longer needed) and
with a return struct rather than arg pointers.  All uses changed.
Use avx2_supported directly instead of using a function pointer.
Exploit C99-style declarations after statements.
Multiply by 15 rather than dividing; it’s faster and more accurate
and cannot overflow here.
(wc): Simplify based on wc_lines API change.
* src/wc.h: New file.
* src/wc_avx2.c: Include it, to check API better.
(wc_lines_avx2): Use new API.  All uses changed.  Exploit C99.
Make locals more local.
2023-09-23 17:07:52 -07:00
Paul Eggert
769ace51e8 factor,tail: avoid quadratic reallocation
* src/factor.c (struct mp_factors): New member nalloc.
(mp_factor_init): Initialize it.
* src/factor.c (mp_factor_insert):
* src/tail.c (parse_options): Use xpalloc to avoid quadratic
worst-case behavior on reallocation.
* src/tail.c (pids_alloc): New static var.
2023-09-23 01:15:50 -07:00
Paul Eggert
9ecc4f4e44 doc: mention Unicode exceptions for wc 2023-09-23 00:28:28 -07:00
Paul Eggert
a6064bb864 wc: simplify by removing SUPPORT_OLD_MBRTOWC
* src/wc.c (SUPPORT_OLD_MBRTOWC): Remove.  All uses removed.
(wc): Simplify by assuming C99-or-later behavior for mbrtoc32,
which after all is a C11 API.  Fix the !SUPPORT_OLD_MBRTOWC
code, which evidently was never tested seriously.
2023-09-23 00:28:27 -07:00
Paul Eggert
17a9e79023 wc: 3× speedup in C locale
The 3× speedup was measured by invoking 'wc $(find * -type f)'
on the coreutils sources etc. on an Ubuntu 23.04 x86-64.
These changes also speed up wc 20% in UTF-8 locales.
* src/wc.c (wc_isprint, wc_isspace): New static vars.
(wc): Use them for speed.
(main): Initialize them if needed.
(isnbspace): Remove; no longer used.
2023-09-23 00:28:27 -07:00
Paul Eggert
bee39b93f5 wc: treat encoding errors as non white space
* src/wc.c (wc): Treat encoding errors like non white space
characters.
2023-09-23 00:28:27 -07:00
Paul Eggert
31076e8689 wc: fix word count bug
* bootstrap.conf (gnulib_modules): Remove c32isprint.
* src/wc.c (wc): Consider all non-white-space characters
to be word constituents, even if they are not printable.
POSIX requires this, and it is what BSD does.
Partly do this by simplifying the check for a word,
by counting word starts rather than word ends.
* tests/wc/wc.pl: Test for the bug.
2023-09-23 00:28:27 -07:00
Paul Eggert
a6648d4102 maint: omit some unused function tests
* m4/jm-macros.m4: Do not check for ftruncate, iswspace,
mkfifo, mbrlen, sysctl.  Coreutils no longer uses the
corresponding HAVE_* macros, typically because Gnulib
handles them now.
* src/wc.c (iswspace): Remove; unused.
2023-09-23 00:28:27 -07:00
Paul Eggert
fc1822a042 sort: not a special case for mbrtowc
* configure.ac (GNULIB_MBRTOWC_SINGLE_THREAD): Define.
2023-09-23 00:28:27 -07:00
Paul Eggert
14d35d5bad maint: prefer char32_t to wchar_t
This should work better on non-glibc platforms that don’t
use Unicode for wchar_t.  However, POSIX appears to prohibit
this for printf.c so leave that alone.
* bootstrap.conf (gnulib_modules): Add btoc32, c32iscntrl,
c32isprint, c32isspace, c32width, mbrtoc32.  Remove btoc, wcwidth.
* src/df.c, src/ls.c, src/wc.c:
Include uchar.h instead of wchar.h and wctype.h.
* src/df.c (replace_invalid_chars):
* src/ls.c (quote_name_buf):
* src/wc.c (isnbspace, wc):
Use char32_t instead of wchar_t.
2023-09-23 00:28:27 -07:00
Paul Eggert
c5a210a9c8 wc: simplify #if MB_LEN_MAX
* src/wc.c: Don’t have special #ifs for platforms where
MB_LEN_MAX is 1.  On these platforms, MB_CUR_MAX is 1 as well,
so the compiler should optimize away all multi-byte code.
2023-09-23 00:28:26 -07:00
Paul Eggert
fb51f74ff6 wc: avoid undefined conversion state
* src/wc.c (wc): When mbrtowc returns (size_t) -1, zero the
conversion state, since POSIX says it’s undefined.
2023-09-23 00:28:26 -07:00
Paul Eggert
092f8178c0 maint: use mbszero
* bootstrap.conf (gnulib_modules): Add mbszero.
* src/df.c (replace_invalid_chars):
* src/ls.c (quote_name_buf):
* src/pathchk.c (portable_chars_only):
* src/printf.c (STRTOX):
* src/wc.c (wc):
Prefer mbszero to clearing an mbstate_t by hand.
2023-09-23 00:28:26 -07:00
Paul Eggert
c80a538d96 maint: prefer mcel
This causes Gnulib code to also use mcel, which is more consistent.
* bootstrap.conf (avoided_gnulib_modules): Avoid mbuiter
and mbuiterf, since we can now just use mcel.  This avoids
the need to ship and compile mbchar and these modules.
(gnulib_modules): Change mcel to mcel-prefer.
2023-09-23 00:28:26 -07:00
Paul Eggert
6c16044d8d wc: stop worrying about EBCDIC, shift-JIS, etc
* src/wc.c: Do not include mbchar.h.
(wc): Check for ASCII characters instead of using is_basic.
Other parts of Gnulib and coreutils already assume the encoding
is upward compatible with ASCII, and the old code wouldn’t
have worked anyway with shift-JIS.
2023-09-23 00:28:26 -07:00
Paul Eggert
17bddc047b expr: use mcel
The mcel API is simpler and corresponds more closely to how
Emacs etc. behave when the input has encoding errors,
since it treats each encoding-error byte separately.
* bootstrap.conf (gnulib_modules): Add mcel.
* src/expr.c: Include mcel.h instead of mbuiter.h.
(mbs_logical_cspn, mbs_logical_substr, mbs_offset_to_chars):
Use mcel API.
(mbs_logical_substr): Use ximemdup0 so as not to waste memory in
the result, fixing a FIXME.
2023-09-23 00:28:26 -07:00
Paul Eggert
654700ba5d build: update gnulib submodule to latest 2023-09-23 00:28:26 -07:00
Pádraig Brady
2593502290 build: avoid build failures on gcc <= 10, or clang
On gcc 10 the following build failure occurs:
  "error: a label can only be part of a statement
   and a declaration is not a statement"
This is because the current code is non standards conforming,
but GCC >= 11 will compile it (even with the -Wpedantic option).
This issue is tracked for GCC at:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111526

* src/tail.c (parse_options): Avoid a declaration after label,
by using a surrounding block.
2023-09-21 19:04:14 +01:00
Stephen Kitt
d24a117707 tail: allow multiple PIDs
tail can watch multiple files, but currently only a single writer. It
can be useful to watch files from multiple writers, or even processes
not directly related to the files (e.g. watch log files written by a
server process, for the duration of a test driven by a separate
client).

* src/tail.c (writers_are_dead): New function.
(tail_forever): Use it to wait for writers.
(tail_forever_inotify): As above.
(parse_options): Manage --pid options in an array.
* doc/coreutils.texi: Update documentation.
* tests/tail/pid.sh: Add a variant with two PIDs.
* News: Mention the new feature.
2023-09-20 15:53:34 +01:00
Sylvestre Ledru
8367b95a13 ls: --dired now implies long format with hyperlinks disabled
Currently --dired is silently ignored
with conflicting output formats

* src/ls.c (decode_switches): Set default format and hyperlink mode
when the --dired option is specified.
* tests/ls/dired.sh: Check that formats are implied / overridden.
* NEWS: Mention the change in behavior.
* doc/coreutils.texi (ls invocation): Adjust --dired description.
2023-09-17 18:47:50 +01:00
Sylvestre Ledru
3564e3a572 tests: improve ls --dired testing
* tests/ls/dired.sh: Verify ls --dired output against varying offsets.
2023-09-15 13:37:27 +01:00
Pádraig Brady
3b0f5b9971 maint: use C99 int size specifiers rather than PRI.MAX defines
Following on from commit v9.3-128-gf31229ebd
replace all uses of the PRI.MAX portability defines
with C99 size specifiers %z, %j, and %t.
2023-09-13 23:08:02 +01:00
Pádraig Brady
75e24853b7 doc: add subsections for cksum nodes
* doc/coreutils.texi: Specify each of the cksum nodes as a subsection,
so that the docs are organised appropriately in the pdf and html manual.
2023-09-11 20:45:42 +01:00
Paul Eggert
c7ec75a276 cp,mv,install: add copy_internal comment
* src/copy.c (copy_internal): Add comment about
some particularly tricky logic.
2023-09-08 16:25:39 -07:00
Paul Eggert
3cff27ddc1 cp: avoid needless unlinkat after fstatat ELOOP
* src/copy.c (copy_internal): When cp -f's fstatat fails on the
destination with ELOOP, report an error immediately when fstatat
used AT_SYMLINK_NOFOLLOW, as the later unlinkat would fail too.
2023-09-08 16:25:39 -07:00
Paul Eggert
a66a4b77a5 cp,mv,install: minor copy_internal refactoring
* src/copy.c (copy_internal): Redo to avoid need for calculating
fstatat_flags when not needed.  This is for clarity, not speed.
2023-09-08 16:25:39 -07:00
Paul Eggert
67324bf19c cp,mv,install: fix comment punctuation
* src/copy.h: Fix punctuation in comment.
2023-09-08 16:25:39 -07:00
Paul Eggert
69bd8be403 cp,mv,install: simplify copy_internal
* src/copy.c (copy_internal): Simplify.
2023-09-08 16:25:39 -07:00
Paul Eggert
68f4c238ca maint: prefer psame_inode, PSAME_INODE, STP_*
Prefer psame_inode, PSAME_INODE, STP_NBLOCKS, and STP_BLKSIZE,
which take addresses of objects, to their counterparts that
take the whole objects.  In some cases the whole objects might
not be initialized, which would be undefined behavior strictly
speaking.
* gl/lib/root-dev-ino.h (ROOT_DEV_INO_CHECK):
* src/cp-hash.c (src_to_dest_compare):
* src/ls.c (dev_ino_compare):
* src/pwd.c (robust_getcwd):
Prefer PSAME_INODE to SAME_INODE.
* src/chown-core.c (restricted_chown):
* src/copy.c (copy_reg, same_file_ok, source_is_dst_backup)
(copy_internal):
* src/ln.c (do_link):
* src/pwd.c (logical_getcwd):
* src/sort.c (avoid_trashing_input):
* src/split.c (create):
* src/stat.c (find_bind_mount):
Prefer psame_inode to SAME_INODE.
* src/copy.c (infer_scantype):
* src/du.c (process_file):
* src/ls.c (gobble_file, print_long_format)
(print_file_name_and_frills, length_of_file_name_and_frills):
* src/stat.c (print_stat):
Prefer STP_NBLOCKS to ST_NBLOCKS.
* src/copy.c (copy_reg):
* src/head.c (elide_tail_bytes_file, elide_tail_lines_file):
* src/ioblksize.h (io_blksize):
* src/od.c (skip):
* src/shred.c (do_wipefd):
* src/stat.c (print_stat):
* src/tail.c (tail_bytes):
* src/truncate.c (do_ftruncate):
* src/wc.c (wc):
Prefer STP_BLKSIZE to ST_BLKSIZE.
* src/ioblksize.h (io_blksize):
Arg is now struct stat const *, not struct stat.  All callers changed.
2023-09-04 23:12:02 -07:00
Paul Eggert
217d68104a build: update gnulib submodule to latest 2023-09-04 23:12:02 -07:00
Paul Eggert
65a1c5b441 cp,mv,install: a bit more up-to-date source stat
* src/copy.c (copy_reg): Replace caller’s source status
with the more recent version.
2023-09-04 23:12:02 -07:00
Paul Eggert
9cd52bd999 cp,mv,install: fix chmod on Linux CIFS
This bug occurs only when temporarily setting the mode to the
intersection of old and new modes when changing ownership.
* src/copy.c (owner_failure_ok): Treat EACCES like EPERM.
2023-09-02 13:28:23 -07:00
Paul Eggert
5f97136160 cp,mv,install: fix chown on Linux CIFS
* src/copy.c (chown_failure_ok): Also treat EACCES as OK.
2023-09-01 15:10:45 -07:00
Paul Eggert
de4a5220f2 maint: simplify set_owner
* src/copy.c (HAVE_FCHOWN, fchown): Remove.
(fchmod_or_lchmod): Move up.
(fchown_or_lchown): New function.
(set_owner): Use it to simplify.
2023-09-01 15:10:45 -07:00
Paul Eggert
74439d15d7 chown: port to mingw and MSVC 14
* src/chown-core.c (restricted_chown): Don’t assume fchown exists.
The Gnulib doc says that nowadays this is needed only for
ports to mingw and MSVC 14, but it’s an easy port so let’s do it.
2023-09-01 15:10:44 -07:00
Pádraig Brady
850a056441 maint: avoid syntax check failure
* tests/misc/numfmt.pl: Keep lines <= 80 chars.
2023-08-31 21:59:02 +01:00
Paul Eggert
8ed8d003f1 maint: Gnulib module gc
Remove Gnulib modules that coreutils code no longer use directly.
Some of these are used indirectly, but gnulib-tool should do that.
* bootstrap.conf (gnulib_modules): Remove calloc-gnu, cloexec,
getgroups, getpass-gnu, getugroups, getusershell, gnu-mae,
group-member, lchown, mgetgroups, netinet_in, readlink,
realloc-gnu, rename, rpmatch, stpncpy, tzset, wchar-single,
wcswidth.
2023-08-30 20:32:13 -07:00
Paul Eggert
07f8ec6bff maint: assume non-rare encodings
* configure.ac (GNULIB_WCHAR_SINGLE_LOCALE): Define.
This can improve performance, while dropping support for
rare encodings on non-GNU platforms.  Nowadays these encodings
are typically not worth the hassle.
2023-08-30 20:32:13 -07:00
Paul Eggert
af21374071 maint: tune for single thread & locale
* configure.ac (GNULIB_EXCLUDE_SINGLE_THREAD)
(GNULIB_REGEX_SINGLE_THREAD, GNULIB_WCHAR_SINGLE_LOCALE):
Define.
2023-08-30 20:32:13 -07:00
Paul Eggert
e0326b0473 maint: regularize struct initializers
* src/chmod.c (process_file):
* src/df.c (replace_invalid_chars):
* src/iopoll.c (iopoll_internal):
* src/ls.c (quote_name_buf):
* src/pathchk.c (portable_chars_only):
* src/printf.c (STRTOX):
* src/shred.c (main):
* src/stat.c (neg_to_zero, do_stat):
* src/timeout.c (settimeout):
* src/tr.c (card_of_complement):
* src/wc.c (wc):
Prefer ‘{0}’ to initialize everything to zero.
* src/stat.c (do_stat):
* src/timeout.c (settimeout):
Do not assume the usual order for struct members,
as POSIX does not guarantee this.
2023-08-30 20:32:13 -07:00
Paul Eggert
2c902cc288 maint: rely on Gnulib fdatasync
* m4/jm-macros.m4: Remove fdatasync-related code,
as Gnulib now does this.
* src/dd.c (fdatasync) [!HAVE_FDATASYNC]:
* src/shred.c (dosync) [!HAVE_FDATASYNC]: Rely on Gnulib fdatasync.
2023-08-30 20:32:13 -07:00
Paul Eggert
50e99b59bf maint: use modern Gnulib LIB_ macros
* src/local.mk (src_timeout_LDADD, src_dd_LDADD)
(src_shred_LDADD, src_sync_LDADD): Use TIMER_TIME_LIB
and FDATASYNC_LIB instead of LIB_TIMER_TIME and
LIB_FDATASYNC.
2023-08-30 20:32:13 -07:00
Paul Eggert
75bf3c00d3 kill: rely on Gnulib strsignal
Omit checks no longer needed now that we use strsignal.
* configure.ac: Do not check for strsignal-related decls.
* src/kill.c (sys_siglist, strsignal): Remove.
2023-08-30 20:32:13 -07:00
Paul Eggert
8463f41e4d maint: remove rename macro
* src/copy.h (rename) [RENAME_TRAILING_SLASH_BUG]:
Remove: unused, now that Gnulib takes care of this.
2023-08-29 23:57:40 -07:00
Paul Eggert
cbb6dfec55 maint: remove need for mbsalign
This simplifies memory allocation a bit, and removes an arbitrary
limitation from numfmt, which formerly limited cell output to 127
bytes.
* bootstrap.conf (gnulib_modules): Remove mbsalign, strncat.
Add strnlen (the code already used strnlen directly, and we were
saved only because Gnulib used the module indirectly)
* gl/lib/mbsalign.c, gl/lib/mbsalign.h, gl/modules/mbsalign:
* gl/modules/mbsalign-tests, gl/tests/test-mbsalign.c: Remove.
* src/df.c, src/ls.c: Do not include mbsalign.h.
(MBSWIDTH_FLAGS): New constant, now used for all
mbswidth calls.  All callers changed to check for -1 return.
* src/df.c (struct field_data_t): ‘width’ is now int not size_t,
since mbswidth can’t do widths greater than INT_MAX anyway.
Replace ‘align’ with ‘align_right’.  All uses changed.
(print_table): Redo to avoid the need for ambsalign.
(get_header, get_dev): mbswidth returns int, not size_t.
* src/ls.c (MAX_MON_WIDTH): Remove; no longer used.
(abmon_init): Use strnlen to cheaply discard too-long month names.
Align by hand instead of using mbsalign.
* src/numfmt.c: Include stdckdint.h, mbswidth.h.
Do not include mbsalign.h.
(padding_buffer_size): Now idx_t.  All uses changed.
(padding_width): Now intmax_t, since it’s no longer an object
size.  Its sign now records alignment.  All uses changed.
(zero_padding_width): Now int, since it’s given to sprintf.
All uses changed.
(padding_alignment): Remove; it’s now taken from padding_width’s sign.
(double_to_human): Return string length.  BUF_SIZE arg is now idx_t.
Include suffix in output.  All callers changed.  Simplify by not
calling strncat or stpcpy.  Calculate fmt size bound more carefully.
(setup_padding_buffer): Remove.  All uses removed.
(parse_format_string): Use intmax_t, not long, for pad.
On overflow, set widths to large values that cause later code
to do the right thing, rather than separately checking for
overflow here.
(prepare_padded_number): Return bool, not int 0/1.  New arg
PADDING.  All uses changed.  Do not limit padded output to 127
bytes; instead, use xpalloc to expand the output buffer.
(print_padded_number): New arg PADDING.  All uses changed.
(process_suffixed_number): Simplify.
(main): Take extremum if xstrtoimax overflows, as this does
the right thing.
* tests/misc/numfmt.pl: New test suf-20 to test for truncation bug.
Remove tests pad-3.2, fmt-err-7, as they’re no longer invalid but
are quite expensive.
2023-08-29 23:57:40 -07:00
Pádraig Brady
632beba630 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2023-08-29 15:23:14 +01:00
Pádraig Brady
9530a14420 version 9.4
* NEWS: Record release date.
2023-08-29 14:36:22 +01:00
Paul Eggert
2dddc87214 maint: spelling fixes, including author names
Most of this just affects commentary and documentations.  The only
significant behavior change is translating author names via
proper_name_lite rather than proper_name_utf8, or not translating
them at all.  proper_name_lite is good enough for coreutils and
avoids the bloat that had coreutils not using Gnulib proper_name.
* bootstrap.conf (gnulib_modules): Use propername-lite instead
of propername.
(XGETTEXT_OPTIONS): Look for proper_name_lite instead of for
proper_name_utf8.
* cfg.mk (local-checks-to-skip): Remove
sc_proper_name_utf8_requires_ICONV, since we no longer use
proper_name_utf8.
(old_NEWS_hash): Update.
(sc_check-I18N-AUTHORS): Remove; no longer needed.
2023-08-28 14:06:43 -07:00
Paul Eggert
e3f15c9c4a test: omit unreachable code
* src/test.c (unary_operator): Omit unreachable ‘return false;’.
Oracle Solaris Studio 12.6 warns about it.
2023-08-28 14:06:43 -07:00
Bruno Haible
c8340962dd tests: avoid test failure on Android
* gl/tests/test-mbsalign.c (main): Skip the unibyte truncation test
on Android, when the "C" locale in fact is multibyte.
2023-08-28 12:18:26 +01:00
Paul Eggert
9348edb6b6 sort: port sort-merge-fdlimit test to Solaris 10
* tests/sort/sort-merge-fdlimit.sh: Give 'sort' fd 6 too.
Needed for the same reason sort-continue.sh needed a ulimit -n boost.
2023-08-27 20:50:04 -07:00
Paul Eggert
5c9998fbab sort: port sort-continue test back to Solaris 10
* tests/sort/sort-continue.sh: Use ulimit -n 7 not -n 6.  On
Solaris 10 'sort' uses Gnulib mkostemp, which calls Gnulib
getrandom, which opens /dev/urandom to calculate the temp file's
name, which means 'sort' needs one more file descriptor to work.
2023-08-27 19:15:31 -07:00
Pádraig Brady
b3afbcad9c tests: avoid false failure on cygwin
* tests/cksum/md5sum-bsd.sh: Avoid part of test dealing with backslashes
in file names, on systems where backslash is a directory separator.
Issue reported by Bruno Haible on cygwin.
2023-08-27 20:22:32 +01:00
Pádraig Brady
f4e2e2bb57 cksum: adjust tests and docs to binary mode handling
Following commit v9.3-80-g5e1e0993b which makes cksum
match the output of the standalone utilities...

* doc/coreutils.texi (cksum output modes): Remove the mention
that cksum never outputs a binary indicator, as that's no longer the
case.
* tests/cksum/b2sum.sh: Avoid outputting a binary indicator.
* tests/cksum/sm3sum.pl: Likewise.
2023-08-27 19:53:52 +01:00
Pádraig Brady
5e44ad4e6d all: avoid duplicated write errors on FreeBSD
* src/system.h (write_error): Also call fpurge(), which was seen to
be needed on FreeBSD 13.1 to avoid duplicated write errors.
* src/head.c (xwrite_stdout): Likewise.
* bootstrap.conf: Depend on fpurge.
Reported by Bruno Haible.
2023-08-27 17:32:07 +01:00
Pádraig Brady
13e13107e1 tests: avoid false failure where sleep is a shell builtin
* tests/misc/usage_vs_getopt.sh: Handle sleep as a shell builtin,
which was seen on Alpine Linux 3.18.
2023-08-27 17:18:01 +01:00
Bruno Haible
900606431e build: fix link errors of sort, split on CentOS 5 and Solaris 10
* src/local.mk (src_sort_LDADD, src_split_LDADD): Add $(CLOCK_TIME_LIB).
2023-08-27 16:37:54 +01:00
Bruno Haible
016e9a3bb8 build: fix compilation error on AIX 7.1
* src/copy.c (copy_internal): Don't test for ENOTEMPTY if it has the
same value as EEXIST.
2023-08-27 16:37:52 +01:00
Pádraig Brady
32e8ead131 build: update with gnulib fixes
* gnulib: Update to incorporate gnulib fixes
from Bruno Haible from his coreutils 9.4 pre-release testing.
2023-08-27 16:09:07 +01:00
Pádraig Brady
25727ebd6a doc: remove older ChangeLog items
* Makefile.am: Update the oldest documented version
to 8.30 which is now about 5 years old.
2023-08-24 12:10:49 +01:00
Pádraig Brady
13f439ce56 shred: fix operation on Solaris with 64 bit builds
* NEWS: Mention the bug fix.
* gl/lib/randread.c (get_nonce): Limit getrandom() <= 1024 bytes.
2023-08-23 15:23:42 +01:00
Pádraig Brady
d553ab43c6 build: update gnulib submodule to latest
* gnulib: Update to latest
2023-08-22 12:10:09 +01:00
Pádraig Brady
e15f5ab354 doc: reorg texinfo for the checksumming utilities
* doc/coreutils.texi: Reorg so that 'cksum invocation' is the
main node listing all options and output formats, which is then
referenced by the descriptions of the standalone utilities.
Use macros in the description of the standalone utilities
rather than referencing 'md5sum invocation' to be more direct.
2023-08-22 12:09:57 +01:00
Pádraig Brady
b0af86d062 doc: cksum: remove -b description from texinfo
* doc/coreutils.texi (cksum invocation): Following commit 5e1e0993
also remove the desciption of the -b option for the cksum command.
2023-08-21 22:20:39 +01:00
Pádraig Brady
4f92de5822 cp: with --sparse=never, avoid COW and copy offload
* src/cp.c (main): Set default reflink mode appropriately
with --sparse=never.
* src/copy.c (infer_scantype): Add a comment to related code.
* tests/cp/sparse-2.sh: Add a test case.
* NEWS: Mention the bug.
2023-08-21 14:28:14 +01:00
Pádraig Brady
27c76b83b4 maint: comment spelling fix
* tests/split/l-chunk-root.sh: Fix recently introduced typo.
2023-08-19 16:45:17 +01:00
Pádraig Brady
20b9a015e5 maint: remove extraneous line in NEWS
* NEWS: Remove extraneous line.
2023-08-16 11:47:54 +01:00
Bruno Haible
622eea03cd uptime: simplify following gnulib changes
* build-aux/gen-lists-of-programs.sh (build_if_possible_progs):
Remove uptime.
(normal_progs): Add uptime.
* configure.ac: Remove GNULIB_BOOT_TIME invocation.
* m4/boottime.m4: Remove file.
* src/uptime.c: Don't include <sys/sysctl.h>, <OS.h>.
(print_uptime): Don't call sysctl, get_system_info, as Gnulib's
readutmp module now does this.
2023-08-15 15:22:27 -07:00
Paul Eggert
f2c2643fc5 maint: update uptime NEWS
* NEWS: Update as per Bruno Haible <https://bugs.gnu.org/65255#14>.
2023-08-15 15:22:27 -07:00
Pádraig Brady
fc5e68612f tests: fix false failure due to locale on alpine
* tests/sort/sort-debug-keys.sh: Decimal point was seen to be '.'
on fr_FR.UTF-8 on Alpine Linux 3.18, so add an extra guard
to ensure we've a ',' as the decimal point on this locale.
Fixes https://bugs.gnu.org/65310
2023-08-15 22:55:41 +01:00
Paul Eggert
1ea34cbf6a uptime: be more generous about read_utmp failure
* src/uptime.c (print_uptime): Check for overflow
when computing uptime.  Use C99-style decl after statements.
Do not let an idx_t value go negative.
(print_uptime, uptime): Be more generous about read_utmp failures,
or when read_utmp does not report the boot time.  Instead of
failing, warn but keep going, printing the information that we did
get, and then exit with nonzero status.
(print_uptime): Return the desired exit status.  Caller changed.
2023-08-15 14:01:58 -07:00
Bruno Haible
d8cfa5db49 uptime: Include VM sleep time in the "up" duration
* src/uptime.c: Don't include c-strtod.h.
(print_uptime): Don't read /proc/uptime, because the value it provides
does not change when a date adjustment occurs.
* bootstrap.conf (gnulib_modules): Remove 'uptime'.
2023-08-15 14:01:58 -07:00
Paul Eggert
58977651ec build: update gnulib submodule to latest 2023-08-15 14:01:58 -07:00
Bernhard Voelker
0cb8332196 maint: fix typo in NEWS
* NEWS: s|/who/log/wtmp|/var/log/tmp|, introduced in commit 85edb4afbd.
2023-08-15 13:35:13 +02:00
Bernhard Voelker
d428096a6a doc: reference install(1) and cp(1) from each other
* man/cp.x (SEE ALSO): Add install(1).
* man/install.x (SEE ALSO): Add cp(1).

Discussed at
https://lists.gnu.org/r/coreutils/2023-08/msg00026.html
2023-08-15 13:29:41 +02:00
Bruno Haible
db1d95f43b build: fix recent compilation error on GNU/Hurd
* src/copy.c (set_author): Revert change from MACH_PORT_NULL to
MACH_PORT_nullptr from commit 16b5ca6e (2023-06-29).
2023-08-14 22:11:57 +01:00
Pádraig Brady
dc3c843187 maint: avoid syntax-check failure
* po/POTFILES.in: Cater to lib/file-type.c adjustments
as suggested by sc_po_check.
2023-08-14 14:03:35 +01:00
Bruno Haible
049e5b0f87 build: fix link errors with gcc < 4.8
* configure.ac: Attempt to link, not only compile, the test programs
with __builtin_cpu_supports, to avoid link errors with cksum and wc.
2023-08-14 13:45:44 +01:00
Paul Eggert
85edb4afbd doc: improve NEWS discussion of systemd 2023-08-12 23:51:59 -07:00
Paul Eggert
9b673e61af build: update gnulib submodule to latest 2023-08-12 23:51:59 -07:00
Pádraig Brady
f31229ebd1 maint: allow use of printf C99 integer size specifiers
Older systems that had issues with these like HP-UX and Solaris 8
are now obsolete, and can easily apply patches to provide support.
Also we've used %td since coreutils 9.1, with no reported issues.

* cfg.mk (sc_prohibit-c99-printf-format): Remove to allow use of
%[jtz] size specifiers, which allows for cleaner code
by avoiding the need to cast to PRI?MAX etc.
2023-08-12 11:32:25 +01:00
Pádraig Brady
5420604332 doc: separate out description of 2038 time stamp change
* NEWS: Separate out the description of the _existing_ issues
with outputting timestamps on 32 bit systems, from _future_ issues
outputting timestamps on all systems.  Also move this to the
"improvement" section, since it's not really a coreutils
specific issue, and also is a build time configurable option.
2023-08-11 14:34:49 +01:00
Bruno Haible
d70d55c0a4 pinky,users,who: optimize read_utmp invocation
When we are only interested in entries of type USER_PROCESS, tell
read_utmp that it does not need to determine the boot time.

* src/pinky.c (short_pinky): Pass option READ_UTMP_USER_PROCESS.
* src/users.c (users): Likewise.
* src/who.c (who): Likewise, if calling list_entries_who.
2023-08-11 14:07:37 +01:00
Paul Eggert
ad82336026 who: simplify based on readutmp changes
* src/pinky.c (time_string, print_entry, scan_entries, short_pinky):
* src/uptime.c (print_uptime, uptime):
* src/users.c (list_entries_users, users):
* src/who.c (UT_TYPE_RUN_LVL, UT_TYPE_INIT_PROCESS)
(UT_TYPE_LOGIN_PROCESS, UT_TYPE_DEAD_PROCESS, UT_TYPE_NEW_TIME)
(time_string, print_user, print_boottime)
(make_id_equals_comment, print_deadprocs, print_login)
(print_initspawn, print_clockchange, print_runlevel)
(list_entries_who, scan_entries, who):
Simplify, partly by using plain -> rather than macros.
2023-08-08 20:05:33 -07:00
Paul Eggert
422dcd424c pinky,who: omit pragma
* src/pinky.c, src/who.c:
Omit no-longer-needed -Wstringop-overread pragma.
2023-08-08 20:05:33 -07:00
Bruno Haible
911c0bc41d maint: Simplify after gnulib changed
Update gnulib submodule to latest.
All of UT_USER_SIZE, UT_ID_SIZE, UT_LINE_SIZE, UT_HOST_SIZE are now -1.

* src/pinky.c (print_entry): Remove code for bounded-length ut_line,
ut_user, ut_host.
(scan_entries): Remove code for bounded-length ut_user.
* src/who.c (print_line): Remove userlen, linelen arguments.
(print_user): Remove code for bounded-length ut_line, ut_user, ut_host.
(make_id_equals_comment): Remove code for bounded-length ut_id.
(print_boottime, print_deadprocs, print_login, print_initspawn,
print_clockchange, print_runlevel, print_heading): Update print_line
invocations.
(scan_entries): Remove code for bounded-length ut_line.
2023-08-08 20:05:33 -07:00
Paul Eggert
0e58c95000 maint: Update after gnulib module 'readutmp' changed
(This patch is coauthored with Bruno Haible,
with original version at <https://bugs.gnu.org/64937#>.)
This updates the gnulib submodule to latest.
For year-2038 safety on Linux/{x86,arm},
this adds an --enable-systemd option to ‘configure’.
The idea is that this sort of thing will become the default
after it has been tested more.
* configure.ac: Don't test whether struct utmp and struct utmpx
have the ut_host field; this is now done in gnulib's readutmp module.
* src/local.mk: Link the programs 'pinky', 'uptime', 'users',
'who' with $(READUTMP_LIB).
* src/pinky.c, src/who.c:
Test HAVE_STRUCT_XTMP_UT_HOST instead of HAVE_UT_HOST.
* src/pinky.c (print_entry):
* src/who.c (print_user, print_deadprocs, print_login)
(print_initspawn, scan_entries):
Support the situation where ut_line is a 'char *' rather than a
'char[]' of fixed size.  Likewise for ut_user and ut_host.
(make_id_equals_comment): Likewise for ut_id.
* src/pinky.c (print_entry):
* src/who.c (print_user):
Open /dev to simplify looking up its entries.
Don’t use printf if the output might in theory be longer than INT_MAX.
* src/pinky.c (scan_entries, short_pinky):
* src/uptime.c (print_uptime, uptime):
* src/users.c (list_entries_users, users):
* src/who.c (who):
Use idx_t where new read_utmp needs it.
* src/system.h (STREQ_LEN): Add comment that last arg can be -1.
2023-08-03 23:16:00 -07:00
Paul Eggert
cb7bb52551 uptime: fix Y5881633 bug
* src/uptime.c (print_uptime): Prefer signed types.
Fix unlikely bug on platforms with 32-bit long and 64-bit time_t
if the idle time exceeds 2**31 days (about 6 million years...).
2023-08-02 06:52:39 -07:00
Paul Eggert
93e30466ff pinky: fix "d" typo
Problem reported by Bruno Haible (bug#65003).
* src/pinky.c (idle_string): Fix recently-introduced typo:
missing "d" for "days".
2023-08-02 06:52:39 -07:00
Dragan Simic
73ba9f71e1 maint: minor comment cleanups
* src/cut.c: Adjust a few comments slightly, simply to have their
trailing whitespace the same as in the majority of the comments.
2023-08-01 15:35:44 +01:00
Dragan Simic
7783df863a cut: promptly diagnose write errors, continued
* src/cut.c: Complete the error-handling improvements started in
commit e0a4a60af5, by adding a couple of remaining checks for putchar().
While there, sprinkle a few rather useful comments, and perform a few
small code cleanups, to make the code and the comments more uniform
and more conformant to the official coding style.  Also make the help
message slightly more uniform.
2023-08-01 15:34:50 +01:00
Dragan Simic
10dcb0b125 maint: reformat text width in HACKING
* HACKING: Adjust line lengths.
2023-08-01 15:32:21 +01:00
Pádraig Brady
e886b300f7 pinky: fix buffer size on 32 bit builds
* src/pinky.c (idle_string): Use the correct buffer size
following the recent int type adjustment.
2023-08-01 14:59:29 +01:00
Pádraig Brady
89c8c5fff3 od: fix issues with recent format string changes
* src/ioblksize.h: Avoid syntax check with redundant idx.h inclusion.
* src/od.c (FMT_BYTES_ALLOCATED): Increase by two to avoid:
  error: '%s' directive writing between 1 and 2 bytes into a region
  of size between 1 and 4 [-Werror=format-overflow=]
(maint): Use %td to print idx_t rather than invalid %jt format.
2023-08-01 13:30:02 +01:00
Paul Eggert
0b2796750f pinky: prefer signed types
* src/pinky.c (idle_string): Prefer intmax_t to unsigned long int;
this avoids an overflow on platforms where unsigned long is 32
bits and time_t is 64 bits (the bug could occur on such a system
that was idle for more than 6 million years, so it’s a bit
hard to supply a test case...).
2023-07-31 17:51:29 -07:00
Paul Eggert
703d2d6bd4 pathchk: prefer signed types
* src/pathchk.c (validate_file_name): Prefer signed types.
2023-07-31 17:51:29 -07:00
Paul Eggert
244268f719 numfmt: prefer signed types
* src/numfmt.c (suffix_power_char, powerld, expld)
(simple_strtod_int, double_to_human, prepare_padded_number)
(process_suffixed_number): Prefer signed types.
(process_suffixed_number): Fix an unlikely bug if an
arg has exactly 2**32 spaces at the start.
2023-07-31 17:51:29 -07:00
Paul Eggert
df73cf50e9 mktemp,seq: prefer signed types
* src/mktemp.c (main):
* src/seq.c (main): Prefer signed types.
2023-07-31 17:51:28 -07:00
Paul Eggert
a0b8c4ad61 kill: prefer signed types
* src/kill.c (list_signals):
Prefer signed types.  This avoids undefined behavior on
theoretical platforms where unsigned and signed int have
different representations.
2023-07-31 17:51:28 -07:00
Paul Eggert
6387164e5e groups,id: don’t assume gid_t fits in unsigned long
* src/group-list.c (print_group): Convert to intmax_t or
uintmax_t, not to unsigned long.
2023-07-31 17:51:28 -07:00
Paul Eggert
e20d63c442 dircolors,du,expr: prefer signed types
* src/dircolors.c (dc_parse_stream):
* src/du.c (max_depth, main):
* src/expr.c (main):
Prefer signed types.
2023-07-31 17:51:28 -07:00
Paul Eggert
08c325c63b od: prefer signed types
* src/od.c: Include stdckdint.h.
(bytes_to_oct_digits, bytes_to_signed_dec_digits)
(bytes_to_unsigned_dec_digits, bytes_to_hex_digits):
Use ‘char’ for these small constants.
(simple_strtoi): Rename from simple_strtoul.  Convert to int
instead of unsigned long; that’s good enough.  All uses changed.
Simplify by using ckd_mul and ckd_add to check for overflow.
(main): Prefer signed types to unsigned.
2023-07-31 17:51:28 -07:00
Paul Eggert
89f7d44912 cksum,df,digest: prefer signed types
* src/cksum.c (main):
* src/df.c (decode_output_arg):
* src/digest.c (valid_digits):
Prefer idx_t to unsigned types when the value is an index
into an array.
2023-07-31 17:51:28 -07:00
Paul Eggert
73a813e484 join: prefer signed types
* src/join.c (struct outlist, struct field, struct line)
(struct seq, autocount_1, autocount_2, join_field_1, join_field_2)
(extract_field, keycmp, check_order, init_linep, free_spareline)
(getseq, delseq, prfield, prfields, prjoin, join, add_field)
(string_to_join_field, decode_field_spec, add_field_list)
(set_join_field, main):
Prefer signed integers to unsigned.
2023-07-31 17:51:28 -07:00
Paul Eggert
46e5702bf3 factor: prefer signed types
When it’s easy, prefer signed types to unsigned, as
they are less confusing and allow overflow checking.
* src/factor.c (struct mp_factors, udiv_qrnnd)
(count_leading_zeros, count_trailing_zeros)
(factor_insert_multiplicity, mp_factor_clear, mp_factor_insert)
(factor_insert_refind, factor_using_division)
(mp_factor_using_division, powm2, millerrabin, millerrabin2)
(mp_millerrabin, prime_p, prime2_p, mp_prime_p, isqrt, isqrt2)
(invtab, q_freq, factor_using_squfof, strto2uintmax)
(print_factors_single, main):
Prefer signed integers to unsigned.
2023-07-31 17:51:28 -07:00
Paul Eggert
9970fac34b maint: include idx.h everywhere
* src/system.h: Include idx.h here, instead of in every file
that currently uses idx_t.  This should make it easier to use
idx_t in the future.
2023-07-31 17:51:28 -07:00
Paul Eggert
9cbda6e1f8 who: fix only-theoretical overflow
Change stzncpy’s implementation to match its comment, in the case
where SRC + LEN would overflow.  This case never happens in coreutils.
* src/system.h (stzncpy): Work even if SRC + LEN would overflow.
2023-07-31 11:21:43 -07:00
Pádraig Brady
779f34e180 tac: handle short reads on input
This can be reproduced by getting the read() above 2G,
which induces a short read, thus triggering the erroneous failure.

  $ truncate -s 5G 5G

  $ cat 5G | TMPDIR=$PWD tac | wc -c
  tac: /tmp/tacFt7txA: read error: Illegal seek
  0

With the fix in place we now get:

  $ cat 5G | TMPDIR=$PWD src/tac | wc -c
  5368709120

* src/tac.c (tac_seekable): Use full_read() to handle short reads.
* NEWS: Mention the bug fix.
Reported at https://bugs.debian.org/1042546
2023-07-31 18:55:19 +01:00
Bruno Haible
a102826245 uptime: output correct user count on OpenBSD
* src/uptime.c (print_uptime, uptime): Always call read_utmp
and count the result.
* NEWS: Mention the fix (text by Bruno Haible).
2023-07-31 09:28:04 -07:00
Paul Eggert
76c795bf2e build: update gnulib submodule to latest 2023-07-31 09:28:04 -07:00
Paul Eggert
39f5c3f92e build: update gnulib submodule to latest
* NEWS: Mention a bug that this fixes.
2023-07-29 17:23:15 -07:00
Paul Eggert
3cb862ce5f mv: better diagnostic for 'mv dir x' failure
Problem reported by Nir Oren <https://bugs.gnu.org/64785>.
* src/copy.c (copy_internal): Use a more-specific diagnostic when
a rename fails due to a problem that must be due to the
destination, avoiding user confusion in cases like 'mv dir x'
where x is a nonempty directory.
* tests/mv/dir2dir.sh: Adjust to match.
2023-07-22 13:41:07 -07:00
Pádraig Brady
b0e41e3f30 doc: clarify tail -n/-c +NUM operation
tail -n/-c +NUM, is different from tail -n/-c NUM,
and head -n/-c NUM, and head -n/c -NUM, in that it
specifies a 1 based index rather than a count to skip/include.
So clarify this in tail --help and tail info manual.
Note we also mention this gotcha at:
https://www.pixelbeat.org/docs/coreutils-gotchas.html#tail

* doc/coreutils.texi (tail invocation): Give examples for -c/-n +NUM,
to make it clear one has to specify a number 1 larger than
might be expected.
* src/tail.c (usage): State the skip at start edge case more clearly
in the -n description. -c is not often used with tail so we leave
full explanation of that to the info manual.  Also split the string
to simplify translation.
2023-07-20 15:13:01 +01:00
Pádraig Brady
4bf182f92a maint: add a syntax check to prevent use of NULL
* cfg.mk (sc_prohibit_NULL): Direct to use nullptr instead.
2023-07-18 23:13:06 +01:00
Pádraig Brady
8fd50b8672 tests: split: provide more isolated /tmp handling
* tests/split/l-chunk.sh: Move the "expensive" portion to ...
* tests/split/l-chunk-root.sh: .. A new test split from l-chunk.sh
which uses an isolated TMPDIR, rather than exhausting /tmp,
as that gives false positive failures with some other coreutils tests
like tac-2-nonseekable.sh and shuf-reservoir.sh at least.
* tests/local.mk: Reference the new test.
2023-07-18 23:11:24 +01:00
Pádraig Brady
464be62df6 split: honor $TMPDIR for temp files
* bootstrap.conf: Depend on tmpdir rather than tmpfile,
as the standard tmpfile() doesn't honor $TMPDIR.
* src/split.c (copy_to_tmpfile): Adjust to call temp_stream() rather
than tmpfile();
* NEWS: Mention the improvement.
2023-07-18 23:11:24 +01:00
Pádraig Brady
1b86b70dd5 tac: fall back to /tmp if $TMPDIR is unavailable
This also refactors temp_stream() to its own module,
in preparation for use by split.

* src/tac.c: Refactor temp_stream() out to ...
* src/temp-stream.c: ... A new module mostly refactored from tac,
but uses tmpdir to more robustly support $TMPDIR,
while falling back to /tmp if not available.
* src/temp-stream.h: The new module interface.
* src/local.mk: Reference the new module from tac.
* tests/tac/tac.pl: Adjust to non failing missing $TMPDIR.
* po/POTFILES.in: Reference the new module with translatable strings.
* NEWS: Mention the user visible improvements to tac TMPDIR handling.
2023-07-18 23:10:40 +01:00
Pádraig Brady
47e1388d6f maint: add syntax check to ensure safe mkstemp usage
One needs to include stdlib--.h if using mkstemp()
lest one hits esoteric bugs with closed stdin etc.

* cfg.mk (sc_require_stdlib_safer): Add a new syntax check.
(sc_require_stdio_safer): Fix this; broken since commit fa7ed969c3.
2023-07-18 18:59:10 +01:00
Pádraig Brady
02a4ebd6c4 join: promptly diagnose write errors
* src/join.c (prjoin): Check for write errors after each line.
* tests/misc/write-errors.sh: enable the test for join.
* NEWS: Mention the improvement.
2023-07-17 11:28:36 +01:00
Pádraig Brady
b1df1d557e comm: promptly diagnose write errors
* src/comm.c (writeline): Simplify by removing the unneeded STREAM
parameter.  Call write_error() upon ferror().
(compare_files): Adjust to simplified writeline().
* tests/misc/write-errors.sh: Enable comm test.
* NEWS: Mention the improvement.
2023-07-17 11:28:36 +01:00
Pádraig Brady
e0a4a60af5 cut: promptly diagnose write errors
* src/cut.c (cut_bytes): Diagnose errors from fwrite() and putchar().
(cut_fields): Likewise.
* tests/misc/write-errors.sh: Enable the test for cut,
and augment to cover both cut_bytes() and cut_fields().
* NEWS: Mention the improvement.
2023-07-17 11:28:36 +01:00
Pádraig Brady
ca7711456f uniq: promptly diagnose write errors
* src/uniq.c (write_line): Check the output from fwrite() immediately.
(check_file): Likewise.
* tests/misc/write-errors.sh: Enable the test case.
* NEWS: Mention the improvement.
2023-07-17 11:28:36 +01:00
Pádraig Brady
a03c00023a od: promptly diagnose write errors
* src/od.c (dump): Check for write errors after each block written,
to exit early even with large / unbounded inputs.
* tests/misc/write-errors.sh: enable od check.
* NEWS: Mention the improvement.
Fixes https://bugs.gnu.org/64540
2023-07-17 11:28:36 +01:00
Pádraig Brady
0b2ff7637f all: avoid repeated diagnostic upon write error
* cfg.mk (sc_some_programs_must_avoid_exit_failure): Adjust to
avoid false positive.
(sc_prohibit_exit_write_error): A new syntax check to prohibit
open coding error(..., "write error"); instead directing to use...
* src/system.h (write_error): ... a new function to clear stdout errors
before we explicitly diagnose a write error and exit.
* src/basenc.c: Use write_error() to ensure no repeated diagnostics.
* src/cat.c: Likewise.
* src/expand.c: Likewise.
* src/factor.c: Likewise.
* src/paste.c: Likewise.
* src/seq.c: Likewise.
* src/shuf.c: Likewise.
* src/split.c: Likewise.
* src/tail.c: Likewise.
* src/tr.c: Likewise.
* src/unexpand.c: Likewise.
* tests/misc/write-errors.sh: Remove TODOs for the fixed utilities:
expand, factor, paste, shuf, tr, unexpand.
2023-07-17 11:28:36 +01:00
Pádraig Brady
ef47b928d0 tests: ensure utilties exit promptly upon write error
* tests/local.mk: Reference the new test.
* tests/misc/write-errors.sh: A new test to ensure utilities
exit promptly upon writing to /dev/full.
2023-07-17 11:28:30 +01:00
Jim Meyering
c0e7e4a1d4 cksum: improve problematic_chars function
* src/digest.c (problematic_chars): Implement using strcspn,
and traversing S only once, rather than once per escaped byte.
2023-07-13 22:39:04 -07:00
Pádraig Brady
ebd776a422 maint: give a new function the "pure" attribute
* src/digest.c (problematic_chars): This recently introduced
function does not modify state so is pure, even though GCC 13.1 at least
did not warn about that attribute being appropriate.
2023-07-12 20:41:00 +01:00
Pádraig Brady
86614ba1c2 cksum: escape filenames with a leading '\' in --check status
* src/digest.c (digest_check): Also escape in the case that the
file name contains '\'.
* tests/cksum/md5sum-bsd.sh: Add a test case.
* doc/coreutils.texi (md5um invocation): Clarify escaping operation.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/64392
2023-07-11 12:16:41 +01:00
Pádraig Brady
5e1e0993b5 cksum: support transparent emulation of older utils
Support -b, --binary, and -t, --text
to allow full emulation of older utilities with:
  exec cksum -a $algo --untagged "$@"
Note this would diverge from OpenBSD's support of cksum -b.

* src/digest.c: Change -b to mean --binary, not --base64 in all cases.
Accept -b and -t in all cases.  Keep --binary and --text undocumented
for cksum.
* tests/cksum/cksum-base64.pl: s/-b/--base64/.
* tests/cksum/cksum-a.sh: Ensure cksum supports -b and -t appropriately.
* NEWS: Mention the change in behavior.
2023-07-09 14:33:14 +01:00
Pádraig Brady
2f1cffe07a maint: avoid static analysis failure for ignored dup2 return
* src/sort.c: We're ignoring failures from these calls,
so do so explicitly to avoid static analysis issues
as reported by coverity.
2023-07-08 13:42:51 +01:00
Sylvestre Ledru
1ac8630f1e tests: mktemp -t: $TMPDIR has higher priority than -p
* tests/misc/mktemp.pl: Ensure that with -t,
$TMPDIR has precedence over -p.
2023-07-04 12:11:16 +01:00
Paul Eggert
80a6c7faa2 maint: update .gitignore
Add some newly-created Gnulib files,
plus some bootstrap temporaries.
2023-07-01 11:51:17 -07:00
Paul Eggert
57ffc40323 stty: fix untranslated diagnostics
* src/stty.c (set_speed): Translate diagnostics.
2023-07-01 11:51:17 -07:00
Paul Eggert
6380a66a7d maint: sync bootstrap from Gnulib
* bootstrap: Copy from gnulib/build-aux/bootstrap.
2023-07-01 11:51:17 -07:00
Paul Eggert
d727aba601 maint: prefer ckd_add to INT_ADD_WRAPV etc
* bootstrap.conf (gnulib_modules): Add stdckdint.
Also, in C source code, prefer C23 macros like ckd_add
to their Gnulib near-equivalents like INT_ADD_WRAPV.
Include <stdckdint.h> as needed.
2023-07-01 11:51:16 -07:00
Paul Eggert
123d03dca4 who: don’t crash if clock gyrates
* src/who.c (idle_string): Avoid signed integer overflow
if the superuser messes with the clock in bizarre ways.
Remove an ‘assume’ that wasn’t correct under this scenario.
2023-07-01 11:51:16 -07:00
Paul Eggert
c0285a7136 df: omit GCC 5 ‘assume’s
* src/df.c (main):
* src/shred.c (dopass):
Omit ‘assumes’ needed to pacify GCC 5 but not needed with GCC 13.
2023-07-01 11:51:16 -07:00
Paul Eggert
17aaba6a41 maint: pacify GCC bug#109613 better
* src/cut.c (cut_file):
* src/nl.c (nl_file): Pacify GCC Bug#109613 in a better way, by
narrowing the coverage of the ‘assume’ so that bugs in the
no-longer-covered part are not masked.
2023-07-01 11:51:16 -07:00
Paul Eggert
d438486cb5 maint: stop pacifying Parfait
* src/fmt.c (get_paragraph):
* src/stty.c (display_changed, display_all): Omit calls to
‘assume’ that are present only to pacify false positives by Parfait
<https://labs.oracle.com/pls/apex/f?p=94065:12:17236785746387:13>,
which went in-house in 2012 and never came back.
2023-07-01 11:51:16 -07:00
Paul Eggert
a44b866b11 build: update gnulib submodule to latest 2023-07-01 11:51:16 -07:00
Paul Eggert
6d61667d0d maint: go back to using ‘error’
Now that Gnulib’s ‘error’ module does proper static checking
for not returning, we need no longer use the ‘die’ macro.
This makes code easier to read for people that are used to ‘error’.
* cfg.mk (error_fns, exclude_file_name_regexp): Remove ‘die’.
(sc_die_EXIT_FAILURE): Remove.
* src/die.h: Remove.  All includes removed.  All calls to ‘die’
changed back to calls to ‘error’.
* src/install.c (get_ids): Use quoteaf (problem found with
make syntax-check).
* src/system.h: Include error.h, since some of our macros call ‘error’.
Stop including error.h elsewhere.
2023-07-01 11:51:16 -07:00
Paul Eggert
478055dc30 maint: improve static and dynamic checking
This modernizes the source code somewhat, to take advantage
of advances in GCC over the years, and Gnulib’s ‘assure’ module.
Include assure.h in files that now need it.
Do not include assert.h directly; it’s no longer needed.
* bootstrap.conf (gnulib_modules): Add ‘assure’.
* gl/lib/randread.c (randread_error):
* src/chmod.c (describe_change):
* src/chown-core.c (describe_change):
* src/cp.c (decode_preserve_arg):
* src/head.c (diagnose_copy_fd_failure):
* src/ls.c (parse_ls_color):
* src/od.c (decode_one_format):
* src/split.c (main):
* src/test.c (binary_operator, posixtest):
Prefer affirm to abort, since it has better diagnostics in the
normal case and better performance with -DNDEBUG.
* gl/lib/xdectoint.c, src/die.h: Include stddef.h, for unreachable.
* gl/lib/xdectoint.c: Do not include verify.h; no longer needed.
* gl/lib/xdectoint.c (__xnumtoint):
* src/die.h (die):
Prefer C23 unreachable () to assume (false).
* gl/lib/xfts.c (xfts_open):
* src/basenc.c (base32hex_encode):
* src/copy.c (abandon_move, copy_internal, valid_options):
* src/cut.c (cut_fields):
* src/df.c (alloc_field, decode_output_arg, get_dev):
* src/du.c (process_file, main):
* src/echo.c (usage):
* src/factor.c (udiv_qrnnd, mod2, gcd2_odd, factor_insert_large)
(mulredc2, factor_using_pollard_rho, isqrt2, div_smallq)
(factor_using_squfof):
* src/iopoll.c (iopoll_internal, fwrite_wait):
* src/join.c (add_field):
* src/ls.c (dev_ino_pop, main, gobble_file, sort_files):
* src/mv.c (do_move):
* src/od.c (decode_format_string, read_block, dump, main):
* src/remove.c (rm):
* src/rm.c (main):
* src/sort.c (stream_open):
* src/split.c (next_file_name, lines_chunk_split):
* src/stdbuf.c (main):
* src/stty.c (set_speed):
* src/tac-pipe.c (line_ptr_decrement, line_ptr_increment):
* src/touch.c (touch):
* src/tr.c (find_bracketed_repeat, get_next)
(validate_case_classes, get_spec_stats, string2_extend, main):
* src/tsort.c (search_item, tsort):
* src/wc.c (main):
Prefer affirm to assert, as it allows for better static
checking when compiling with -DNDEBUG.
* src/chown-core.c (change_file_owner):
* src/df.c (get_field_list):
* src/expr.c (printv, null, tostring, toarith, eval2):
* src/ls.c (time_type_to_statx, calc_req_mask, get_funky_string)
(print_long_format):
* src/numfmt.c (simple_strtod_fatal):
* src/od.c (decode_one_format):
* src/stty.c (mode_type_flag):
* src/tail.c (xlseek):
* src/tr.c (is_char_class_member, get_next, get_spec_stats)
(string2_extend):
Prefer unreachable () to abort () or assert (false) when merely
pacifying the compiler, e.g., in a switch statement on an enum
where all cases are covered.
* src/copy.c (valid_options): Now returns void; the bool was useless.
Caller no longer needs to assert.
* src/csplit.c (find_line):
* src/expand-common.c (next_file):
* src/shred.c (incname):
* src/sort.c (main):
* src/tr.c (append_normal_char, append_range, append_char_class)
(append_repeated_char, append_equiv_class):
* src/tsort.c (search_item):
Omit assert, since the hardware will check for us.
* src/df.c (header_mode): Now the enum type it should have been.
* src/du.c (process_file):
* src/ls.c (assert_matching_dev_ino):
* src/tail.c (valid_file_spec):
* src/tr.c (validate_case_classes):
Mark defns with MAYBE_UNUSED if they’re not used when -DNDEBUG.
* src/factor.c (prime_p, prime2_p, mp_prime_p): Now ATTRIBUTE_PURE.
Prefer affirm to error+abort.  No need to translate this diagnostic.
* src/fmt.c (get_paragraph):
* src/stty.c (display_changed, display_all, sane_mode):
* src/who.c (idle_string):
Prefer assume to assert, since the goal is merely pacification
and assert doesn’t pacify anyway if -DNDEBUG is used.
* src/join.c (decode_field_spec):
Omit unreachable abort.
* src/ls.c (assert_matching_dev_ino, main):
* src/tr.c (get_next):
Prefer assure to assert, since the check is relatively expensive
and won’t help static analysis.
* src/ls.c (main):
Prefer static_assert to assert of a constant expression.
(format_inode): Redo to make it clear that buflen doesn’t matter,
and that buf must have a certain number of bytes.  All callers changed.
This pacifies -Wformat-overflow.
* src/od.c (decode_one_format):
Omit an assert that tested for obviously undefined behavior,
as the compiler could optimize it away anyway.
* src/od.c (decode_one_format, decode_format_string):
Prefer ATTRIBUTE_NONNULL to runtime checking.
* src/stat.c: Do not include <stddef.h> since system.h does that now.
* src/sync.c (sync_arg):
Prefer unreachable () to assert (true), which was a typo.
* src/system.h: Include stddef.h, for unreachable.
* src/tail.c (xlseek): Simplify by relying on ‘error’ to exit.
2023-07-01 11:51:15 -07:00
Paul Eggert
2522c1db68 maint: fix indenting in previous change
* src/ptx.c: Adjust to fit into 80 columns.
2023-07-01 11:51:14 -07:00
Paul Eggert
16b5ca6e0d maint: prefer C23-style nullptr
* bootstrap.conf (gnulib_modules): Add nullptr.
In code, prefer nullptr to NULL where either will do.
2023-06-29 15:29:29 -07:00
Bruno Haible
e600fbb764 build: ensure that makeinfo ≥ 6.8 checks the @menu structure
See <https://lists.gnu.org/r/bug-texinfo/2023-06/msg00015.html>.

* doc/local.mk (MAKEINFO): New variable.
* cfg.mk (_makefile_at_at_check_exceptions): Update.
2023-06-22 23:22:07 +01:00
Pádraig Brady
e8858f1515 b2sum: fix UAR with --check with malformed checksum lines
* src/digest.c (split_3): Reinstate the check for whitespace after the
digest portion of the line, so that we exit early before inspecting
the file name which would be outside the passed buffer in the case
where the input does not contain a newline.
* tests/cksum/b2sum.sh: Add a test case.
* NEWS: Mention the bug fix.
* THANKS.in: Add Frank Busse who has reported multiple bugs using KLEE.
Fixes https://bugs.gnu.org/64229
2023-06-22 23:22:07 +01:00
Paul Eggert
ed9d8b8730 maint: update GCC bug number in comment 2023-06-21 00:08:21 -07:00
Paul Eggert
3638944ff5 doc: mention fix for bug#64123 2023-06-19 23:24:02 -07:00
Paul Eggert
5ac7f2d281 build: update gnulib submodule to latest 2023-06-19 23:24:02 -07:00
Sylvestre Ledru
15925d0e5b tests: move tests to a directory per utility
* cfg.mk: Adjust syntax check exclusion paths.
* tests/local.mk: Adjust for renamed tests.
2023-06-19 13:12:37 +01:00
Pádraig Brady
d53190ed46 doc: mention cksum error fix with cpu feature checks changes
* NEWS: Mention the error message to aid those searching
for solutions to the issue, and mention cksum also
as that was confirmed to fix the error with the adjusted
cpu feature detection, as discussed at https://bugs.debian.org/1037264
* src/cksum.c: Cleanup syntax-check failure from previous commit.
2023-06-15 01:00:05 +01:00
Paul Eggert
f780a85985 cksum,wc: clean up hw capability checking
* src/cksum.c (cksum_pclmul) [!CRCTAB && !USE_PCLMUL_CRC32]:
Remove macro.
(cksum_fp): No longer file-scope.
(pclmul_supported): Define only if USE_PCLMUL_CRC32.
This omits the debug output "using generic hardware support"
for simplicity and consistency with wc’s output.
(crc_sum_stream) [!USE_PCLMUL_32]: No need for static function pointer.
* src/wc.c (wc_lines_p) [USE_AVX2_WC_LINECOUNT]: No longer file-scope.
(wc) [USE_AVX2_WC_LINECOUNT]: Check for avx2 support at most once,
which was surely the code’s original intent.
(wc) [!USE_AVX2_WC_LINECOUNT]: No need for static function pointer.
2023-06-14 14:54:46 -07:00
Paul Eggert
4ac941565f cksum,wc: don’t include <cpuid.h>
* src/cksum.c [!CRCTAB && USE_PCLMUL_CRC32]:
* src/wc.c [USE_AVX2_WC_LINECOUNT]:
Don’t include <cpuid.h>; no longer needed.
2023-06-14 14:54:46 -07:00
Paul Eggert
7814596fa9 cksum: fix bug in check for cksum_pclmul
This fixes a typo in the previous patch.
Problem reported by Pádraig Brady <https://bugs.gnu.org/64058#11>.
* src/cksum.c (pclmul_supported): Also require AVX support
to use cksum_pclmul.
2023-06-14 14:54:46 -07:00
Paul Eggert
91a74d3614 wc: port to kernels that disable XSAVE YMM
Problem reported by Dave Hansen <https://bugs.gnu.org/64058>.
Apply similar change to cksum and pclmul, too.
* NEWS: Mention wc fix.
* configure.ac (cpuid_exists, get_cpuid_count_exists):
Remove.  All uses removed, since we no longer use __get_cpuid or
__get_cpuid_count.
(pclmul_intrinsic_exists, avx2_intrinsic_exists): Set to no if
__builtin_cpu_supports calls cannot be compiled.
(HAVE_PCLMUL_INTRINSIC, HAVE_AVX2_INTRINSIC): Remove; unused.
Simplify surrounding code because of this.
* src/cksum.c (pclmul_supported):
* src/wc.c (avx2_supported):
Use __builtin_cpu_supports instead of doing it by hand.
Simplify surrounding code because of this.
2023-06-13 21:14:29 -07:00
Ville Skyttä
3789024073 dircolors: update list of backup file extensions
* src/dircolors.hin: Sort backup section by extension.
Treat .dpkg-new and .dpkg-tmp as backup files.
Treat .crdownload (Chromium based browsers' partial download)
as a backup file.
2023-06-12 21:55:51 +01:00
Pádraig Brady
e8e81fc44b dd: fix parsing of numbers with more than two multipliers
* src/dd.c (parse_integer): Use recursion to support more than two
multipliers.  Also protect suffix[-1] access to ensure we don't
inspect before the passed string.
* tests/dd/bytes.sh: Add test cases.
* doc/coreutils.texi (dd invocation): Note the support for specifying
many multipliers in a number.
* NEWS: Mention the bug fix.
Fixes https://bugs.debian.org/1037275
2023-06-11 23:10:34 +01:00
Pádraig Brady
b841f111de build: update gnulib submodule to latest
* gnulib: Update to latest.
* po/POTFILES.in: Remove recent sc_po_check workaround.
* tests/misc/date-debug.sh: Adjust as per spelling fix.
2023-06-09 11:27:35 +01:00
Pádraig Brady
66ea09b0fe doc: od --strings: clarify operation
* doc/coreutils.texi (od invocation): Remove mention of ASCII,
as all printable characters in unibyte locales are output.
* src/od.c (usage): Clarify that only NUL terminated strings
are displayed, and that it's printable chars, not only graphic chars
that are output. I.e., spaces are output also if part of the string.
Reported at https://bugs.ddebian.org/1037217
2023-06-08 11:06:20 +01:00
Pádraig Brady
c2173c0a52 maint: ls.c: update stale comment for previous commit
* src/ls.c (gobble_file): Update comment to correspond with
the changes in the previous commit.
2023-06-07 21:51:47 +01:00
Pádraig Brady
bf574deec8 ls: display command line symlinks that return ELOOP
* src/ls.c (gobble_file): Ensure we lstat() a symlink
specified on the command line, if we receive ELOOP from stat().
* tests/ls/symlink-loop.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/63931
2023-06-07 19:59:40 +01:00
Pádraig Brady
e1e21f6dff ls: use more standard symlink traversal
* src/ls.c (gobble_file): stat() symlinks directly,
rather than their targets.  This will be more consistent
with how symlinks are generally accessed.
(make_link_name): Remove no longer used function.
Addresses https://bugs.gnu.org/63931
2023-06-07 19:59:30 +01:00
Pádraig Brady
6c975de166 doc: reference COPYING from README
* README: Reference COPYING as per the GNU coding standards,
and soon to be enforced with a syntax-check from gnulib.
2023-06-07 16:05:15 +01:00
Pádraig Brady
6a61883757 maint: avoid syntax-check failure
* po/POTFILES.in: Add lib/propername.h due to new comments
that trigger sc_po_check.
2023-06-06 11:34:09 +01:00
Pádraig Brady
3621d51c9d doc: NEWS: mention the more defensive copy_file_range avoidance
* NEWS: Mention the improvement in reinstating runtime avoidance
of copy_file_range(), that came with the last gnulib update,
picking up gnulib commit fb034b35.
2023-06-06 11:16:39 +01:00
Paul Eggert
e8909df3ce build: update gnulib submodule to latest 2023-06-05 22:44:22 -07:00
Pádraig Brady
4d12f4df0c maint: use consistent make variable interpolation syntax
* cfg.mk: Prefer $() interpolation over ${}
lest the reader is confused as to whether shell interpolation,
i.e. $${} was intended.
2023-06-01 13:21:12 +01:00
Pádraig Brady
0147288d20 split: --additional-suffix: disallow trailing '/'
Note mktemp --suffix has the same inconsistency,
but mktemp -d does support creating dirs
so probably best to leave that as is.

* src/split.c (main): Check for trailing /.
* tests/split/additional-suffix.sh: Augment the test.
Reported in https://bugs.debian.org/1036827
2023-05-31 17:26:13 +01:00
Pádraig Brady
d055228e34 maint: adjust code to handle "error" syntax-check changes
* src/dd.c: Don't include no longer used error.h.
Use quoteaf() rather than quote() to quote appropriate for the shell
and to avoid the syntax-check failure,
* src/stty.c: Use quoteaf() rather than quotef()
to have more consistent quoting of the invalid arg.
2023-05-31 17:24:13 +01:00
Pádraig Brady
b7c8eb0046 maint: augment syntax checks to cater for more "error" functions
src/cfg.mk (sc_error_quotes, sc_error_shell_quotes,
sc_error_shell_always_quotes): Include "die" and "diagnose"
in the class of error functions to check arguments for.
2023-05-31 17:20:09 +01:00
Paul Eggert
48f5a39872 dd: fix ‘error’ name issue without macros
* src/dd.c (_GL_NO_INLINE_ERROR): Remove; no longer needed.
(diagnose): Rename from nl_error and omit first arg since it is
always zero.  All uses changed.
(error): Remove macro.
2023-05-30 14:25:03 -07:00
Pádraig Brady
fe18d3982a build: update gnulib submodule to latest
* gnulib: Update to latest.
* src/dd.c: Avoid error macro redefinition.
2023-05-28 15:03:00 +01:00
Pádraig Brady
17479ef60c build: modernize bootstrap prerequsite tools
Following on from commit v9.0-15-gaa31b919c
which updated README-prereq...

* bootstrap.conf: Add an explicit requirement on m4.
Add an explicit requirement on texi2pdf which is often
packaged separately to makeinfo and induces a failure
far down the distribution phase if not present.
Replace the rsync dependency with wget,
which gnulib changed to in 2018.
2023-05-19 22:20:07 +01:00
Pádraig Brady
d5d9b67eec build: update gnulib submodule to latest
* gnulib: Update to latest.
* configure.ac: Remove gnulib reference, as that specific issue
is now explicitly avoided in gnulib itself.
2023-05-19 18:40:53 +01:00
Pádraig Brady
76e1200eeb build: pacify GCC 13 with -flto
* src/cut.c (cut_file): Explicitly mark STREAM as nonnull to avoid
-Werror=null-dereference.
* src/nl.c (nl_file): Likewise.
2023-05-19 11:32:14 +01:00
Pádraig Brady
ba0527d4ca build: revert -Wmaybe-uninitialized warnings avoidance
This reverts commit 800c86d5, as that was deemed too invasive.
We do keep the change to tee.c to allow using -O3 without warnings.
For other optimization options like -O0, -Og, -O1, -Os,
one can use WERROR_CFLAGS= to stop warnings inducing a build failure.
2023-05-19 09:58:50 +01:00
Pádraig Brady
800c86d5fa build: avoid false -Wmaybe-uninitialized warnings
Allow easily building a debug build for example with:
  make CFLAGS='-O0 -ggdb'

False -Wmaybe-uninitialized warnings hit in different
places depending on the compiler passes used.
These changes were tested with gcc 10.2.1, 12.2.1, and 13.1.1 like:
  for o in g s z fast 0 1 2 3; do
    make clean && make -j$(nproc) CFLAGS="-O$o" || break
  done

* src/digest.c: Disable -Wmaybe-uninitialized that gives
false positive here at -O0.
* src/ln.c: Avoid -Wmaybe-uninitialized that gives
false positive here at -O1.
* src/pr.c: Likewise.
* src/sort.c: Likewise.
* src/tee.c: Avoid -Wmaybe-uninitialized that gives
false positive here at -O3 on gcc 13.1.1 at least.
* src/cp.c: Avoid -Wmaybe-uninitialized that gives
false positive here at -Os on gcc 13.1.1 at least.
* src/copy.c: Avoid -Wmaybe-uninitialized that gives
false positive here at -Og on gcc 13.1.1 at least.
* src/head.c: Likewise.
* src/paste.c: Likewise.
2023-05-18 12:13:47 +01:00
Pádraig Brady
aed3b8190a build: gnulib: avoid false -Wstringop-overflow warning
Tested on gcc 13.1.1 with: make CFLAGS='-O0 -ggdb'

* configure.ac: Disable -Wstringop-overflow for gnulib.
This warning is far too problematic in my experience:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
and triggers with gcc -O0 with versions 12,13 at least.
2023-05-18 11:57:26 +01:00
Pádraig Brady
f218412b9a maint: cleanups to NEWS
* NEWS: Use more consistent wording, ordering, and formatting
for recent entries.
2023-05-13 10:33:14 +01:00
Pádraig Brady
059e53e5b4 split: advise the kernel of sequential access pattern
As split is often dealing with large files,
ensure we indicate to the kernel our sequential access pattern.
This was seen to operate 5% faster when reading from SSD,
as tested with:

dd bs=1M count=2K if=/dev/urandom of=big.in

for split in split.orig split; do
  # Ensure big file is not cached
  dd of=big.in oflag=nocache conv=notrunc,fdatasync count=0 status=none
  # Test read efficiency
  CWD=$PWD; (cd /dev/shm && time $CWD/src/$split -n2 $CWD/big.in)
done

real    0m9.039s
user    0m0.055s
sys     0m3.510s

real    0m8.568s
user    0m0.056s
sys     0m3.752s

* src/split.c (main): Use fdadvise to help the kernel
choose a more appropriate readahead buffer.
* NEWS: Mention the improvement.
2023-05-08 21:34:58 +01:00
Pádraig Brady
ba128e628c doc: adjust build instructions for disabling year 2038 support
* README-install: Adjust the instructions as per recent gnulib updates.
2023-05-08 12:57:56 +01:00
Bernhard Voelker
3f942cd03f build: update gnulib submodule to latest
This fixes failures in "very-expensive" tests on FTS with many
directory entries:
  FAIL: tests/rm/ext3-perf
  FAIL: tests/rm/many-dir-entries-vs-OOM

The following shows the problem in the former of the above tests:
  $ mkdir d && seq 400000 | env -C d xargs touch )
  $ rm -rf d
  rm: traversal failed: d: Operation not supported

Gnulib commit 3f0950f65abb (2023-04-26) introduced this regression
which was fixed again with gnulib commit d4d8abb39eb0.

See discussion in
<https://lists.gnu.org/r/bug-gnulib/2023-05/msg00040.html>

* bootstrap.conf (gnulib_modules): Change "year2038-required" to
"year2038-recommended"; the module has been replaced.
* gnulib: Update to latest.
* tests/init.sh: Likewise.
2023-05-07 23:07:12 +02:00
Paul Eggert
42f33ae68c doc: time zone conversion example
* doc/coreutils.texi (Examples of date):
Give time zone conversion example.
2023-05-07 09:17:27 -07:00
Paul Eggert
7edec89fc3 doc: new subsection for date format specs
* doc/coreutils.texi (Date format specifiers): New subsection,
which groups the date format specifiers without otherwise
changing contents.
2023-05-07 09:17:26 -07:00
Pádraig Brady
fae65623a9 pr: fix parsing of empty arguments
Before:
  $ pr --expand-tabs=
  pr: '-e' extra characters or invalid number in the argument:
   ‘SHELL=/bin/bash’: Value too large for defined data type

After:
  $ pr --expand-tabs=
  pr: '-e': Invalid argument: ‘’

* src/pr.c (getoptarg): Ensure we don't parse beyond the
end of an empty argument, thus outputting arbitrary stack
info in subsequent error messages.

Addresses https://bugs.debian.org/1035596
2023-05-06 11:26:04 +01:00
Paul Eggert
300af78691 cp: -p --parents: minor cleanup of previous patch
This doesn’t change behavior; it just clarifies the code a bit.
* src/cp.c (re_protect): New arg DST_SRC_NAME, for clarity, and so
that we need to skip '/'s only once.  Caller changed.
Rename a couple of local variables to try to make things clearer.
2023-05-05 11:05:03 -07:00
Pádraig Brady
c6b1fe4347 cp: -p --parents: fix failure to preserve permissions for absolute paths
* src/cp.c (re_protect): Ensure copy_acl() is passed an absolute path.
* tests/cp/cp-parents.sh: Add a test case.
* NEWS: Mention the bug.
Fixes https://bugs.gnu.org/63245
2023-05-03 18:15:59 +01:00
Pádraig Brady
7223651ad1 tests: provide more info on DEBUG=yes
* README: State that DEBUG=yes is particularly useful with perl tests.
* tests/split/l-chunk.sh: Use the more standard $DEBUG variable
rather than an internal $DEBUGGING variable.
2023-05-02 22:39:03 +01:00
Pádraig Brady
6d683a1d02 doc: provide more info on the default 32-bit cksum digest
* doc/coreutils.texi (cksum invocation): Say that the default
digest format is 32-bit and based on the Ethernet standard CRC.
2023-04-30 22:10:25 +01:00
Pádraig Brady
2cae0419c9 maint: remove redundant exit status handling
* src/numfmt.c: Remove redundant / confusing
use of TIMEOUT_FAILURE.
2023-04-30 13:05:12 +01:00
Paul Eggert
35adc746a0 maint: simplify --enable-gcc-warnings='expensive'
* configure.ac (WERROR_CFLAGS): Omit mention of
-Wno-analyzer-double-free, -Wno-analyzer-null-dereference, and
-Wno-analyzer-use-after-free as manywarnings no longer uses them.
2023-04-26 18:20:20 -07:00
Paul Eggert
21e7573508 maint: suppress GCC 13 false alarms
* src/csplit.c, src/fmt.c, src/make-prime-list.c, src/nohup.c:
Add pragmas to pacify GCC 13 when coreutils is configured
with --enable-gcc-warnings='expensive'.
2023-04-26 18:20:20 -07:00
Paul Eggert
6c199713ed chmod: pacify GCC 13
* src/chmod.c (main): Use xpalloc instead of X2REALLOC,
and make the corresponding variables signed instead of unsigned.
When reallocating the buffer, this grows it by a factor of 1.5, not 2.
This also pacifies gcc -Wanalyzer-null-dereference.
2023-04-26 18:20:19 -07:00
Paul Eggert
d178b49754 csplit: pacify GCC 13
* src/csplit.c (load_buffer): Refactor for clarity.
This also xpacifies gcc -Wanalyzer-use-of-uninitialized-value.
When reallocating the buffer, grow it by a factor of 1.5, not 2.
2023-04-26 18:20:19 -07:00
Paul Eggert
941027eeb7 build: update gnulib submodule to latest 2023-04-26 18:20:19 -07:00
Pádraig Brady
5e1c5f2d71 tests: more cases for read input diagnostics
* tests/misc/read-errors.sh: Exercise more modes of
various utilities for better read error coverage.
* tests/split/fail.sh: Remove part refactored into the above test.
2023-04-26 16:20:50 +01:00
Pádraig Brady
4eb5abbff4 uniq: be more specific when diagnosing read errors
* src/uniq.c (check_file): Use the errno when diagnosing read errors.
2023-04-26 16:19:51 +01:00
Jaroslav Skarvada
b16553cdad build: fix build with -mno-ssse3
Avoid the following error with -mno-ssse3:
 inlining failed in call to 'always_inline' '_mm_shuffle_epi8':
 target specific option mismatch

* configure.ac: Ensure we use ssse3 specific code when
checking whether to enable the pclmul cksum implementation.
2023-04-26 13:51:42 +01:00
Pádraig Brady
3fb0cc80fa pr: fix infinite loop when double spacing
* src/pr.c (init_parameters): Ensure we avoid a 0 lines_per_body
which was possible when adjusting for double spacing.
That caused print_page() to always return true,
causing an infinite loop.
* tests/pr/pr-tests.pl: Add a test case.
* NEWS: Mention the fix.
Fixes https://bugs.debian.org/1034808
2023-04-25 14:18:35 +01:00
Pádraig Brady
cc078f747f copy: reduce verbosity of -i and -u with --verbose
Since skipping of files is central to the operation of -i and -u,
and with -u one may be updating few files out of many,
reinstate the verbosity of this functionality as it was before 9.3.

* src/copy.c (copy_internal): Only output "skipped" message
with --debug.  Also adjust so message never changes with --debug.
* tests/cp/cp-i.sh: Adjust accordingly.
* tests/mv/mv-n.sh: Likewise.
* tests/cp/debug.sh: Add explicit test case for message.
* NEWS: Mention the change in behavior.
2023-04-25 11:17:54 +01:00
Pádraig Brady
7ea7c020e8 tests: ensure all utilities that read input diagnose errors
* tests/misc/read-errors.sh: Add a new test.
* tests/misc/date-f.sh: Remove unneeded test.
* tests/misc/dircolors.sh: Likewise.
* tests/local.mk: Reference new test, and dereference removed ones.
2023-04-24 11:46:28 +01:00
Pádraig Brady
82e1750daa factor: diagnose errors reading the input
* src/factor.c (do_stdin): Exit with failure upon read errors.
* NEWS: Mention the bug fix.
2023-04-24 11:46:28 +01:00
Pádraig Brady
5595673d5c numfmt: diagnose errors reading the input
* src/numfmt.c (main): Exit with failure upon read errors.
* NEWS: Mention the bug fix.
2023-04-24 11:46:28 +01:00
Pádraig Brady
0e62ba282e tsort: diagnose errors reading the input
* src/tsort.c (tsort): Check for errors after readtoken().
* NEWS: Mention the bug fix.
2023-04-24 11:46:28 +01:00
Pádraig Brady
9d333aca43 cksum: fix failure to diagnose read errors with crc32
The default crc32 mode fails to diagnose read errors.

* src/cksum.c (cksum_slice8): Fix the check for read errors.
(cksum_pclmul): Likewise.
* NEWS: Mention the bug fix.
2023-04-24 11:46:28 +01:00
Andreas Schwab
e29f4411c8 tests: avoid failure when cp fails for proc files
When run under QEmu emulation emulated /proc files have
unstable inode numbers.

* tests/cp/proc-short-read.sh: Skip if unstable inode numbers detected.
2023-04-24 11:37:09 +01:00
Pádraig Brady
6bab375973 install: support stripping files with a leading hyphen
* src/install.c (strip): Prepend "./" to file names with a leading "-".
* tests/install/strip-program.sh: Add a test case.
* NEWS: Mention the bug fix.
Reported in https://bugs.debian.org/1034429
2023-04-21 19:13:52 +01:00
Pádraig Brady
f6229adb09 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2023-04-18 15:32:53 +01:00
860 changed files with 10497 additions and 9363 deletions

View File

@@ -13,7 +13,7 @@ Before reporting a new bug, please check the following resources:
* Coreutils FAQ: https://www.gnu.org/software/coreutils/faq/coreutils-faq.html
* Coreutils Gotchas: https://www.pixelbeat.org/docs/coreutils-gotchas.html
contains a list of some quirks and unexpected behaviour (which are often
contains a list of some quirks and unexpected behavior (which are often
mistaken for bugs).
* Online Manual:
@@ -68,7 +68,7 @@ When sending messages to coreutils@gnu.org or bug-coreutils@gnu.org :
<!--
Copyright (C) 2017-2023 Free Software Foundation, Inc.
Copyright (C) 2017-2024 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

@@ -22,7 +22,7 @@ contributing to the GNU Project, please read
* Coreutils FAQ: https://www.gnu.org/software/coreutils/faq/coreutils-faq.html
* Coreutils Gotchas: https://www.pixelbeat.org/docs/coreutils-gotchas.html
contains a list of some quirks and unexpected behaviour (which are often
contains a list of some quirks and unexpected behavior (which are often
mistaken for bugs).
* Online Manual:
@@ -88,7 +88,7 @@ in this matter.
<!--
Copyright (C) 2017-2023 Free Software Foundation, Inc.
Copyright (C) 2017-2024 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

16
.gitignore vendored
View File

@@ -1,16 +1,19 @@
*.I[12]
*.[EIOX]
*.[EIOXao]
*.bak
*.gcda
*.gcno
*.o
*.a
*~
._bootmp
.deps
.gdb-history
.kludge-stamp
.version
/*.patch
/.Tpo
/.am*
/.re-list
/.sc-start-*
/ABOUT-NLS
/ChangeLog
/GNUmakefile
@@ -84,6 +87,7 @@
/lib/math.h
/lib/netdb.h
/lib/netinet/in.h
/lib/obstack.h
/lib/parse-datetime-gen.h
/lib/parse-datetime.c
/lib/poll.h
@@ -111,7 +115,12 @@
/lib/sys/
/lib/termios.h
/lib/time.h
/lib/uchar.h
/lib/unicase.h
/lib/unicase/
/lib/unictype
/lib/unictype.h
/lib/uninorm.h
/lib/unistd.h
/lib/unistr
/lib/unistr.h
@@ -200,6 +209,7 @@
/tests/factor/t[0-9][0-9].sh
/tests/t?
/tests/test-suite.log
/tight-scope.mk
ID
Makefile
Makefile.in

View File

@@ -1 +1 @@
9.2
9.4

View File

@@ -1,6 +1,6 @@
# Suppress valgrind diagnostics we don't care about.
# Copyright (C) 2003-2023 Free Software Foundation, Inc.
# Copyright (C) 2003-2024 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
AUTHORS
View File

@@ -2,30 +2,30 @@ Here are the names of the programs in this package,
each followed by the name(s) of its author(s).
arch: David MacKenzie, Karel Zak
b2sum: Padraig Brady, Samuel Neves
b2sum: Pádraig Brady, Samuel Neves
base32: Simon Josefsson
base64: Simon Josefsson
basename: David MacKenzie
basenc: Simon Josefsson, Assaf Gordon
cat: Torbjorn Granlund, Richard M. Stallman
cat: Torbjörn Granlund, Richard M. Stallman
chcon: Russell Coker, Jim Meyering
chgrp: David MacKenzie, Jim Meyering
chmod: David MacKenzie, Jim Meyering
chown: David MacKenzie, Jim Meyering
chroot: Roland McGrath
cksum: Padraig Brady, Q. Frank Xia
cksum: Pádraig Brady, Q. Frank Xia
comm: Richard M. Stallman, David MacKenzie
coreutils: Alex Deymo
cp: Torbjorn Granlund, David MacKenzie, Jim Meyering
cp: Torbjörn Granlund, David MacKenzie, Jim Meyering
csplit: Stuart Kemp, David MacKenzie
cut: David M. Ihnat, David MacKenzie, Jim Meyering
date: David MacKenzie
dd: Paul Rubin, David MacKenzie, Stuart Kemp
df: Torbjorn Granlund, David MacKenzie, Paul Eggert
df: Torbjörn Granlund, David MacKenzie, Paul Eggert
dir: Richard M. Stallman, David MacKenzie
dircolors: H. Peter Anvin
dirname: David MacKenzie, Jim Meyering
du: Torbjorn Granlund, David MacKenzie, Paul Eggert, Jim Meyering
du: Torbjörn Granlund, David MacKenzie, Paul Eggert, Jim Meyering
echo: Brian Fox, Chet Ramey
env: Richard Mlynarik, David MacKenzie, Assaf Gordon
expand: David MacKenzie
@@ -67,7 +67,7 @@ printf: David MacKenzie
ptx: François Pinard
pwd: Jim Meyering
readlink: Dmitry V. Levin
realpath: Padraig Brady
realpath: Pádraig Brady
rm: Paul Rubin, David MacKenzie, Richard M. Stallman, Jim Meyering
rmdir: David MacKenzie
runcon: Russell Coker
@@ -81,9 +81,9 @@ shred: Colin Plumb
shuf: Paul Eggert
sleep: Jim Meyering, Paul Eggert
sort: Mike Haertel, Paul Eggert
split: Torbjorn Granlund, Richard M. Stallman
split: Torbjörn Granlund, Richard M. Stallman
stat: Michael Meskes
stdbuf: Padraig Brady
stdbuf: Pádraig Brady
stty: David MacKenzie
sum: Kayvan Aghaiepour, David MacKenzie
sync: Jim Meyering, Giuseppe Scrivano
@@ -91,11 +91,11 @@ tac: Jay Lepreau, David MacKenzie
tail: Paul Rubin, David MacKenzie, Ian Lance Taylor, Jim Meyering
tee: Mike Parker, Richard M. Stallman, David MacKenzie
test: Kevin Braunsdorf, Matthew Bradburn
timeout: Padraig Brady
timeout: Pádraig Brady
touch: Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, Randy Smith
tr: Jim Meyering
true: Jim Meyering
truncate: Padraig Brady
truncate: Pádraig Brady
tsort: Mark Kettenis
tty: David MacKenzie
uname: David MacKenzie

19
HACKING
View File

@@ -3,22 +3,21 @@ Coreutils Contribution Guidelines
Prerequisites
=============
You will need the "git" version control tools.
On Fedora-based systems, do "yum install git".
On Debian-based ones install the "git-core" package.
Then run "git --version". If that says it's older than
version 1.4.4, then you'd do well to get a newer version.
You will need the "git" version control tools. On Fedora-based
systems, do "yum install git". On Debian-based ones install the
"git-core" package. Then run "git --version". If that says it's
older than version 1.4.4, then you'd do well to get a newer version.
At worst, just download the latest stable release from
https://git-scm.com/ and build from source.
For details on building the programs in this package, see
the file, README-hacking.
For details on building the programs in this package, see the file,
README-hacking.
Use the latest upstream sources
===============================
Base any changes you make on the latest upstream sources.
You can get a copy of the latest with this command:
Base any changes you make on the latest upstream sources. You can get
a copy of the latest with this command:
git clone https://git.savannah.gnu.org/git/coreutils.git
cd coreutils
@@ -617,7 +616,7 @@ and root only tests, is to follow these steps (requires lcov to be installed):
xdg-open doc/coverage/index.html
========================================================================
Copyright (C) 2009-2023 Free Software Foundation, Inc.
Copyright (C) 2009-2024 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-2023 Free Software Foundation, Inc.
# Copyright (C) 1990-2024 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
@@ -94,7 +94,7 @@ dist-hook: gen-ChangeLog
$(AM_V_at)touch $(distdir)/doc/constants.texi \
$(distdir)/doc/coreutils.info
gen_start_ver = 8.29
gen_start_ver = 8.31
.PHONY: gen-ChangeLog
gen-ChangeLog:
$(AM_V_GEN)if test -d .git; then \

262
NEWS
View File

@@ -1,5 +1,251 @@
GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release 9.5 (2024-03-28) [stable]
** Bug fixes
chmod -R now avoids a race where an attacker may replace a traversed file
with a symlink, causing chmod to operate on an unintended file.
[This bug was present in "the beginning".]
cp, mv, and install no longer issue spurious diagnostics like "failed
to preserve ownership" when copying to GNU/Linux CIFS file systems.
They do this by working around some Linux CIFS bugs.
cp --no-preserve=mode will correctly maintain set-group-ID bits
for created directories. Previously on systems that didn't support ACLs,
cp would have reset the set-group-ID bit on created directories.
[bug introduced in coreutils-8.20]
join and uniq now support multi-byte characters better.
For example, 'join -tX' now works even if X is a multi-byte character,
and both programs now treat multi-byte characters like U+3000
IDEOGRAPHIC SPACE as blanks if the current locale treats them so.
numfmt options like --suffix no longer have an arbitrary 127-byte limit.
[bug introduced with numfmt in coreutils-8.21]
mktemp with --suffix now better diagnoses templates with too few X's.
Previously it conflated the insignificant --suffix in the error.
[bug introduced in coreutils-8.1]
sort again handles thousands grouping characters in single-byte locales
where the grouping character is greater than CHAR_MAX. For e.g. signed
character platforms with a 0xA0 (aka &nbsp) grouping character.
[bug introduced in coreutils-9.1]
split --line-bytes with a mixture of very long and short lines
no longer overwrites the heap (CVE-2024-0684).
[bug introduced in coreutils-9.2]
tail no longer mishandles input from files in /proc and /sys file systems,
on systems with a page size larger than the stdio BUFSIZ.
[This bug was present in "the beginning".]
timeout avoids a narrow race condition, where it might kill arbitrary
processes after a failed process fork.
[bug introduced with timeout in coreutils-7.0]
timeout avoids a narrow race condition, where it might fail to
kill monitored processes immediately after forking them.
[bug introduced with timeout in coreutils-7.0]
wc no longer fails to count unprintable characters as parts of words.
[bug introduced in textutils-2.1]
** Changes in behavior
base32 and base64 no longer require padding when decoding.
Previously an error was given for non padded encoded data.
base32 and base64 have improved detection of corrupted encodings.
Previously encodings with non zero padding bits were accepted.
basenc --base16 -d now supports lower case hexadecimal characters.
Previously an error was given for lower case hex digits.
cp --no-clobber, and mv -n no longer exit with failure status if
existing files are encountered in the destination. Instead they revert
to the behavior from before v9.2, silently skipping existing files.
ls --dired now implies long format output without hyperlinks enabled,
and will take precedence over previously specified formats or hyperlink mode.
numfmt will accept lowercase 'k' to indicate Kilo or Kibi units on input,
and uses lowercase 'k' when outputting such units in '--to=si' mode.
pinky no longer tries to canonicalize the user's login location by default,
rather requiring the new --lookup option to enable this often slow feature.
wc no longer ignores encoding errors when counting words.
Instead, it treats them as non white space.
** New features
chgrp now accepts the --from=OWNER:GROUP option to restrict changes to files
with matching current OWNER and/or GROUP, as already supported by chown(1).
chmod adds support for -h, -H,-L,-P, and --dereference options, providing
more control over symlink handling. This supports more secure handling of
CLI arguments, and is more consistent with chown, and chmod on other systems.
cp now accepts the --keep-directory-symlink option (like tar), to preserve
and follow existing symlinks to directories in the destination.
cp and mv now accept the --update=none-fail option, which is similar
to the --no-clobber option, except that existing files are diagnosed,
and the command exits with failure status if existing files.
The -n,--no-clobber option is best avoided due to platform differences.
env now accepts the -a,--argv0 option to override the zeroth argument
of the command being executed.
mv now accepts an --exchange option, which causes the source and
destination to be exchanged. It should be combined with
--no-target-directory (-T) if the destination is a directory.
The exchange is atomic if source and destination are on a single
file system that supports atomic exchange; --exchange is not yet
supported in other situations.
od now supports printing IEEE half precision floating point with -t fH,
or brain 16 bit floating point with -t fB, where supported by the compiler.
tail now supports following multiple processes, with repeated --pid options.
** Improvements
cp,mv,install,cat,split now read and write a minimum of 256KiB at a time.
This was previously 128KiB and increasing to 256KiB was seen to increase
throughput by 10-20% when reading cached files on modern systems.
env,kill,timeout now support unnamed signals. kill(1) for example now
supports sending such signals, and env(1) will list them appropriately.
SELinux operations in file copy operations are now more efficient,
avoiding unneeded MCS/MLS label translation.
sort no longer dynamically links to libcrypto unless -R is used.
This decreases startup overhead in the typical case.
wc is now much faster in single-byte locales and somewhat faster in
multi-byte locales.
* Noteworthy changes in release 9.4 (2023-08-29) [stable]
** Bug fixes
On GNU/Linux s390x and alpha, programs like 'cp' and 'ls' no longer
fail on files with inode numbers that do not fit into 32 bits.
[This bug was present in "the beginning".]
'b2sum --check' will no longer read unallocated memory when
presented with malformed checksum lines.
[bug introduced in coreutils-9.2]
'cp --parents' again succeeds when preserving mode for absolute directories.
Previously it would have failed with a "No such file or directory" error.
[bug introduced in coreutils-9.1]
'cp --sparse=never' will avoid copy-on-write (reflinking) and copy offloading,
to ensure no holes present in the destination copy.
[bug introduced in coreutils-9.0]
cksum again diagnoses read errors in its default CRC32 mode.
[bug introduced in coreutils-9.0]
'cksum --check' now ensures filenames with a leading backslash character
are escaped appropriately in the status output.
This also applies to the standalone checksumming utilities.
[bug introduced in coreutils-8.25]
dd again supports more than two multipliers for numbers.
Previously numbers of the form '1024x1024x32' gave "invalid number" errors.
[bug introduced in coreutils-9.1]
factor, numfmt, and tsort now diagnose read errors on the input.
[This bug was present in "the beginning".]
'install --strip' now supports installing to files with a leading hyphen.
Previously such file names would have caused the strip process to fail.
[This bug was present in "the beginning".]
ls now shows symlinks specified on the command line that can't be traversed.
Previously a "Too many levels of symbolic links" diagnostic was given.
[This bug was present in "the beginning".]
pinky, uptime, users, and who no longer misbehave on 32-bit GNU/Linux
platforms like x86 and ARM where time_t was historically 32 bits.
Also see the new --enable-systemd option mentioned below.
[bug introduced in coreutils-9.0]
'pr --length=1 --double-space' no longer enters an infinite loop.
[This bug was present in "the beginning".]
shred again operates on Solaris when built for 64 bits.
Previously it would have exited with a "getrandom: Invalid argument" error.
[bug introduced in coreutils-9.0]
tac now handles short reads on its input. Previously it may have exited
erroneously, especially with large input files with no separators.
[This bug was present in "the beginning".]
'uptime' no longer incorrectly prints "0 users" on OpenBSD,
and is being built again on FreeBSD and Haiku.
[bugs introduced in coreutils-9.2]
'wc -l' and 'cksum' no longer crash with an "Illegal instruction" error
on x86 Linux kernels that disable XSAVE YMM. This was seen on Xen VMs.
[bug introduced in coreutils-9.0]
** Changes in behavior
'cp -v' and 'mv -v' will no longer output a message for each file skipped
due to -i, or -u. Instead they only output this information with --debug.
I.e., 'cp -u -v' etc. will have the same verbosity as before coreutils-9.3.
'cksum -b' no longer prints base64-encoded checksums. Rather that
short option is reserved to better support emulation of the standalone
checksum utilities with cksum.
'mv dir x' now complains differently if x/dir is a nonempty directory.
Previously it said "mv: cannot move 'dir' to 'x/dir': Directory not empty",
where it was unclear whether 'dir' or 'x/dir' was the problem.
Now it says "mv: cannot overwrite 'x/dir': Directory not empty".
Similarly for other renames where the destination must be the problem.
[problem introduced in coreutils-6.0]
** Improvements
cp, mv, and install now avoid copy_file_range on linux kernels before 5.3
irrespective of which kernel version coreutils is built against,
reinstating that behavior from coreutils-9.0.
comm, cut, join, od, and uniq will now exit immediately upon receiving a
write error, which is significant when reading large / unbounded inputs.
split now uses more tuned access patterns for its potentially large input.
This was seen to improve throughput by 5% when reading from SSD.
split now supports a configurable $TMPDIR for handling any temporary files.
tac now falls back to '/tmp' if a configured $TMPDIR is unavailable.
'who -a' now displays the boot time on Alpine Linux, OpenBSD,
Cygwin, Haiku, and some Android distributions
'uptime' now succeeds on some Android distributions, and now counts
VM saved/sleep time on GNU (Linux, Hurd, kFreeBSD), NetBSD, OpenBSD,
Minix, and Cygwin.
On GNU/Linux platforms where utmp-format files have 32-bit timestamps,
pinky, uptime, and who can now work for times after the year 2038,
so long as systemd is installed, you configure with a new, experimental
option --enable-systemd, and you use the programs without file arguments.
(For example, with systemd 'who /var/log/wtmp' does not work because
systemd does not support the equivalent of /var/log/wtmp.)
* Noteworthy changes in release 9.3 (2023-04-18) [stable]
** Bug fixes
@@ -11,7 +257,7 @@ GNU coreutils NEWS -*- outline -*-
[bug introduced in coreutils-9.2]
cp --recursive --backup will again operate correctly.
Previousy it may have issued "File exists" errors when
Previously it may have issued "File exists" errors when
it failed to appropriately rename files being replaced.
[bug introduced in coreutils-9.2]
@@ -301,7 +547,7 @@ GNU coreutils NEWS -*- outline -*-
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
capabilities are 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
@@ -392,7 +638,7 @@ GNU coreutils NEWS -*- outline -*-
expr no longer mishandles unmatched \(...\) in regular expressions.
[bug introduced in coreutils-6.0]
ls no longer crashes when printing the SELinux context for unstatable files.
ls no longer crashes when printing the SELinux context for unstattable files.
[bug introduced in coreutils-6.9.91]
mkdir -m no longer mishandles modes more generous than the umask.
@@ -971,7 +1217,7 @@ GNU coreutils NEWS -*- outline -*-
** Bug fixes
cp --parents will now set an SELinux context for created directories,
as appropriate for the -a, --preseve=context, or -Z options.
as appropriate for the -a, --preserve=context, or -Z options.
[bug present since SELinux support added in coreutils-6.10]
date again converts from a specified time zone. Previously output was
@@ -1608,7 +1854,7 @@ GNU coreutils NEWS -*- outline -*-
** Bug fixes
df now processes the mount list correctly in the presence of unstatable
df now processes the mount list correctly in the presence of unstattable
mount points. Previously it may have failed to output some mount points.
[bug introduced in coreutils-8.21]
@@ -2861,7 +3107,7 @@ GNU coreutils NEWS -*- outline -*-
ls --color now handles files with capabilities correctly. Previously
files with capabilities were often not colored, and also sometimes, files
without capabilites were colored in error. [bug introduced in coreutils-7.0]
without capabilities were colored in error. [bug introduced in coreutils-7.0]
md5sum now prints checksums atomically so that concurrent
processes will not intersperse their output.
@@ -3010,7 +3256,7 @@ GNU coreutils NEWS -*- outline -*-
avoid the disproportionate quadratic performance penalty. Leading to
another improvement:
rm -r is now slightly more standards-conformant when operating on
rm -r is now slightly more standard-conforming when operating on
write-protected files with relative names longer than 8KiB.
@@ -5650,7 +5896,7 @@ packages, see ./old/*/NEWS.
========================================================================
Copyright (C) 2001-2023 Free Software Foundation, Inc.
Copyright (C) 2001-2024 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

7
README
View File

@@ -96,8 +96,8 @@ run this command:
make check TESTS=tests/df/df-P.sh VERBOSE=yes SUBDIRS=. >> log 2>&1
For some tests, you can get even more detail by adding DEBUG=yes.
Then include the contents of the file 'log' in your bug report.
For some tests, particularly perl tests, you can get even more detail by adding
DEBUG=yes. Then include the contents of the file 'log' in your bug report.
***************************************
@@ -127,10 +127,11 @@ https://www.gnu.org/prep/standards/
For any copyright year range specified as YYYY-ZZZZ in this package
note that the range specifies every single year in that closed interval.
Please see the file COPYING for copying conditions.
========================================================================
Copyright (C) 1998-2023 Free Software Foundation, Inc.
Copyright (C) 1998-2024 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

@@ -101,7 +101,7 @@ each program. One way to do this is to use vc-dwim
-----
Copyright (C) 2002-2023 Free Software Foundation, Inc.
Copyright (C) 2002-2024 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

@@ -58,7 +58,7 @@ Although 32-bit builds fail if that forces time_t to be 32 bits, this
can be fixed by using 64-bit builds. For example, on AIX where GCC
defaults to 32 bits, one can use "./configure CC='gcc -maix64' AR='ar
-X64'"; similarly, on Solaris one can configure with CC='gcc -m64'.
If all else fails one can configure with ac_year2038_required=no;
If all else fails one can configure with --disable-year2038;
however, this will mishandle timestamps after 2038, and please file
bug reports for any such situations.

View File

@@ -1,7 +1,7 @@
#! /bin/bash
# Convert this package for use with valgrind.
# Copyright (C) 2002-2023 Free Software Foundation, Inc.
# Copyright (C) 2002-2024 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
@@ -41,7 +41,7 @@ _path='export PATH='$srcdir':${PATH#*:}'
pre='#!/bin/sh\n'"$_path"'\n'
n=15 # stack trace depth
log_fd=3 # One can redirect this to file like 3>vg.log
test -e /tmp/cu-vg && suppressions='--supressions=/tmp/cu-vg'
test -e /tmp/cu-vg && suppressions='--suppressions=/tmp/cu-vg'
vg="exec /usr/bin/valgrind $suppressions --log-fd=$log_fd \
--leak-check=yes --track-fds=yes --leak-check=full --num-callers=$n"
cat <<EOF > src/vg/gen

View File

@@ -211,6 +211,7 @@ Francesco Montorsi fr_m@hotmail.com
François Pinard pinard@iro.umontreal.ca
François Rigault rigault.francois@gmail.com
Frank Adler fadler@allesklar.de
Frank Busse f.busse@imperial.ac.uk
Frank T Lofaro ftlofaro@snooks.Egr.UNLV.EDU
Fred Fish fnf@ninemoons.com
Frédéric L. W. Meunier 0@pervalidus.net
@@ -237,7 +238,6 @@ Greg McGary gkm@gnu.org
Greg Metcalfe metcalfegreg@qwest.net
Greg Schafer gschafer@zip.com.au
Greg Troxel gdt@bbn.com
Greg Wooledge gawooledge@sherwin.com
Gregory Leblanc gleblanc@cu-portland.edu
Guido Leenders guido.leenders@invantive.com
Guntram Blohm Extern.Guntram.Blohm@AUDI.DE
@@ -411,6 +411,7 @@ Marty Leisner leisner@sdsp.mc.xerox.com
Masami Takikawa takikawm@CS.ORST.EDU
Mate Wierdl mw@moni.msci.memphis.edu
Matej Vela mvela@public.srce.hr
Matheus Afonso Martins Moreira matheus.a.m.moreira@gmail.com
Mathias Brodala info@noctus.net
Matias A. Fonzo selk@dragora.org
Matt Kraai kraai@ftbfs.org
@@ -565,7 +566,6 @@ Rudolf Kastl rkastl@redhat.com
Sahil Amoli sahilamoli@gmail.com
Sami Farin sfarin@ratol.fi
Samuel Neves sneves@dei.uc.pt
Samuel Tardieu sam@rfc1149.net
Samuel Thibault samuel.thibault@ens-lyon.org
Samuli Karkkainen Samuli.Karkkainen@hut.fi
Sander van Malssen svm@kozmix.ow.nl
@@ -634,7 +634,7 @@ Tony Leneis tony@plaza.ds.adp.com
Tony Robinson ajr@eng.cam.ac.uk
Toomas Soome Toomas.Soome@Elion.ee
Toralf Förster toralf.foerster@gmx.de
Torbjorn Lindgren tl@funcom.no
Torbjörn Lindgren tl@funcom.no
Torsten Landschoff torsten@pclab.ifg.uni-kiel.de
Travis Gummels tgummels@redhat.com
Tristan Miller psychonaut@nothingisreal.com

4
TODO
View File

@@ -18,7 +18,7 @@ document the following in coreutils.texi:
Suggestion from Paul Eggert:
More generally, there's not that much use for imaxtostr nowadays,
since the inttypes module and newer versions of gettext allow things
like _("truncating %s at %" PRIdMAX " bytes") to work portably.
like _("truncating %s at %jd bytes") to work portably.
I suspect that (if someone cares to take the time) we can remove
all instances of imaxtostr and umaxtostr in coreutils and gnulib.
@@ -143,7 +143,7 @@ pr's use of nstrftime can make it malloc a very large (up to SIZE_MAX) buffer
-----
Copyright (C) 2002-2023 Free Software Foundation, Inc.
Copyright (C) 2002-2024 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

1885
bootstrap

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
# Bootstrap configuration.
# Copyright (C) 2006-2023 Free Software Foundation, Inc.
# Copyright (C) 2006-2024 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,6 +20,8 @@
avoided_gnulib_modules='
--avoid=canonicalize-lgpl
--avoid=dummy
--avoid=mbuiter
--avoid=mbuiterf
'
# gnulib modules used by this package.
@@ -36,25 +38,27 @@ gnulib_modules="
argv-iter
assert
assert-h
assure
attribute
autobuild
backupfile
backup-rename
backupfile
base32
base64
btowc
btoc32
buffer-lcm
byteswap
c-strcase
cl-strtod
cl-strtold
calloc-gnu
c32iscntrl
c32isspace
c32width
canon-host
canonicalize
chmodat
chown
chownat
cloexec
cl-strtod
cl-strtold
closein
closeout
config-h
@@ -103,6 +107,7 @@ gnulib_modules="
fnmatch-gnu
fopen-safer
fprintftime
fpurge
free-posix
freopen
freopen-safer
@@ -115,7 +120,6 @@ gnulib_modules="
fts
full-read
full-write
getgroups
gethrxtime
getline
getloadavg
@@ -123,19 +127,14 @@ gnulib_modules="
getndelim2
getopt-gnu
getpagesize
getpass-gnu
gettext-h
gettime
gettime-res
getugroups
getusershell
git-version-gen
gitlog-to-changelog
gnu-make
gnu-web-doc-update
gnumakefile
gnupload
group-member
hard-locale
hash
hash-triple
@@ -152,7 +151,6 @@ gnulib_modules="
isblank
largefile
lchmod
lchown
ldtoastr
lib-ignore
libgmp
@@ -166,18 +164,19 @@ gnulib_modules="
malloc-gnu
manywarnings
mbrlen
mbrtoc32
mbrtowc
mbsalign
mbschr
mbslen
mbswidth
mbszero
mcel-prefer
memcasecmp
memchr
memcmp2
mempcpy
memrchr
minmax
mgetgroups
mkancesdirs
mkdir
mkdir-p
@@ -191,9 +190,9 @@ gnulib_modules="
modechange
mountlist
mpsort
netinet_in
nproc
nstrftime
nullptr
obstack
open
openat-safer
@@ -209,7 +208,7 @@ gnulib_modules="
posixver
priv-set
progname
propername
propername-lite
pthread-cond
pthread-mutex
pthread-thread
@@ -221,19 +220,15 @@ gnulib_modules="
randperm
rawmemchr
read-file
readlink
readtokens
readtokens0
readutmp
realloc-gnu
regex
remove
rename
renameat
renameatu
rmdir
root-dev-ino
rpmatch
safe-read
same
save-cwd
@@ -245,17 +240,18 @@ gnulib_modules="
settime
sig2str
sigaction
skipchars
smack
ssize_t
stat-macros
stat-size
stat-time
stdbool
stdckdint
stdlib-safer
stpcpy
stpncpy
strdup-posix
strncat
strnlen
strnumcmp
strsignal
strtoimax
@@ -271,8 +267,7 @@ gnulib_modules="
time_rz
timer-time
timespec
tmpfile
tzset
tmpdir
uname
unicodeio
unistd-safer
@@ -282,7 +277,6 @@ gnulib_modules="
unlocked-io
unsetenv
update-copyright
uptime
useless-if-before-free
userspec
utimecmp
@@ -293,9 +287,6 @@ gnulib_modules="
verify
verror
version-etc-fsf
wchar-single
wcswidth
wcwidth
winsz-ioctl
winsz-termios
write-any-file
@@ -318,7 +309,7 @@ gnulib_modules="
xstrtol-error
xstrtold
xstrtoumax
year2038-required
year2038-recommended
yesno
"
@@ -347,7 +338,7 @@ see_manual='"This is a proper name. See the gettext manual, section Names."'
see_manual=\'"$see_manual"\'
XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\
--keyword=proper_name:1,'"$see_manual"'\\\
--keyword=proper_name_utf8:1,'"$see_manual"'\\\
--keyword=proper_name_lite:1,'"$see_manual"'\\\
'
gnulib_tool_option_extras="--tests-base=gnulib-tests --with-tests --symlink\
@@ -364,11 +355,13 @@ gettext 0.19.2
git 1.4.4
gperf -
gzip -
m4 -
makeinfo 6.1
texi2pdf 6.1
patch -
perl 5.5
rsync -
tar -
wget -
xz -
"

View File

@@ -33,7 +33,6 @@ build_if_possible_progs='
stdbuf
stty
timeout
uptime
users
who
'
@@ -132,6 +131,7 @@ normal_progs='
unexpand
uniq
unlink
uptime
vdir
wc
whoami

View File

@@ -71,6 +71,7 @@ override_single() {
override_single dir ls
override_single vdir ls
override_single arch uname
override_single chgrp chown
for cmd in $ALL_PROGRAMS; do
echo "# Command $cmd"

91
cfg.mk
View File

@@ -1,5 +1,5 @@
# Customize maint.mk -*- makefile -*-
# Copyright (C) 2003-2023 Free Software Foundation, Inc.
# Copyright (C) 2003-2024 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,7 +26,6 @@ VC_LIST_ALWAYS_EXCLUDE_REGEX = src/blake2/.*$$
# Tests not to run as part of "make distcheck".
local-checks-to-skip = \
sc_proper_name_utf8_requires_ICONV \
sc_indent
# Tools used to bootstrap this package, used for "announcement".
@@ -49,10 +48,11 @@ export VERBOSE = yes
# 4914152 9e
export XZ_OPT = -8e
old_NEWS_hash = 72a8f8283d3c9daef72e06be5bb52734
old_NEWS_hash = d66ee7a9fdb974017a4a17cf358d047d
# Add an exemption for sc_makefile_at_at_check.
_makefile_at_at_check_exceptions = ' && !/^cu_install_prog/ && !/dynamic-dep/'
_makefile_at_at_check_exceptions = \
' && !/MAKEINFO/ && !/^cu_install_prog/ && !/dynamic-dep/'
# Our help-version script is in a slightly different location.
_hv_file ?= $(srcdir)/tests/misc/help-version
@@ -189,12 +189,15 @@ sc_prohibit_quotes_notation:
exit 1; } \
|| :
error_fns = (error|diagnose)
# 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 arguments, or the arguments in parenthesis.
sc_error_quotes:
@cd $(srcdir)/src && GIT_PAGER= git grep -n 'error *(.*%s.*, [^(]*);$$'\
@cd $(srcdir)/src \
&& GIT_PAGER= git grep -E -n '$(error_fns) *\(.*%s.*, [^(]*\);$$' \
*.c | grep -v ', q' \
&& { echo '$(ME): '"Use quote() for error string arguments" 1>&2; \
exit 1; } \
@@ -206,7 +209,7 @@ sc_error_quotes:
sc_error_shell_quotes:
@cd $(srcdir)/src && \
{ GIT_PAGER= git grep -E \
'error \(.*%s[:"], .*(name|file)[^"]*\);$$' *.c; \
'$(error_fns) \(.*%s[:"], .*(name|file)[^"]*\);$$' *.c; \
GIT_PAGER= git grep -E \
' quote[ _].*file' *.c; } \
| grep -Ev '(quotef|q[^ ]*name)' \
@@ -220,27 +223,17 @@ sc_error_shell_quotes:
# to provide better support for copy and paste.
sc_error_shell_always_quotes:
@cd $(srcdir)/src && GIT_PAGER= git grep -E \
'error \(.*[^:] %s[ "].*, .*(name|file)[^"]*\);$$' \
'$(error_fns) \(.*[^:] %s[ "].*, .*(name|file)[^"]*\);$$' \
*.c | grep -Ev '(quoteaf|q[^ ]*name)' \
&& { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
exit 1; } \
|| :
@cd $(srcdir)/src && GIT_PAGER= git grep -E -A1 \
'error \([^%]*[^:] %s[ "]' *.c | grep 'quotef' \
'$(error_fns) \([^%]*[^:] %s[ "]' *.c | grep 'quotef' \
&& { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
exit 1; } \
|| :
# Usage of error() with an exit constant, should instead use die(),
# as that avoids warnings and may generate better code, due to being apparent
# to the compiler that it doesn't return.
sc_die_EXIT_FAILURE:
@cd $(srcdir)/src && GIT_PAGER= git grep -E \
'error \([^?]*EXIT_' \
&& { echo '$(ME): '"Use die() instead of error" 1>&2; \
exit 1; } \
|| :
# Avoid unstyled quoting to internal slots and thus destined for diagnostics
# as that can leak unescaped control characters to the output, when using
# the default "literal" quoting style.
@@ -295,27 +288,6 @@ sc_check-AUTHORS: $(all_programs)
&& diff $(au_actual) $(au_dotdot) \
&& rm -f $(au_actual) $(au_dotdot)
# Each program with a non-ASCII author name must link with LIBICONV.
sc_check-I18N-AUTHORS:
@cd $(srcdir)/src && \
for i in $$(git grep -l -w proper_name_utf8 *.c|sed 's/\.c//'); do \
grep -E "^src_$${i}_LDADD"' .?= .*\$$\(LIBICONV\)' local.mk \
> /dev/null \
|| { echo "$(ME): link rules for $$i do not include" \
'$$(LIBICONV)' 1>&2; exit 1; }; \
done
# Disallow the C99 printf size specifiers %z and %j as they're not portable.
# The gnulib printf replacement does support them, however the printf
# replacement is not currently explicitly depended on by the gnulib error()
# module for example. Also we use fprintf() in a few places to output simple
# formats but don't use the gnulib module as it is seen as overkill at present.
# We'd have to adjust the above gnulib items before disabling this.
sc_prohibit-c99-printf-format:
@cd $(srcdir)/src && GIT_PAGER= git grep -n '%[0*]*[jz][udx]' *.c \
&& { echo '$(ME): Use PRI*MAX instead of %j or %z' 1>&2; exit 1; } \
|| :
# Ensure the alternative __attribute (keyword) form isn't used as
# that form is not elided where required. Also ensure that we don't
# directly use attributes already defined by gnulib.
@@ -343,7 +315,7 @@ FILTER_LONG_LINES = \
\|^[^:]*NEWS:.*https\{,1\}://| d; \
\|^[^:]*doc/fdl.texi:| d; \
\|^[^:]*man/help2man:| d; \
\|^[^:]*tests/misc/sha[0-9]*sum.*\.pl[-:]| d; \
\|^[^:]*tests/cksum/sha[0-9]*sum.*\.pl[-:]| d; \
\|^[^:]*tests/pr/|{ \|^[^:]*tests/pr/pr-tests:| !d; };
sc_long_lines:
@wc -L /dev/null >/dev/null 2>/dev/null \
@@ -509,6 +481,18 @@ sc_prohibit_man_see_also_period:
{ echo '$(ME): do not end "SEE ALSO" section with a period' \
1>&2; exit 1; } || :
sc_prohibit_exit_write_error:
@prohibit='error.*EXIT_FAILURE.*write error' \
in_vc_files='\.c$$' \
halt='Use write_error() instead' \
$(_sc_search_regexp)
sc_prohibit_NULL:
@prohibit='$(begword)NULL$(endword)' \
in_vc_files='\.[ch]$$' \
halt='use nullptr instead' \
$(_sc_search_regexp)
# Don't use "indent-tabs-mode: nil" anymore. No longer needed.
sc_prohibit_emacs__indent_tabs_mode__setting:
@prohibit='^( *[*#] *)?indent-tabs-mode:' \
@@ -561,7 +545,7 @@ sc_prohibit_short_facl_mode_spec:
# Ensure that "stdio--.h" is used where appropriate.
sc_require_stdio_safer:
@if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
files=$$(grep -l '$(begword)freopen \?(' $$($(VC_LIST_EXCEPT) \
files=$$(grep -El '$(begword)freopen ?\(' $$($(VC_LIST_EXCEPT)\
| grep '\.[ch]$$')); \
test -n "$$files" && grep -LE 'include "stdio--.h"' $$files \
| grep . && \
@@ -570,6 +554,18 @@ sc_require_stdio_safer:
else :; \
fi
# Ensure that "stdlib--.h" is used where appropriate.
sc_require_stdlib_safer:
@if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
files=$$(grep -El '$(begword)mkstemp ?\(' $$($(VC_LIST_EXCEPT)\
| grep '\.[ch]$$')); \
test -n "$$files" && grep -LE 'include "stdlib--.h"' $$files \
| grep . && \
{ echo '$(ME): the above files should use "stdlib--.h"' \
1>&2; exit 1; } || :; \
else :; \
fi
sc_prohibit_perl_hash_quotes:
@prohibit="\{'[A-Z_]+' *[=}]" \
halt="in Perl code, write \$$hash{KEY}, not \$$hash{'K''EY'}" \
@@ -626,7 +622,8 @@ sc_prohibit_test_empty:
sc_some_programs_must_avoid_exit_failure:
@cd $(srcdir) \
&& grep -nw EXIT_FAILURE \
$$(git grep -El '[^T]_FAILURE|EXIT_CANCELED' $(srcdir)/src) \
$$(git grep -El '[^T]_FAILURE|EXIT_CANCELED' src/) \
| grep -v '^src/system\.h:' \
| grep -vE '= EXIT_FAILURE|return .* \?' | grep . \
&& { echo '$(ME): do not use EXIT_FAILURE in the above' \
1>&2; exit 1; } || :
@@ -842,9 +839,10 @@ 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|chown-core|find-mount-point)\.h|make-prime-list\.c)$$
^src/((system|copy|chown-core|find-mount-point)\.h|make-prime-list\.c)$$
_src = (false|lbracket|ls-(dir|ls|vdir)|tac-pipe|uname-(arch|uname))
_src := (false|lbracket|chown-(chgrp|chown)
_src := $(_src)|ls-(dir|ls|vdir)|tac-pipe|uname-(arch|uname))
_gl_src = (xdecto.max|cl-strtold)
exclude_file_name_regexp--sc_require_config_h_first = \
(^lib/buffer-lcm\.c|gl/lib/$(_gl_src)\.c|src/$(_src)\.c)$$
@@ -885,7 +883,7 @@ exclude_file_name_regexp--sc_prohibit_stat_st_blocks = \
exclude_file_name_regexp--sc_prohibit_continued_string_alpha_in_column_1 = \
^src/(system\.h|od\.c|printf\.c|getlimits\.c)$$
_cksum = ^tests/misc/cksum-base64\.pl$$
_cksum = ^tests/cksum/cksum-base64\.pl$$
exclude_file_name_regexp--sc_prohibit_test_backticks = \
^tests/(local\.mk|(init|misc/stdbuf|factor/create-test)\.sh)$$|$(_cksum)
@@ -929,6 +927,9 @@ _gl_TS_other_headers = $(srcdir)/src/*.h src/*.h
# Normally, the rule would detect its declaration, but that uses a
# different name, __clz_tab.
_gl_TS_unmarked_extern_vars = factor_clz_tab
# Avoid tight_scope rule stating these should be static
# as there is no way to achieve that with the way these are defined.
_gl_TS_unmarked_extern_vars += ptr_MD5_.*
# Other tight_scope settings
_gl_TS_dir = .
_gl_TS_obj_files = src/*.$(OBJEXT)

View File

@@ -1,7 +1,7 @@
# -*- autoconf -*-
# Process this file with autoconf to produce a configure script.
# Copyright (C) 1991-2023 Free Software Foundation, Inc.
# Copyright (C) 1991-2024 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
@@ -55,7 +55,6 @@ gl_ASSERT_NO_GNULIB_POSIXCHECK])
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL
AC_PROG_RANLIB
AC_PROG_EGREP
AC_PROG_LN_S
@@ -64,6 +63,26 @@ gl_SET_CRYPTO_CHECK_DEFAULT([auto-gpl-compat])
gl_INIT
coreutils_MACROS
# These are safe, since 'sort', coreutils's only multithreaded app,
# does not use the relevant modules.
AC_DEFINE([GNULIB_EXCLUDE_SINGLE_THREAD], [1],
[Define to 1 if apps call 'exclude' functions from a single thread.])
AC_DEFINE([GNULIB_REGEX_SINGLE_THREAD], [1],
[Define to 1 if apps call 'regex' functions from a single thread.])
# Although 'sort' is multithreaded and can use these functions,
# it uses them only from the main thread.
AC_DEFINE([GNULIB_MBRTOWC_SINGLE_THREAD], [1],
[Define to 1 if apps call mbrtowc, mbrtoc32, and 'regex' functions
from a single thread.])
# This is safe, since all apps set locale early.
AC_DEFINE([GNULIB_WCHAR_SINGLE_LOCALE], [1],
[Define to 1 if apps don't set the locale after calling
locale-sensitive functions like mbrtowc and wcwidth.])
AC_DEFINE([GNULIB_MBRTOC32_REGULAR], [1],
[Do not worry about rare encodings like CP864, EBCDIC, Johab, and Shift JIS
that glibc does not support.])
# The test suite needs to know if we have a working perl.
AM_CONDITIONAL([HAVE_PERL], [test "$gl_cv_prog_perl" != no])
@@ -153,6 +172,13 @@ AC_ARG_ENABLE([gcc-warnings],
&& gl_gcc_warnings=yes])]
)
# clang is unduly picky about some things, even by default.
if test "$gl_cv_compiler_clang" = yes; then
gl_WARN_ADD([-Wno-format-extra-args])
gl_WARN_ADD([-Wno-implicit-const-int-float-conversion])
gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
fi
if test $gl_gcc_warnings != no; then
gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
AC_SUBST([WERROR_CFLAGS])
@@ -160,8 +186,7 @@ if test $gl_gcc_warnings != no; then
ew=
AS_IF([test $gl_gcc_warnings != expensive],
[# -fanalyzer and related options slow GCC considerably.
ew="$ew -fanalyzer -Wno-analyzer-double-free -Wno-analyzer-malloc-leak"
ew="$ew -Wno-analyzer-null-dereference -Wno-analyzer-use-after-free"])
ew="$ew -fanalyzer -Wno-analyzer-malloc-leak"])
# This, $nw, is the list of warnings we disable.
nw=$ew
@@ -184,7 +209,7 @@ if test $gl_gcc_warnings != no; then
nw="$nw -Wswitch-enum" # Too many warnings for now
nw="$nw -Wswitch-default" # Too many warnings for now
nw="$nw -Wstack-protector" # not worth working around
nw="$nw -Wformat-overflow=2" # False alarms due to GCC bug 80776
nw="$nw -Wformat-overflow=2" # False alarms due to GCC bug 110333
nw="$nw -Wformat-truncation=2" # False alarm in ls.c, probably related
# things I might fix soon:
nw="$nw -Wfloat-equal" # sort.c, seq.c
@@ -214,21 +239,6 @@ if test $gl_gcc_warnings != no; then
gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
gl_WARN_ADD([-Wno-format-nonliteral])
# clang is unduly picky about some things.
AC_CACHE_CHECK([whether the compiler is clang], [utils_cv_clang],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#ifndef __clang__
#error "not clang"
#endif
]])],
[utils_cv_clang=yes],
[utils_cv_clang=no])])
if test $utils_cv_clang = yes; then
gl_WARN_ADD([-Wno-format-extra-args])
gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
fi
gl_WARN_ADD([-fdiagnostics-show-option])
gl_WARN_ADD([-funit-at-a-time])
@@ -262,6 +272,10 @@ if test $gl_gcc_warnings != no; then
# FP in careadlinkat.c w/gcc 10.0.1 20200205
gl_WARN_ADD([-Wno-return-local-addr])
# FIXME: remove this line when gcc improves
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
gl_WARN_ADD([-Wno-stringop-overflow])
gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
AC_SUBST([GNULIB_WARN_CFLAGS])
@@ -337,6 +351,51 @@ if test $utils_cv_localtime_cache = yes; then
AC_DEFINE([LOCALTIME_CACHE], [1], [FIXME])
fi
# Find the library for dynamic loading of shared libraries.
AC_SEARCH_LIBS([dlopen], [dl])
AS_CASE([$ac_cv_search_dlopen],
[no | 'none required'],
[LIB_DL=],
[*],
[LIB_DL="$ac_cv_search_dlopen"])
AC_SUBST([LIB_DL])
# Should 'sort' link libcrypto dynamically?
AS_CASE([$LIB_CRYPTO],
[-lcrypto],
[# Check for dlopen and libcrypto dynamic linking in one program,
# as there's little point to checking them separately.
AC_CACHE_CHECK([for dlopen and whether libcrypto is linked dynamically],
[utils_cv_dlopen_libcrypto],
[utils_cv_dlopen_libcrypto=no
saved_LIBS=$LIBS
LIBS="$LIBS $LIB_DL $LIB_CRYPTO"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <dlfcn.h>
#include <openssl/sha.h>
/* Use SHA512 rather than MD5 here to avoid deprecation warnings.
So need to check HAVE_OPENSSL_MD5.. with DLOPEN_LIBCRYPTO. */
]],
[[return !(dlopen ("libcrypto.so", RTLD_LAZY | RTLD_GLOBAL)
&& SHA512 (0, 0, 0));]])],
[# readelf works with cross-builds; ldd works on more platforms.
LIBCRYPTO_SONAME="`(readelf -d conftest$EXEEXT || ldd conftest$EXEEXT
) 2>/dev/null |
sed -n 's/.*\(libcrypto\.so\.[[.0-9]]*\).*/\1/p'`"
AS_CASE([$LIBCRYPTO_SONAME],
[*libcrypto*],
[utils_cv_dlopen_libcrypto=yes])])
LIBS=$saved_LIBS])
AS_CASE([$utils_cv_dlopen_libcrypto],
[yes],
[AC_DEFINE([DLOPEN_LIBCRYPTO], [1],
[Define to 1 if dlopen exists and libcrypto is
linked dynamically.])
AC_DEFINE_UNQUOTED([LIBCRYPTO_SONAME], ["$LIBCRYPTO_SONAME"],
[versioned libcrypto])
])])
# macOS >= 10.12
AC_CHECK_FUNCS([fclonefileat])
@@ -403,38 +462,6 @@ AC_DEFUN([coreutils_DUMMY_1],
])
coreutils_DUMMY_1
AC_MSG_CHECKING([ut_host in struct utmp])
AC_CACHE_VAL([su_cv_func_ut_host_in_utmp],
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <utmp.h>
struct utmp ut;
int s = sizeof ut.ut_host;]])],
[su_cv_func_ut_host_in_utmp=yes],
[su_cv_func_ut_host_in_utmp=no])])
AC_MSG_RESULT([$su_cv_func_ut_host_in_utmp])
if test $su_cv_func_ut_host_in_utmp = yes; then
have_ut_host=1
AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
fi
if test -z "$have_ut_host"; then
AC_MSG_CHECKING([ut_host in struct utmpx])
AC_CACHE_VAL([su_cv_func_ut_host_in_utmpx],
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <utmpx.h>
struct utmpx ut;
int s = sizeof ut.ut_host;]])],
[su_cv_func_ut_host_in_utmpx=yes],
[su_cv_func_ut_host_in_utmpx=no])])
AC_MSG_RESULT([$su_cv_func_ut_host_in_utmpx])
if test $su_cv_func_ut_host_in_utmpx = yes; then
AC_DEFINE([HAVE_UTMPX_H], [1], [FIXME])
AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
fi
fi
GNULIB_BOOT_TIME([gl_ADD_PROG([optional_bin_progs], [uptime])])
AC_SYS_POSIX_TERMIOS()
gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
@@ -500,11 +527,6 @@ if test $gl_cv_sys_tiocgwinsz_needs_termios_h = no && \
[Define if your system defines TIOCGWINSZ in sys/pty.h.])
fi
# For src/kill.c.
AC_CHECK_DECLS([strsignal, sys_siglist, _sys_siglist, __sys_siglist], , ,
[AC_INCLUDES_DEFAULT
#include <signal.h>])
# Build df only if there's a point to it.
if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
gl_ADD_PROG([optional_bin_progs], [df])
@@ -522,7 +544,8 @@ gl_WARN_ADD([-errwarn], [CFLAGS])
AC_MSG_CHECKING([whether this system supports stdbuf])
CFLAGS="-fPIC $CFLAGS"
LDFLAGS="-shared $LDFLAGS"
stdbuf_supported=no
AC_CACHE_VAL([utils_cv_stdbuf_supported],[
utils_cv_stdbuf_supported=no
# Note we only LINK here rather than RUN to support cross compilation
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
@@ -536,40 +559,69 @@ AC_LINK_IFELSE(
if (stdbuf != 1)
return 1;]])
],
[stdbuf_supported=yes])
AC_MSG_RESULT([$stdbuf_supported])
if test "$stdbuf_supported" = "yes" && test -z "$EXEEXT"; then
[utils_cv_stdbuf_supported=yes])])
AC_MSG_RESULT([$utils_cv_stdbuf_supported])
if test "$utils_cv_stdbuf_supported" = "yes" && test -z "$EXEEXT"; then
gl_ADD_PROG([optional_bin_progs], [stdbuf])
fi
CFLAGS=$ac_save_CFLAGS
LDFLAGS=$ac_save_LDFLAGS
ac_c_werror_flag=$cu_save_c_werror_flag
AC_MSG_CHECKING([if __get_cpuid available])
AC_LINK_IFELSE(
[AC_LANG_SOURCE([[
#include <cpuid.h>
int
main (void)
{
unsigned int eax, ebx, ecx, edx;
__get_cpuid (1, &eax, &ebx, &ecx, &edx);
return 1;
}
# Test compiler support for half precision floating point types (for od)
AC_MSG_CHECKING([IEEE 16 bit floating point])
AC_CACHE_VAL([utils_cv_ieee_16_bit_supported],[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
int
main (void)
{
volatile _Float16 hf = 1;
float f = hf; /* Ensure compiler can promote to float. */
return !(f == 1.0f);
}
]])
],[
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_CPUID], [1], [__get_cpuid available])
cpuid_exists=yes
utils_cv_ieee_16_bit_supported=yes
],[
AC_MSG_RESULT([no])
])
utils_cv_ieee_16_bit_supported=no
],[
utils_cv_ieee_16_bit_supported=no
])])
AC_MSG_RESULT([$utils_cv_ieee_16_bit_supported])
if test $utils_cv_ieee_16_bit_supported = yes; then
AC_DEFINE([FLOAT16_SUPPORTED], [1], [IEEE 16 bit float supported])
fi
AC_MSG_CHECKING([Brain 16 bit floating point])
AC_CACHE_VAL([utils_cv_brain_16_bit_supported],[
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
int
main (void)
{
volatile __bf16 hf = 1;
float f = hf; /* Ensure compiler can promote to float. */
return !(f == 1.0f);
}
]])
],[
utils_cv_brain_16_bit_supported=yes
],[
utils_cv_brain_16_bit_supported=no
],[
utils_cv_brain_16_bit_supported=no
])])
AC_MSG_RESULT([$utils_cv_brain_16_bit_supported])
if test $utils_cv_brain_16_bit_supported = yes; then
AC_DEFINE([BF16_SUPPORTED], [1], [Brain 16 bit float supported])
fi
ac_save_CFLAGS=$CFLAGS
CFLAGS="-mavx -mpclmul $CFLAGS"
AC_MSG_CHECKING([if pclmul intrinsic exists])
AC_COMPILE_IFELSE(
AC_CACHE_VAL([utils_cv_pclmul_intrinsic_exists],[
AC_LINK_IFELSE(
[AC_LANG_SOURCE([[
#include <x86intrin.h>
@@ -578,49 +630,28 @@ AC_COMPILE_IFELSE(
{
__m128i a, b;
a = _mm_clmulepi64_si128 (a, b, 0x00);
return 1;
a = _mm_shuffle_epi8 (a, b);
return __builtin_cpu_supports ("pclmul");
}
]])
],[
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_PCLMUL_INTRINSIC], [1], [pclmul intrinsic exists])
pclmul_intrinsic_exists=yes
utils_cv_pclmul_intrinsic_exists=yes
],[
AC_MSG_RESULT([no])
])
if test "x$cpuid_exists" = "xyes" &&
test "x$pclmul_intrinsic_exists" = "xyes"; then
utils_cv_pclmul_intrinsic_exists=no
])])
AC_MSG_RESULT([$utils_cv_pclmul_intrinsic_exists])
if test $utils_cv_pclmul_intrinsic_exists = yes; then
AC_DEFINE([USE_PCLMUL_CRC32], [1],
[CRC32 calculation by pclmul hardware instruction enabled])
fi
AM_CONDITIONAL([USE_PCLMUL_CRC32],
[test "x$cpuid_exists" = "xyes" &&
test "x$pclmul_intrinsic_exists" = "xyes"])
[test $utils_cv_pclmul_intrinsic_exists = yes])
CFLAGS=$ac_save_CFLAGS
AC_MSG_CHECKING([if __get_cpuid_count exists])
AC_LINK_IFELSE(
[AC_LANG_SOURCE([[
#include <cpuid.h>
int
main (void)
{
unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx);
return 1;
}
]])
],[
AC_MSG_RESULT([yes])
get_cpuid_count_exists=yes
],[
AC_MSG_RESULT([no])
])
CFLAGS="-mavx2 $CFLAGS"
AC_MSG_CHECKING([if avx2 intrinstics exists])
AC_COMPILE_IFELSE(
AC_MSG_CHECKING([for avx2 intrinsics])
AC_CACHE_VAL([utils_cv_avx2_intrinsic_exists],[
AC_LINK_IFELSE(
[AC_LANG_SOURCE([[
#include <x86intrin.h>
@@ -629,23 +660,20 @@ AC_COMPILE_IFELSE(
{
__m256i a, b;
a = _mm256_sad_epu8 (a, b);
return 1;
return __builtin_cpu_supports ("avx2");
}
]])
],[
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_AVX2_INTRINSIC], [1], [avx2 intrinsics exists])
avx2_intrinsic_exists=yes
utils_cv_avx2_intrinsic_exists=yes
],[
AC_MSG_RESULT([no])
])
if test "x$get_cpuid_count_exists" = "xyes" &&
test "x$avx2_intrinsic_exists" = "xyes"; then
utils_cv_avx2_intrinsic_exists=no
])])
AC_MSG_RESULT([$utils_cv_avx2_intrinsic_exists])
if test $utils_cv_avx2_intrinsic_exists = yes; then
AC_DEFINE([USE_AVX2_WC_LINECOUNT], [1], [Counting lines with AVX2 enabled])
fi
AM_CONDITIONAL([USE_AVX2_WC_LINECOUNT],
[test "x$get_cpuid_count_exists" = "xyes" &&
test "x$avx2_intrinsic_exists" = "xyes"])
[test $utils_cv_avx2_intrinsic_exists = yes])
CFLAGS=$ac_save_CFLAGS

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
# Make coreutils documentation. -*-Makefile-*-
# This is included by the top-level Makefile.am.
# Copyright (C) 1995-2023 Free Software Foundation, Inc.
# Copyright (C) 1995-2024 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,10 @@ doc_coreutils_TEXINFOS = \
doc/fdl.texi \
doc/sort-version.texi
# The customization variable CHECK_NORMAL_MENU_STRUCTURE is necessary with
# makeinfo versions ≥ 6.8.
MAKEINFO = @MAKEINFO@ -c CHECK_NORMAL_MENU_STRUCTURE=1
# The following is necessary if the package name is 8 characters or longer.
# If the info documentation would be split into 10 or more separate files,
# then this is necessary even if the package name is 7 characters long.

View File

@@ -1,6 +1,6 @@
@c File mode bits
@c Copyright (C) 1994--2023 Free Software Foundation, Inc.
@c Copyright (C) 1994--2024 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--2023 Free Software Foundation, Inc.
@c Copyright (C) 2019--2024 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
@@ -843,7 +843,7 @@ natsort -- how it works}).
Ruby's @uref{https://github.com/github/version_sorter,version_sorter}.
@item
Perl has multiple packages for natual and version sorts
Perl has multiple packages for natural and version sorts
(each likely with its own rules and nuances):
@uref{https://metacpan.org/pod/Sort::Naturally,Sort::Naturally},
@uref{https://metacpan.org/pod/Sort::Versions,Sort::Versions},
@@ -865,7 +865,7 @@ glob modifier} @samp{*(n)} will expand to files in natural sort order.
When writing C programs, the GNU libc library (@samp{glibc})
provides the
@uref{https://man7.org/linux/man-pages/man3/strverscmp.3.html,
strvercmp(3)} function to compare two strings, and
strverscmp(3)} function to compare two strings, and
@uref{https://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).

View File

@@ -1,6 +1,6 @@
/* buffer-lcm.c - compute a good buffer size for dealing with two files
Copyright (C) 2002-2023 Free Software Foundation, Inc.
Copyright (C) 2002-2024 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-2023 Free Software Foundation, Inc.
Copyright 2019-2024 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
@@ -46,7 +46,7 @@
Parse the initial prefix of NPTR as a floating-point number in the
current locale or in the C locale (preferring the locale that
yields the longer parse, or the current locale if there is a tie).
If ENDPTR is not NULL, set *ENDPTR to the first unused byte, or to
If ENDPTR is non-null, set *ENDPTR to the first unused byte, or to
NPTR if the prefix cannot be parsed.
If successful, return a number without changing errno.

View File

@@ -1,5 +1,5 @@
/* Declare an access pattern hint for files.
Copyright (C) 2010-2023 Free Software Foundation, Inc.
Copyright (C) 2010-2024 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
@@ -14,12 +14,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Without this pragma, gcc suggests that (given !HAVE_POSIX_FADVISE)
the fdadvise function might be a candidate for attribute 'const'. */
#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
# pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
#endif
#include <config.h>
#include "fadvise.h"

View File

@@ -1,5 +1,5 @@
/* Declare an access pattern hint for files.
Copyright (C) 2010-2023 Free Software Foundation, Inc.
Copyright (C) 2010-2024 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-2023 Free Software Foundation, Inc.
Copyright (C) 2005-2024 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-2023 Free Software Foundation, Inc.
Copyright (C) 2005-2024 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 @@
/* Barebones heap implementation supporting only insert and pop.
Copyright (C) 2010-2023 Free Software Foundation, Inc.
Copyright (C) 2010-2024 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
@@ -50,7 +50,7 @@ heap_alloc (int (*compare) (void const *, void const *), size_t n_reserve)
heap->array = xnmalloc (n_reserve, sizeof *(heap->array));
heap->array[0] = NULL;
heap->array[0] = nullptr;
heap->capacity = n_reserve;
heap->count = 0;
heap->compare = compare ? compare : heap_default_compare;
@@ -96,7 +96,7 @@ heap_remove_top (struct heap *heap)
void *top;
if (heap->count == 0)
return NULL;
return nullptr;
top = heap->array[1];
heap->array[1] = heap->array[heap->count--];

View File

@@ -1,6 +1,6 @@
/* Barebones heap implementation supporting only insert and pop.
Copyright (C) 2010-2023 Free Software Foundation, Inc.
Copyright (C) 2010-2024 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,275 +0,0 @@
/* Align/Truncate a string in a given screen width
Copyright (C) 2009-2023 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/>. */
/* Written by Pádraig Brady. */
#include <config.h>
#include "mbsalign.h"
#include "minmax.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#include <wchar.h>
#include <wctype.h>
/* Replace non printable chars.
Note \t and \n etc. are non printable.
Return 1 if replacement made, 0 otherwise. */
static bool
wc_ensure_printable (wchar_t *wchars)
{
bool replaced = false;
wchar_t *wc = wchars;
while (*wc)
{
if (!iswprint ((wint_t) *wc))
{
*wc = 0xFFFD; /* L'\uFFFD' (replacement char) */
replaced = true;
}
wc++;
}
return replaced;
}
/* Truncate wchar string to width cells.
* Returns number of cells used. */
static size_t
wc_truncate (wchar_t *wc, size_t width)
{
size_t cells = 0;
int next_cells = 0;
while (*wc)
{
next_cells = wcwidth (*wc);
if (next_cells == -1) /* non printable */
{
*wc = 0xFFFD; /* L'\uFFFD' (replacement char) */
next_cells = 1;
}
if (cells + next_cells > width)
break;
cells += next_cells;
wc++;
}
*wc = L'\0';
return cells;
}
/* Write N_SPACES space characters to DEST while ensuring
nothing is written beyond DEST_END. A terminating NUL
is always added to DEST.
A pointer to the terminating NUL is returned. */
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? */
while (n_spaces-- && (dest < dest_end))
*dest++ = ' ';
*dest = '\0';
return dest;
}
/* Align a string, SRC, in a field of *WIDTH columns, handling multi-byte
characters; write the result into the DEST_SIZE-byte buffer, DEST.
ALIGNMENT specifies whether to left- or right-justify or to center.
If SRC requires more than *WIDTH columns, truncate it to fit.
When centering, the number of trailing spaces may be one less than the
number of leading spaces.
Return the length in bytes required for the final result, not counting
the trailing NUL. A return value of DEST_SIZE or larger means there
wasn't enough space. DEST will be NUL terminated in any case.
Return SIZE_MAX upon error (invalid multi-byte sequence in SRC,
or malloc failure), unless MBA_UNIBYTE_FALLBACK is specified.
Update *WIDTH to indicate how many columns were used before padding. */
size_t
mbsalign (char const *src, char *dest, size_t dest_size,
size_t *width, mbs_align_t align, int flags)
{
size_t ret = SIZE_MAX;
size_t src_size = strlen (src) + 1;
char *newstr = NULL;
wchar_t *str_wc = NULL;
char const *str_to_print = src;
size_t n_cols = src_size - 1;
size_t n_used_bytes = n_cols; /* Not including NUL */
size_t n_spaces = 0;
bool conversion = false;
bool wc_enabled = false;
/* In multi-byte locales convert to wide characters
to allow easy truncation. Also determine number
of screen columns used. */
if (!(flags & MBA_UNIBYTE_ONLY) && MB_CUR_MAX > 1)
{
size_t src_chars = mbstowcs (NULL, src, 0);
if (src_chars == SIZE_MAX)
{
if (flags & MBA_UNIBYTE_FALLBACK)
goto mbsalign_unibyte;
else
goto mbsalign_cleanup;
}
src_chars += 1; /* make space for NUL */
str_wc = malloc (src_chars * sizeof (wchar_t));
if (str_wc == NULL)
{
if (flags & MBA_UNIBYTE_FALLBACK)
goto mbsalign_unibyte;
else
goto mbsalign_cleanup;
}
if (mbstowcs (str_wc, src, src_chars) != 0)
{
str_wc[src_chars - 1] = L'\0';
wc_enabled = true;
conversion = wc_ensure_printable (str_wc);
n_cols = wcswidth (str_wc, src_chars);
}
}
/* If we transformed or need to truncate the source string
then create a modified copy of it. */
if (wc_enabled && (conversion || (n_cols > *width)))
{
if (conversion)
{
/* May have increased the size by converting
\t to \uFFFD for example. */
src_size = wcstombs (NULL, str_wc, 0) + 1;
}
newstr = malloc (src_size);
if (newstr == NULL)
{
if (flags & MBA_UNIBYTE_FALLBACK)
goto mbsalign_unibyte;
else
goto mbsalign_cleanup;
}
str_to_print = newstr;
n_cols = wc_truncate (str_wc, *width);
n_used_bytes = wcstombs (newstr, str_wc, src_size);
}
mbsalign_unibyte:
if (n_cols > *width) /* Unibyte truncation required. */
{
n_cols = *width;
n_used_bytes = n_cols;
}
if (*width > n_cols) /* Padding required. */
n_spaces = *width - n_cols;
/* indicate to caller how many cells needed (not including padding). */
*width = n_cols;
{
size_t start_spaces, end_spaces;
switch (align)
{
case MBS_ALIGN_LEFT:
start_spaces = 0;
end_spaces = n_spaces;
break;
case MBS_ALIGN_RIGHT:
start_spaces = n_spaces;
end_spaces = 0;
break;
case MBS_ALIGN_CENTER:
default:
start_spaces = n_spaces / 2 + n_spaces % 2;
end_spaces = n_spaces / 2;
break;
}
if (flags & MBA_NO_LEFT_PAD)
start_spaces = 0;
if (flags & MBA_NO_RIGHT_PAD)
end_spaces = 0;
/* Write as much NUL terminated output to DEST as possible. */
if (dest_size != 0)
{
size_t space_left;
char *dest_end = dest + dest_size - 1;
dest = mbs_align_pad (dest, dest_end, start_spaces);
space_left = dest_end - dest;
dest = mempcpy (dest, str_to_print, MIN (n_used_bytes, space_left));
mbs_align_pad (dest, dest_end, end_spaces);
}
/* indicate to caller how many bytes needed (not including NUL). */
ret = n_used_bytes + ((start_spaces + end_spaces) * 1);
}
mbsalign_cleanup:
free (str_wc);
free (newstr);
return ret;
}
/* A wrapper around mbsalign() to dynamically allocate the
minimum amount of memory to store the result.
Return NULL on failure. */
char *
ambsalign (char const *src, size_t *width, mbs_align_t align, int flags)
{
size_t orig_width = *width;
size_t size = *width; /* Start with enough for unibyte mode. */
size_t req = size;
char *buf = NULL;
while (req >= size)
{
char *nbuf;
size = req + 1; /* Space for NUL. */
nbuf = realloc (buf, size);
if (nbuf == NULL)
{
free (buf);
buf = NULL;
break;
}
buf = nbuf;
*width = orig_width;
req = mbsalign (src, buf, size, width, align, flags);
if (req == SIZE_MAX)
{
free (buf);
buf = NULL;
break;
}
}
return buf;
}

View File

@@ -1,63 +0,0 @@
/* Align/Truncate a string in a given screen width
Copyright (C) 2009-2023 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 <stddef.h>
#include <stdlib.h>
typedef enum { MBS_ALIGN_LEFT, MBS_ALIGN_RIGHT, MBS_ALIGN_CENTER } mbs_align_t;
enum {
/* Use unibyte mode for invalid multibyte strings
or when heap memory is exhausted. */
MBA_UNIBYTE_FALLBACK = 0x0001,
/* As an optimization, don't do multibyte processing
when we know no multibyte characters are present. */
MBA_UNIBYTE_ONLY = 0x0002,
/* Don't add leading padding. */
MBA_NO_LEFT_PAD = 0x0004,
/* Don't add trailing padding. */
MBA_NO_RIGHT_PAD = 0x0008
#if 0 /* Other possible options. */
/* Skip invalid multibyte chars rather than failing. */
MBA_IGNORE_INVALID
/* Align multibyte strings using "figure space" (\u2007). */
MBA_USE_FIGURE_SPACE
/* Don't truncate. */
MBA_NO_TRUNCATE
/* Ensure no leading whitespace. */
MBA_LSTRIP
/* Ensure no trailing whitespace. */
MBA_RSTRIP
#endif
};
size_t
mbsalign (char const *src, char *dest, size_t dest_size,
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)
_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-2023 Free Software Foundation, Inc.
Copyright (C) 1999-2024 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-2023 Free Software Foundation, Inc.
Copyright (C) 1999-2024 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 @@
/* Generate random integers.
Copyright (C) 2006-2023 Free Software Foundation, Inc.
Copyright (C) 2006-2024 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
@@ -35,13 +35,13 @@ int
main (int argc, char **argv)
{
randint i;
randint n = strtoumax (argv[1], NULL, 10);
randint choices = strtoumax (argv[2], NULL, 10);
randint n = strtoumax (argv[1], nullptr, 10);
randint choices = strtoumax (argv[2], nullptr, 10);
char const *name = argv[3];
struct randint_source *ints = randint_all_new (name, SIZE_MAX);
for (i = 0; i < n; i++)
printf ("%"PRIuMAX"\n", randint_choose (ints, choices));
printf ("%ju\n", randint_choose (ints, choices));
return (randint_all_free (ints) == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
@@ -77,14 +77,14 @@ randint_new (struct randread_source *source)
}
/* Create a new randint_source by creating a randread_source from
NAME and ESTIMATED_BYTES. Return NULL (setting errno) if
NAME and ESTIMATED_BYTES. Return nullptr (setting errno) if
unsuccessful. */
struct randint_source *
randint_all_new (char const *name, size_t bytes_bound)
{
struct randread_source *source = randread_new (name, bytes_bound);
return (source ? randint_new (source) : NULL);
return (source ? randint_new (source) : nullptr);
}
/* Return the random data source of *S. */

View File

@@ -1,6 +1,6 @@
/* Generate random integers.
Copyright (C) 2006-2023 Free Software Foundation, Inc.
Copyright (C) 2006-2024 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 permutations.
Copyright (C) 2006-2023 Free Software Foundation, Inc.
Copyright (C) 2006-2024 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
@@ -109,7 +109,7 @@ typedef Hash_table sparse_map;
static sparse_map *
sparse_new (size_t size_hint)
{
return hash_initialize (size_hint, NULL, sparse_hash_, sparse_cmp_, free);
return hash_initialize (size_hint, nullptr, sparse_hash_, sparse_cmp_, free);
}
/* Swap the values for I and J. If a value is not already present
@@ -154,7 +154,7 @@ sparse_free (sparse_map *sv)
/* From R, allocate and return a malloc'd array of the first H elements
of a random permutation of N elements. H must not exceed N.
Return NULL if H is zero. */
Return nullptr if H is zero. */
size_t *
randperm_new (struct randint_source *r, size_t h, size_t n)
@@ -164,7 +164,7 @@ randperm_new (struct randint_source *r, size_t h, size_t n)
switch (h)
{
case 0:
v = NULL;
v = nullptr;
break;
case 1:
@@ -209,13 +209,13 @@ randperm_new (struct randint_source *r, size_t h, size_t n)
if (sparse)
{
sv = sparse_new (h * 2);
if (sv == NULL)
if (sv == nullptr)
xalloc_die ();
v = xnmalloc (h, sizeof *v);
}
else
{
sv = NULL; /* To placate GCC's -Wuninitialized. */
sv = nullptr; /* To placate GCC's -Wuninitialized. */
v = xnmalloc (n, sizeof *v);
for (i = 0; i < n; i++)
v[i] = i;

View File

@@ -1,6 +1,6 @@
/* Generate buffers of random data.
Copyright (C) 2006-2023 Free Software Foundation, Inc.
Copyright (C) 2006-2024 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
@@ -38,6 +38,7 @@
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "assure.h"
#include "minmax.h"
#include "rand-isaac.h"
#include "stdio-safer.h"
@@ -45,9 +46,9 @@
#include "xalloc.h"
#if _STRING_ARCH_unaligned || _STRING_INLINE_unaligned
# define ALIGNED_POINTER(ptr, type) true
# define POINTER_IS_ALIGNED(ptr, type) true
#else
# define ALIGNED_POINTER(ptr, type) ((size_t) (ptr) % alignof (type) == 0)
# define POINTER_IS_ALIGNED(ptr, type) ((size_t) (ptr) % alignof (type) == 0)
#endif
/* The maximum buffer size used for reads of random data. Using the
@@ -103,11 +104,10 @@ struct randread_source
static void
randread_error (void const *file_name)
{
if (file_name)
error (exit_failure, errno,
errno == 0 ? _("%s: end of file") : _("%s: read error"),
quote (file_name));
abort ();
affirm (exit_failure);
error (exit_failure, errno,
errno == 0 ? _("%s: end of file") : _("%s: read error"),
quote (file_name));
}
/* Simply return a new randread_source object with the default error
@@ -132,7 +132,13 @@ get_nonce (void *buffer, size_t bufsize)
char *buf = buffer, *buflim = buf + bufsize;
while (buf < buflim)
{
ssize_t nbytes = getrandom (buf, buflim - buf, 0);
#if defined __sun
# define MAX_GETRANDOM 1024
#else
# define MAX_GETRANDOM SIZE_MAX
#endif
size_t max_bytes = MIN (buflim - buf, MAX_GETRANDOM);
ssize_t nbytes = getrandom (buf, max_bytes, 0);
if (0 <= nbytes)
buf += nbytes;
else if (errno != EINTR)
@@ -161,21 +167,21 @@ randread_free_body (struct randread_source *s)
default handler. Unless a non-default handler is used, NAME's
lifetime should be at least that of the returned value.
Return NULL (setting errno) on failure. */
Return nullptr (setting errno) on failure. */
struct randread_source *
randread_new (char const *name, size_t bytes_bound)
{
if (bytes_bound == 0)
return simple_new (NULL, NULL);
return simple_new (nullptr, nullptr);
else
{
FILE *source = NULL;
FILE *source = nullptr;
struct randread_source *s;
if (name)
if (! (source = fopen_safer (name, "rb")))
return NULL;
return nullptr;
s = simple_new (source, name);
@@ -190,7 +196,7 @@ randread_new (char const *name, size_t bytes_bound)
int e = errno;
randread_free_body (s);
errno = e;
return NULL;
return nullptr;
}
isaac_seed (&s->buf.isaac.state);
}
@@ -265,7 +271,7 @@ readisaac (struct isaac *isaac, void *p, size_t size)
/* If P is aligned, write to *P directly to avoid the overhead
of copying from the buffer. */
if (ALIGNED_POINTER (p, isaac_word))
if (POINTER_IS_ALIGNED (p, isaac_word))
{
isaac_word *wp = p;
while (ISAAC_BYTES <= size)

View File

@@ -1,6 +1,6 @@
/* Generate buffers of random data.
Copyright (C) 2006-2023 Free Software Foundation, Inc.
Copyright (C) 2006-2024 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 @@
/* root-dev-ino.c -- get the device and inode numbers for '/'.
Copyright (C) 2003-2023 Free Software Foundation, Inc.
Copyright (C) 2003-2024 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,14 +23,14 @@
#include <stdlib.h>
/* Call lstat to get the device and inode numbers for '/'.
Upon failure, return NULL. Otherwise, set the members of
Upon failure, return nullptr. Otherwise, set the members of
*ROOT_D_I accordingly and return ROOT_D_I. */
struct dev_ino *
get_root_dev_ino (struct dev_ino *root_d_i)
{
struct stat statbuf;
if (lstat ("/", &statbuf))
return NULL;
return nullptr;
root_d_i->st_ino = statbuf.st_ino;
root_d_i->st_dev = statbuf.st_dev;
return root_d_i;

View File

@@ -1,6 +1,6 @@
/* Root device and inode number checking.
Copyright (C) 2003-2023 Free Software Foundation, Inc.
Copyright (C) 2003-2024 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
@@ -28,7 +28,7 @@ get_root_dev_ino (struct dev_ino *root_d_i) _GL_ATTRIBUTE_NONNULL ();
--preserve-root and --no-preserve-root options. */
# define ROOT_DEV_INO_CHECK(Root_dev_ino, Dir_statbuf) \
(Root_dev_ino && SAME_INODE (*Dir_statbuf, *Root_dev_ino))
(Root_dev_ino && PSAME_INODE (Dir_statbuf, Root_dev_ino))
# define ROOT_DEV_INO_WARN(Dirname) \
do \

3
gl/lib/skipchars.c Normal file
View File

@@ -0,0 +1,3 @@
#include <config.h>
#define SKIPCHARS_INLINE _GL_EXTERN_INLINE
#include <skipchars.h>

56
gl/lib/skipchars.h Normal file
View File

@@ -0,0 +1,56 @@
/* Skipping sequences of characters satisfying a predicate
Copyright 2023-2024 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 "mcel.h"
_GL_INLINE_HEADER_BEGIN
#ifndef SKIPCHARS_INLINE
# define SKIPCHARS_INLINE _GL_INLINE
#endif
/* Return the address just past the leading sequence of possibly
multi-byte characters or encoding errors G in STR that satisfy
PREDICATE (G) if OK is true, or that do not satisfy the predicate
call if OK is false. */
SKIPCHARS_INLINE char *
skip_str_matching (char const *str, bool (*predicate) (mcel_t), bool ok)
{
char const *s = str;
for (mcel_t g; *s && predicate (g = mcel_scanz (s)) == ok;
s += g.len)
continue;
return (char *) s;
}
/* Return the address just past the leading sequence of possibly
multi-byte characters or encoding errors G in BUF (which ends at LIM)
that satisfy PREDICATE (G) if OK is true, or that do not satisfy
the predicate call if OK is false. */
SKIPCHARS_INLINE char *
skip_buf_matching (char const *buf, char const *lim,
bool (*predicate) (mcel_t), bool ok)
{
char const *s = buf;
for (mcel_t g; s < lim && predicate (g = mcel_scan (s, lim)) == ok;
s += g.len)
continue;
return (char *) s;
}
_GL_INLINE_HEADER_END

View File

@@ -1,5 +1,5 @@
/* Include and determine availability of smack routines
Copyright (C) 2013-2023 Free Software Foundation, Inc.
Copyright (C) 2013-2024 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
@@ -37,7 +37,7 @@ static inline bool
is_smack_enabled (void)
{
#ifdef HAVE_SMACK
return smack_smackfs_path () != NULL;
return smack_smackfs_path () != nullptr;
#else
return false;
#endif

View File

@@ -1,6 +1,6 @@
/* Compare integer strings.
Copyright (C) 2005-2023 Free Software Foundation, Inc.
Copyright (C) 2005-2024 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 numeric strings. This is an internal include file.
Copyright (C) 1988-2023 Free Software Foundation, Inc.
Copyright (C) 1988-2024 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
@@ -114,8 +114,8 @@ static inline int _GL_ATTRIBUTE_PURE
numcompare (char const *a, char const *b,
int decimal_point, int thousands_sep)
{
unsigned char tmpa = *a;
unsigned char tmpb = *b;
char tmpa = *a;
char tmpb = *b;
int tmp;
size_t log_a;
size_t log_b;

View File

@@ -1,6 +1,6 @@
/* Compare numeric strings.
Copyright (C) 2005-2023 Free Software Foundation, Inc.
Copyright (C) 2005-2024 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 @@
/* Target directory operands for coreutils
Copyright 2004-2023 Free Software Foundation, Inc.
Copyright 2004-2024 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 @@
/* Target directory operands for coreutils
Copyright 2022-2023 Free Software Foundation, Inc.
Copyright 2022-2024 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 decimal strings with bounds checking and exit on error.
Copyright (C) 2014-2023 Free Software Foundation, Inc.
Copyright (C) 2014-2024 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,12 +21,12 @@
#include <errno.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdlib.h>
#include "error.h"
#include "quote.h"
#include "verify.h"
#include "xstrtol.h"
#include <error.h>
#include <quote.h>
#include <xstrtol.h>
/* Parse numeric string N_STR of base BASE, and return the value.
Exit on parse error or if MIN or MAX are exceeded.
@@ -40,7 +40,7 @@ __xnumtoint (char const *n_str, int base, __xdectoint_t min, __xdectoint_t max,
strtol_error s_err;
__xdectoint_t tnum;
s_err = __xstrtol (n_str, NULL, base, &tnum, suffixes);
s_err = __xstrtol (n_str, nullptr, base, &tnum, suffixes);
if (s_err == LONGINT_OK)
{
@@ -69,7 +69,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);
unreachable ();
}
return tnum;

View File

@@ -1,6 +1,6 @@
/* Convert decimal strings with bounds checking and exit on error.
Copyright (C) 2014-2023 Free Software Foundation, Inc.
Copyright (C) 2014-2024 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 @@
/* xfts.c -- a wrapper for fts_open
Copyright (C) 2003-2023 Free Software Foundation, Inc.
Copyright (C) 2003-2024 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,8 +21,8 @@
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include "assure.h"
#include "xalloc.h"
#include "xfts.h"
@@ -33,11 +33,11 @@ xfts_open (char * const *argv, int options,
int (*compar) (const FTSENT **, const FTSENT **))
{
FTS *fts = fts_open (argv, options | FTS_CWDFD, compar);
if (fts == NULL)
if (fts == nullptr)
{
/* This can fail in two ways: out of memory or with errno==EINVAL,
which indicates it was called with invalid bit_flags. */
assert (errno != EINVAL);
affirm (errno != EINVAL);
xalloc_die ();
}

View File

@@ -1,28 +0,0 @@
Description:
Align/Truncate a string in a given screen width.
Files:
lib/mbsalign.c
lib/mbsalign.h
Depends-on:
minmax
wchar
wctype
wcwidth
mempcpy
stdint
configure.ac:
Makefile.am:
lib_SOURCES += mbsalign.c mbsalign.h
Include:
"mbsalign.h"
License:
LGPL
Maintainer:
Pádraig Brady

View File

@@ -1,11 +0,0 @@
Files:
tests/test-mbsalign.c
tests/macros.h
Depends-on:
configure.ac:
Makefile.am:
TESTS += test-mbsalign
check_PROGRAMS += test-mbsalign

24
gl/modules/skipchars Normal file
View File

@@ -0,0 +1,24 @@
Description:
Skip sequences of multi-byte characters or encoding errors
Files:
lib/skipchars.c
lib/skipchars.h
Depends-on:
extern-inline
mcel
configure.ac:
Makefile.am:
lib_SOURCES += skipchars.c
Include:
"skipchars.h"
License:
GPL
Maintainer:
all

View File

@@ -1,5 +1,5 @@
/* Test that fadvise works as advertised.
Copyright (C) 2010-2023 Free Software Foundation, Inc.
Copyright (C) 2010-2024 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
@@ -36,7 +36,7 @@ main (void)
fdadvise (fileno (stdin), 0, 0, FADVISE_RANDOM);
/* Ignored. */
fadvise (NULL, FADVISE_RANDOM);
fadvise (nullptr, FADVISE_RANDOM);
/* Invalid. */
fdadvise (42, 0, 0, FADVISE_RANDOM);

View File

@@ -1,138 +0,0 @@
/* Test that mbsalign works as advertised.
Copyright (C) 2010-2023 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/>. */
/* Written by Pádraig Brady. */
#include <config.h>
#include "mbsalign.h"
#include "macros.h"
#include <stdlib.h>
#include <locale.h>
int
main (void)
{
char dest[4 * 16 + 1];
size_t width, n;
/* Test unibyte truncation. */
width = 4;
n = mbsalign ("t\tés", dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0);
ASSERT (n == 4);
/* Test center alignment. */
width = 4;
n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_CENTER, 0);
ASSERT (*dest == ' ' && *(dest + n - 1) == ' ');
ASSERT (n == 4);
/* Test center alignment, with no trailing padding. */
width = 4;
n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_CENTER,
MBA_NO_RIGHT_PAD);
ASSERT (n == 3);
ASSERT (*dest == ' ' && *(dest + n - 1) == 's');
/* Test left alignment, with no trailing padding. (truncate only). */
width = 4;
n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_LEFT,
MBA_NO_RIGHT_PAD);
ASSERT (n == 2);
ASSERT (*dest == 'e' && *(dest + n - 1) == 's');
/* Test center alignment, with no padding. (truncate only). */
width = 4;
n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_CENTER,
MBA_NO_LEFT_PAD | MBA_NO_RIGHT_PAD);
ASSERT (n == 2);
ASSERT (*dest == 'e' && *(dest + n - 1) == 's');
/* Test center alignment, with no left padding. (may be useful for RTL?) */
width = 4;
n = mbsalign ("es", dest, sizeof dest, &width, MBS_ALIGN_CENTER,
MBA_NO_LEFT_PAD);
ASSERT (n == 3);
ASSERT (*dest == 'e' && *(dest + n - 1) == ' ');
if (setlocale (LC_ALL, "en_US.UTF8"))
{
/* Check invalid input is flagged. */
width = 4;
n = mbsalign ("t\xe1\xe2s", dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0);
ASSERT (n == (size_t) -1);
/* Check invalid input is treated as unibyte */
width = 4;
n = mbsalign ("t\xe1\xe2s", dest, sizeof dest, &width,
MBS_ALIGN_LEFT, MBA_UNIBYTE_FALLBACK);
ASSERT (n == 4);
/* Test multibyte center alignment. */
width = 4;
n = mbsalign ("és", dest, sizeof dest, &width, MBS_ALIGN_CENTER, 0);
ASSERT (n == 5);
ASSERT (*dest == ' ' && *(dest + n - 1) == ' ');
/* Test multibyte left alignment. */
width = 4;
n = mbsalign ("és", dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0);
ASSERT (n == 5);
ASSERT (*(dest + n - 1) == ' ' && *(dest + n - 2) == ' ');
/* Test multibyte right alignment. */
width = 4;
n = mbsalign ("és", dest, sizeof dest, &width, MBS_ALIGN_RIGHT, 0);
ASSERT (n == 5);
ASSERT (*(dest) == ' ' && *(dest + 1) == ' ');
/* multibyte multicell truncation. */
width = 4; /* cells */
n = mbsalign ("日月火水", dest, sizeof dest, &width,
MBS_ALIGN_LEFT, 0);
ASSERT (n == 6); /* 2 characters */
/* multibyte unicell truncation. */
width = 3; /* cells */
n = mbsalign ("¹²³⁴", dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0);
ASSERT (n == 6); /* 3 characters */
/* Check independence from dest buffer. */
width = 4; /* cells */
n = mbsalign ("¹²³⁴", dest, 0, &width, MBS_ALIGN_LEFT, 0);
ASSERT (n == 9); /* 4 characters */
/* Check that width is updated with cells required before padding. */
width = 4; /* cells */
n = mbsalign ("¹²³", dest, 0, &width, MBS_ALIGN_LEFT, 0);
ASSERT (width == 3);
/* Test case where output is larger than input
(as tab converted to multi byte replacement char). */
width = 4;
n = mbsalign ("t\tés" /* 6 including NUL */ , dest, sizeof dest,
&width, MBS_ALIGN_LEFT, 0);
ASSERT (n == 7);
/* Test forced unibyte truncation. */
width = 4;
n = mbsalign ("t\tés", dest, sizeof dest, &width, MBS_ALIGN_LEFT,
MBA_UNIBYTE_ONLY);
ASSERT (n == 4);
}
return 0;
}

View File

@@ -1,6 +1,6 @@
/* Test the ISAAC or ISAAC64 pseudorandom number generator.
Copyright (C) 2010-2023 Free Software Foundation, Inc.
Copyright (C) 2010-2024 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
@@ -581,7 +581,7 @@ main (int argc, char **argv)
/* If invoked with a positive argument, run a benchmark;
if with a negative, run a do-nothing benchmark. */
for (iterations = argc <= 1 ? 0 : strtol (argv[1], NULL, 10);
for (iterations = argc <= 1 ? 0 : strtol (argv[1], nullptr, 10);
iterations != 0;
iterations += (iterations < 0 ? 1 : -1))
if (0 <= iterations)

2
gnulib

Submodule gnulib updated: 4b60490554...259829e78b

View File

@@ -1,6 +1,6 @@
# This file is sourced by init.sh, *before* its initialization.
# Copyright (C) 2010-2023 Free Software Foundation, Inc.
# Copyright (C) 2010-2024 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
@@ -275,7 +275,7 @@ require_valgrind_()
# If the given ACL spec would not change the ACLs on the file, then setfacl
# does not invoke the underlying system call - setxattr(). Therefore, to test
# if setting ACLs really works on the current file system, call setfacl twice
# with conflictive ACL specs.
# with conflicting ACL specs.
require_setfacl_()
{
local d='acltestdir_'
@@ -539,7 +539,7 @@ require_trap_signame_()
# dash 0.5.8 at least does not.
require_kill_group_()
{
kill -0 -- -1 || skip_ 'requires kill with group signalling support'
kill -0 -- -1 || skip_ 'requires kill with group signaling support'
}
# Return nonzero if the specified path is on a file system for

View File

@@ -1,7 +1,7 @@
#!/bin/sh
# Exercise chdir-long's sample main program.
# Copyright (C) 2005-2023 Free Software Foundation, Inc.
# Copyright (C) 2005-2024 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 +0,0 @@
# boottime.m4 serial 4
# Determine whether this system has infrastructure for obtaining the boot time.
# Copyright (C) 1996-2023 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/>.
# GNULIB_BOOT_TIME([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
* ----------------------------------------------------------
AC_DEFUN([GNULIB_BOOT_TIME],
[
AC_CHECK_FUNCS([sysctl])
AC_CHECK_HEADERS_ONCE([sys/param.h])
AC_CHECK_HEADERS([sys/sysctl.h], [], [],
[AC_INCLUDES_DEFAULT
[#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif]])
AC_CHECK_HEADERS_ONCE([utmpx.h OS.h])
AC_CACHE_CHECK(
[whether we can get the system boot time],
[gnulib_cv_have_boot_time],
[
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[AC_INCLUDES_DEFAULT
#if HAVE_SYSCTL && HAVE_SYS_SYSCTL_H
# if HAVE_SYS_PARAM_H
# include <sys/param.h> /* needed for OpenBSD 3.0 */
# endif
# include <sys/sysctl.h>
#endif
#if HAVE_UTMPX_H
# include <utmpx.h>
#endif
#include <utmp.h>
#if HAVE_OS_H
# include <OS.h>
#endif
],
[[
#if (defined BOOT_TIME \
|| (defined CTL_KERN && defined KERN_BOOTTIME) \
|| HAVE_OS_H)
/* your system *does* have the infrastructure to determine boot time */
#else
please_tell_us_how_to_determine_boot_time_on_your_system
#endif
]])],
[gnulib_cv_have_boot_time=yes],
[gnulib_cv_have_boot_time=no])
])
AS_IF([test $gnulib_cv_have_boot_time = yes], [$1], [$2])
])

View File

@@ -1,7 +1,7 @@
#serial 27
# Check declarations for this package.
dnl Copyright (C) 1997-2023 Free Software Foundation, Inc.
dnl Copyright (C) 1997-2024 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-2023 Free Software Foundation, Inc.
dnl Copyright (C) 2007-2024 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

@@ -1,8 +1,8 @@
#serial 114 -*- autoconf -*-
#serial 115 -*- autoconf -*-
dnl Misc type-related macros for coreutils.
# Copyright (C) 1998-2023 Free Software Foundation, Inc.
# Copyright (C) 1998-2024 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
@@ -67,16 +67,11 @@ AC_DEFUN([coreutils_MACROS],
fallocate
fchown
fchmod
ftruncate
iswspace
mkfifo
mbrlen
setgroups
sethostname
siginterrupt
sync
syncfs
sysctl
sysinfo
tcgetpgrp
])
@@ -94,22 +89,6 @@ AC_DEFUN([coreutils_MACROS],
dnl This can't use AC_REQUIRE; I'm not quite sure why.
cu_PREREQ_STAT_PROG
# for dd.c and shred.c
#
# Use fdatasync only if declared. On MacOS X 10.7, fdatasync exists but
# is not declared, and is ineffective.
LIB_FDATASYNC=
AC_SUBST([LIB_FDATASYNC])
AC_CHECK_DECLS_ONCE([fdatasync])
if test $ac_cv_have_decl_fdatasync = yes; then
coreutils_saved_libs=$LIBS
AC_SEARCH_LIBS([fdatasync], [rt posix4],
[test "$ac_cv_search_fdatasync" = "none required" ||
LIB_FDATASYNC=$ac_cv_search_fdatasync])
AC_CHECK_FUNCS([fdatasync])
LIBS=$coreutils_saved_libs
fi
# Check whether libcap is usable -- for ls --color support
LIB_CAP=
AC_ARG_ENABLE([libcap],

View File

@@ -7,7 +7,7 @@ m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl
# directory of the coreutils package.
# Copyright (C) 1998-2023 Free Software Foundation, Inc.
# Copyright (C) 1998-2024 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-2023 Free Software Foundation, Inc.
# Copyright (C) 2002-2024 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,4 +1,4 @@
'\" Copyright (C) 2018-2023 Free Software Foundation, Inc.
'\" Copyright (C) 2018-2024 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>.
@@ -7,7 +7,7 @@
basenc \- Encode/decode data and print to standard output
[DESCRIPTION]
.\" Add any additional description here
[ENCODINGS EXAMPLES]
[ENCODING EXAMPLES]
.PP
.nf
.RS

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2023 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2024 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>.
@@ -60,17 +60,19 @@ file's group, with the same values; and the fourth for other users not
in the file's group, with the same values.
.PP
.B chmod
never changes the permissions of symbolic links; the
doesn't change the permissions of symbolic links; the
.B chmod
system call cannot change their permissions. This is not a problem
since the permissions of symbolic links are never used.
system call cannot change their permissions on most systems,
and most systems ignore permissions of symbolic links.
However, for each symbolic link listed on the command line,
.B chmod
changes the permissions of the pointed-to file.
In contrast,
.B chmod
ignores symbolic links encountered during recursive directory
traversals.
traversals. Options that modify this behavior are described in the
.B OPTIONS
section.
.SH "SETUID AND SETGID BITS"
.B chmod
clears the set-group-ID bit of a

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2023 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2024 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 @@
cp \- copy files and directories
[DESCRIPTION]
.\" Add any additional description here
[SEE ALSO]
install(1)

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2023 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2024 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>.
@@ -24,6 +24,6 @@ shows the space available on that file system rather than on the
file system containing the device node. This version of
.B df
cannot show the space available on unmounted file systems, because on
most kinds of systems doing so requires very nonportable intimate
most kinds of systems doing so requires non-portable intimate
knowledge of file system structures.
.SH OPTIONS

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2023 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2024 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-2023 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2024 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 @@
install \- copy files and set attributes
[DESCRIPTION]
.\" Add any additional description here
[SEE ALSO]
cp(1)

View File

@@ -1,7 +1,7 @@
# Make coreutils man pages. -*-Makefile-*-
# This is included by the top-level Makefile.am.
# Copyright (C) 2002-2023 Free Software Foundation, Inc.
# Copyright (C) 2002-2024 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

@@ -2,7 +2,7 @@
readlink \- print resolved symbolic links or canonical file names
[DESCRIPTION]
.\" Add any additional description here
Note realpath(1) is the preferred command to use
realpath(1) is a better command
for canonicalization functionality.
[SEE ALSO]
readlink(2), realpath(1), realpath(3)

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 1998-2023 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2024 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

@@ -10,5 +10,4 @@ the first argument is used as the complete context. Any additional
arguments after \fICOMMAND\fR are interpreted as arguments to the
command.
.PP
Note that only carefully-chosen contexts are likely to successfully
run.
Only carefully-chosen contexts are likely to run successfully.

View File

@@ -1,4 +1,4 @@
'\" Copyright (C) 2009-2023 Free Software Foundation, Inc.
'\" Copyright (C) 2009-2024 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-2023 Free Software Foundation, Inc.
'\" Copyright (C) 1998-2024 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,14 +1,14 @@
# List of files which contain translatable strings.
# Copyright (C) 1996-2023 Free Software Foundation, Inc.
# Copyright (C) 1996-2024 Free Software Foundation, Inc.
# These are nominally temporary...
lib/argmatch.c
lib/argmatch.h
lib/c-file-type.c
lib/closein.c
lib/closeout.c
lib/copy-acl.c
lib/error.c
lib/file-type.c
lib/gai_strerror.c
lib/getopt.c
lib/mkdir-p.c
@@ -38,7 +38,6 @@ src/basename.c
src/basenc.c
src/cat.c
src/chcon.c
src/chgrp.c
src/chmod.c
src/chown-core.c
src/chown.c
@@ -125,6 +124,7 @@ src/tac-pipe.c
src/tac.c
src/tail.c
src/tee.c
src/temp-stream.c
src/test.c
src/timeout.c
src/touch.c

View File

@@ -32,7 +32,7 @@ Older version (pre 7.2) mention 'tee','eaccess','futimens'.
Details
-------
GLibC version 2.28 removed non-standed headre file (libio.h) and some
GLibC version 2.28 removed a non-standard header file (libio.h) and some
internal symbols which were used by gnulib (a core component of GNU coreutils).
These were announced as 'deprecated' in version 2.27 [1], and removed in
@@ -164,7 +164,7 @@ By adding the directory to your $PATH, older versions can be easily used:
========================================================================
Copyright (C) 2019-2023 Free Software Foundation, Inc.
Copyright (C) 2019-2024 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-2023 Free Software Foundation, Inc.
# Copyright (C) 2019-2024 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

@@ -1,5 +1,5 @@
/* basename -- strip directory and suffix from file names
Copyright (C) 1990-2023 Free Software Foundation, Inc.
Copyright (C) 1990-2024 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,6 @@
#include <sys/types.h>
#include "system.h"
#include "error.h"
#include "quote.h"
/* The official name of this program (e.g., no 'g' prefix). */
@@ -30,12 +29,12 @@
static struct option const longopts[] =
{
{"multiple", no_argument, NULL, 'a'},
{"suffix", required_argument, NULL, 's'},
{"zero", no_argument, NULL, 'z'},
{"multiple", no_argument, nullptr, 'a'},
{"suffix", required_argument, nullptr, 's'},
{"zero", no_argument, nullptr, 'z'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
{nullptr, 0, nullptr, 0}
};
void
@@ -97,7 +96,7 @@ remove_suffix (char *name, char const *suffix)
*np = '\0';
}
/* Perform the basename operation on STRING. If SUFFIX is non-NULL, remove
/* Perform the basename operation on STRING. If SUFFIX is non-null, remove
the trailing SUFFIX. Finally, output the result string. */
static void
@@ -125,7 +124,7 @@ main (int argc, char **argv)
{
bool multiple_names = false;
bool use_nuls = false;
char const *suffix = NULL;
char const *suffix = nullptr;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -137,7 +136,7 @@ main (int argc, char **argv)
while (true)
{
int c = getopt_long (argc, argv, "+as:z", longopts, NULL);
int c = getopt_long (argc, argv, "+as:z", longopts, nullptr);
if (c == -1)
break;
@@ -184,7 +183,8 @@ main (int argc, char **argv)
}
else
perform_basename (argv[optind],
optind + 2 == argc ? argv[optind + 1] : NULL, use_nuls);
optind + 2 == argc ? argv[optind + 1] : nullptr,
use_nuls);
return EXIT_SUCCESS;
}

View File

@@ -1,5 +1,5 @@
/* Base64, base32, and similar encoding/decoding strings or files.
Copyright (C) 2004-2023 Free Software Foundation, Inc.
Copyright (C) 2004-2024 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,11 +23,9 @@
#include <sys/types.h>
#include "system.h"
#include "assure.h"
#include "c-ctype.h"
#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "idx.h"
#include "quote.h"
#include "xstrtol.h"
#include "xdectoint.h"
@@ -50,7 +48,7 @@
#elif BASE_TYPE == 42
# include "base32.h"
# include "base64.h"
# include <assert.h>
# include "assure.h"
# define PROGRAM_NAME "basenc"
#else
# error missing/invalid BASE_TYPE definition
@@ -89,7 +87,7 @@ static struct option const long_options[] =
#endif
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
{nullptr, 0, nullptr, 0}
};
void
@@ -175,10 +173,37 @@ from any other non-alphabet bytes in the encoded stream.\n"),
exit (status);
}
#if BASE_TYPE != 64
static int
base32_required_padding (int len)
{
int partial = len % 8;
return partial ? 8 - partial : 0;
}
#endif
#if BASE_TYPE != 32
static int
base64_required_padding (int len)
{
int partial = len % 4;
return partial ? 4 - partial : 0;
}
#endif
#if BASE_TYPE == 42
static int
no_required_padding (int len)
{
return 0;
}
#endif
#define ENC_BLOCKSIZE (1024 * 3 * 10)
#if BASE_TYPE == 32
# define BASE_LENGTH BASE32_LENGTH
# define REQUIRED_PADDING base32_required_padding
/* Note that increasing this may decrease performance if --ignore-garbage
is used, because of the memmove operation below. */
# define DEC_BLOCKSIZE (1024 * 5)
@@ -191,9 +216,10 @@ static_assert (DEC_BLOCKSIZE % 40 == 0); /* Complete encoded blocks are used. */
# define base_decode_context base32_decode_context
# define base_decode_ctx_init base32_decode_ctx_init
# define base_decode_ctx base32_decode_ctx
# define isbase isbase32
# define isubase isubase32
#elif BASE_TYPE == 64
# define BASE_LENGTH BASE64_LENGTH
# define REQUIRED_PADDING base64_required_padding
/* Note that increasing this may decrease performance if --ignore-garbage
is used, because of the memmove operation below. */
# define DEC_BLOCKSIZE (1024 * 3)
@@ -206,11 +232,12 @@ static_assert (DEC_BLOCKSIZE % 12 == 0); /* Complete encoded blocks are used. */
# define base_decode_context base64_decode_context
# define base_decode_ctx_init base64_decode_ctx_init
# define base_decode_ctx base64_decode_ctx
# define isbase isbase64
# define isubase isubase64
#elif BASE_TYPE == 42
# define BASE_LENGTH base_length
# define REQUIRED_PADDING required_padding
/* Note that increasing this may decrease performance if --ignore-garbage
is used, because of the memmove operation below. */
@@ -219,14 +246,15 @@ static_assert (DEC_BLOCKSIZE % 40 == 0); /* complete encoded blocks for base32*/
static_assert (DEC_BLOCKSIZE % 12 == 0); /* complete encoded blocks for base64*/
static int (*base_length) (int i);
static bool (*isbase) (char ch);
static int (*required_padding) (int i);
static bool (*isubase) (unsigned char ch);
static void (*base_encode) (char const *restrict in, idx_t inlen,
char *restrict out, idx_t outlen);
struct base16_decode_context
{
char nibble;
bool have_nibble;
/* Either a 4-bit nibble, or negative if we have no nibble. */
signed char nibble;
};
struct z85_decode_context
@@ -322,10 +350,10 @@ base64url_encode (char const *restrict in, idx_t inlen,
}
static bool
isbase64url (char ch)
isubase64url (unsigned char ch)
{
return (ch == '-' || ch == '_'
|| (ch != '+' && ch != '/' && isbase64 (ch)));
|| (ch != '+' && ch != '/' && isubase64 (ch)));
}
static void
@@ -435,7 +463,7 @@ static const char base32_hex_to_norm[32 + 9] = {
inline static bool
isbase32hex (char ch)
isubase32hex (unsigned char ch)
{
return ('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'V');
}
@@ -449,7 +477,7 @@ base32hex_encode (char const *restrict in, idx_t inlen,
for (char *p = out; outlen--; p++)
{
assert (0x32 <= *p && *p <= 0x5a); /* LCOV_EXCL_LINE */
affirm (0x32 <= *p && *p <= 0x5a); /* LCOV_EXCL_LINE */
*p = base32_norm_to_hex[*p - 0x32];
}
}
@@ -474,8 +502,8 @@ base32hex_decode_ctx_wrapper (struct base_decode_context *ctx,
char *p = ctx->inbuf;
while (i--)
{
if (isbase32hex (*in))
*p = base32_hex_to_norm[ (int)*in - 0x30];
if (isubase32hex (*in))
*p = base32_hex_to_norm[*in - 0x30];
else
*p = *in;
++p;
@@ -488,12 +516,105 @@ base32hex_decode_ctx_wrapper (struct base_decode_context *ctx,
return b;
}
/* With this approach this file works independent of the charset used
(think EBCDIC). However, it does assume that the characters in the
Base32 alphabet (A-Z2-7) are encoded in 0..255. POSIX
1003.1-2001 require that char and unsigned char are 8-bit
quantities, though, taking care of that problem. But this may be a
potential problem on non-POSIX C99 platforms.
IBM C V6 for AIX mishandles "#define B32(x) ...'x'...", so use "_"
as the formal parameter rather than "x". */
# define B16(_) \
((_) == '0' ? 0 \
: (_) == '1' ? 1 \
: (_) == '2' ? 2 \
: (_) == '3' ? 3 \
: (_) == '4' ? 4 \
: (_) == '5' ? 5 \
: (_) == '6' ? 6 \
: (_) == '7' ? 7 \
: (_) == '8' ? 8 \
: (_) == '9' ? 9 \
: (_) == 'A' || (_) == 'a' ? 10 \
: (_) == 'B' || (_) == 'b' ? 11 \
: (_) == 'C' || (_) == 'c' ? 12 \
: (_) == 'D' || (_) == 'd' ? 13 \
: (_) == 'E' || (_) == 'e' ? 14 \
: (_) == 'F' || (_) == 'f' ? 15 \
: -1)
static signed char const base16_to_int[256] = {
B16 (0), B16 (1), B16 (2), B16 (3),
B16 (4), B16 (5), B16 (6), B16 (7),
B16 (8), B16 (9), B16 (10), B16 (11),
B16 (12), B16 (13), B16 (14), B16 (15),
B16 (16), B16 (17), B16 (18), B16 (19),
B16 (20), B16 (21), B16 (22), B16 (23),
B16 (24), B16 (25), B16 (26), B16 (27),
B16 (28), B16 (29), B16 (30), B16 (31),
B16 (32), B16 (33), B16 (34), B16 (35),
B16 (36), B16 (37), B16 (38), B16 (39),
B16 (40), B16 (41), B16 (42), B16 (43),
B16 (44), B16 (45), B16 (46), B16 (47),
B16 (48), B16 (49), B16 (50), B16 (51),
B16 (52), B16 (53), B16 (54), B16 (55),
B16 (56), B16 (57), B16 (58), B16 (59),
B16 (60), B16 (61), B16 (62), B16 (63),
B16 (32), B16 (65), B16 (66), B16 (67),
B16 (68), B16 (69), B16 (70), B16 (71),
B16 (72), B16 (73), B16 (74), B16 (75),
B16 (76), B16 (77), B16 (78), B16 (79),
B16 (80), B16 (81), B16 (82), B16 (83),
B16 (84), B16 (85), B16 (86), B16 (87),
B16 (88), B16 (89), B16 (90), B16 (91),
B16 (92), B16 (93), B16 (94), B16 (95),
B16 (96), B16 (97), B16 (98), B16 (99),
B16 (100), B16 (101), B16 (102), B16 (103),
B16 (104), B16 (105), B16 (106), B16 (107),
B16 (108), B16 (109), B16 (110), B16 (111),
B16 (112), B16 (113), B16 (114), B16 (115),
B16 (116), B16 (117), B16 (118), B16 (119),
B16 (120), B16 (121), B16 (122), B16 (123),
B16 (124), B16 (125), B16 (126), B16 (127),
B16 (128), B16 (129), B16 (130), B16 (131),
B16 (132), B16 (133), B16 (134), B16 (135),
B16 (136), B16 (137), B16 (138), B16 (139),
B16 (140), B16 (141), B16 (142), B16 (143),
B16 (144), B16 (145), B16 (146), B16 (147),
B16 (148), B16 (149), B16 (150), B16 (151),
B16 (152), B16 (153), B16 (154), B16 (155),
B16 (156), B16 (157), B16 (158), B16 (159),
B16 (160), B16 (161), B16 (162), B16 (163),
B16 (132), B16 (165), B16 (166), B16 (167),
B16 (168), B16 (169), B16 (170), B16 (171),
B16 (172), B16 (173), B16 (174), B16 (175),
B16 (176), B16 (177), B16 (178), B16 (179),
B16 (180), B16 (181), B16 (182), B16 (183),
B16 (184), B16 (185), B16 (186), B16 (187),
B16 (188), B16 (189), B16 (190), B16 (191),
B16 (192), B16 (193), B16 (194), B16 (195),
B16 (196), B16 (197), B16 (198), B16 (199),
B16 (200), B16 (201), B16 (202), B16 (203),
B16 (204), B16 (205), B16 (206), B16 (207),
B16 (208), B16 (209), B16 (210), B16 (211),
B16 (212), B16 (213), B16 (214), B16 (215),
B16 (216), B16 (217), B16 (218), B16 (219),
B16 (220), B16 (221), B16 (222), B16 (223),
B16 (224), B16 (225), B16 (226), B16 (227),
B16 (228), B16 (229), B16 (230), B16 (231),
B16 (232), B16 (233), B16 (234), B16 (235),
B16 (236), B16 (237), B16 (238), B16 (239),
B16 (240), B16 (241), B16 (242), B16 (243),
B16 (244), B16 (245), B16 (246), B16 (247),
B16 (248), B16 (249), B16 (250), B16 (251),
B16 (252), B16 (253), B16 (254), B16 (255)
};
static bool
isbase16 (char ch)
isubase16 (unsigned char ch)
{
return ('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F');
return ch < sizeof base16_to_int && 0 <= base16_to_int[ch];
}
static int
@@ -502,18 +623,21 @@ base16_length (int len)
return len * 2;
}
static const char base16[16] = "0123456789ABCDEF";
static void
base16_encode (char const *restrict in, idx_t inlen,
char *restrict out, idx_t outlen)
{
while (inlen--)
static const char base16[16] = "0123456789ABCDEF";
while (inlen && outlen)
{
unsigned char c = *in;
*out++ = base16[c >> 4];
*out++ = base16[c & 0x0F];
++in;
inlen--;
outlen -= 2;
}
}
@@ -522,7 +646,7 @@ static void
base16_decode_ctx_init (struct base_decode_context *ctx)
{
init_inbuf (ctx);
ctx->ctx.base16.have_nibble = false;
ctx->ctx.base16.nibble = -1;
ctx->i = 1;
}
@@ -533,44 +657,42 @@ base16_decode_ctx (struct base_decode_context *ctx,
char *restrict out, idx_t *outlen)
{
bool ignore_lines = true; /* for now, always ignore them */
*outlen = 0;
char *out0 = out;
signed char nibble = ctx->ctx.base16.nibble;
/* inlen==0 is request to flush output.
if there is a dangling high nibble - we are missing the low nibble,
so return false - indicating an invalid input. */
if (inlen == 0)
return !ctx->ctx.base16.have_nibble;
{
*outlen = 0;
return nibble < 0;
}
while (inlen--)
{
if (ignore_lines && *in == '\n')
unsigned char c = *in++;
if (ignore_lines && c == '\n')
continue;
if (sizeof base16_to_int <= c || base16_to_int[c] < 0)
{
++in;
continue;
*outlen = out - out0;
return false; /* garbage - return false */
}
int nib = *in++;
if ('0' <= nib && nib <= '9')
nib -= '0';
else if ('A' <= nib && nib <= 'F')
nib -= 'A' - 10;
if (nibble < 0)
nibble = base16_to_int[c];
else
return false; /* garbage - return false */
if (ctx->ctx.base16.have_nibble)
{
/* have both nibbles, write octet */
*out++ = (ctx->ctx.base16.nibble << 4) + nib;
++(*outlen);
*out++ = (nibble << 4) + base16_to_int[c];
nibble = -1;
}
else
{
/* Store higher nibble until next one arrives */
ctx->ctx.base16.nibble = nib;
}
ctx->ctx.base16.have_nibble = !ctx->ctx.base16.have_nibble;
}
ctx->ctx.base16.nibble = nibble;
*outlen = out - out0;
return true;
}
@@ -586,9 +708,9 @@ z85_length (int len)
}
static bool
isz85 (char ch)
isuz85 (unsigned char ch)
{
return c_isalnum (ch) || (strchr (".-:+=^!/*?&<>()[]{}@%$#", ch) != NULL);
return c_isalnum (ch) || strchr (".-:+=^!/*?&<>()[]{}@%$#", ch) != nullptr;
}
static char const z85_encoding[85] =
@@ -614,8 +736,8 @@ z85_encode (char const *restrict in, idx_t inlen,
return;
/* currently, there's no way to return an error in encoding. */
die (EXIT_FAILURE, 0,
_("invalid input (length must be multiple of 4 characters)"));
error (EXIT_FAILURE, 0,
_("invalid input (length must be multiple of 4 characters)"));
}
else
{
@@ -768,7 +890,7 @@ z85_decode_ctx (struct base_decode_context *ctx,
inline static bool
isbase2 (char ch)
isubase2 (unsigned char ch)
{
return ch == '0' || ch == '1';
}
@@ -784,7 +906,7 @@ inline static void
base2msbf_encode (char const *restrict in, idx_t inlen,
char *restrict out, idx_t outlen)
{
while (inlen--)
while (inlen && outlen)
{
unsigned char c = *in;
for (int i = 0; i < 8; i++)
@@ -792,6 +914,7 @@ base2msbf_encode (char const *restrict in, idx_t inlen,
*out++ = c & 0x80 ? '1' : '0';
c <<= 1;
}
inlen--;
outlen -= 8;
++in;
}
@@ -801,7 +924,7 @@ inline static void
base2lsbf_encode (char const *restrict in, idx_t inlen,
char *restrict out, idx_t outlen)
{
while (inlen--)
while (inlen && outlen)
{
unsigned char c = *in;
for (int i = 0; i < 8; i++)
@@ -809,6 +932,7 @@ base2lsbf_encode (char const *restrict in, idx_t inlen,
*out++ = c & 0x01 ? '1' : '0';
c >>= 1;
}
inlen--;
outlen -= 8;
++in;
}
@@ -847,7 +971,7 @@ base2lsbf_decode_ctx (struct base_decode_context *ctx,
continue;
}
if (!isbase2 (*in))
if (!isubase2 (*in))
return false;
bool bit = (*in == '1');
@@ -891,7 +1015,7 @@ base2msbf_decode_ctx (struct base_decode_context *ctx,
continue;
}
if (!isbase2 (*in))
if (!isubase2 (*in))
return false;
bool bit = (*in == '1');
@@ -926,7 +1050,7 @@ wrap_write (char const *buffer, idx_t len,
{
/* Simple write. */
if (fwrite (buffer, 1, len, stdout) < len)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
}
else
for (idx_t written = 0; written < len; )
@@ -936,13 +1060,13 @@ wrap_write (char const *buffer, idx_t len,
if (to_write == 0)
{
if (fputc ('\n', out) == EOF)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
*current_column = 0;
}
else
{
if (fwrite (buffer + written, 1, to_write, stdout) < to_write)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
*current_column += to_write;
written += to_write;
}
@@ -955,9 +1079,9 @@ finish_and_exit (FILE *in, char const *infile)
if (fclose (in) != 0)
{
if (STREQ (infile, "-"))
die (EXIT_FAILURE, errno, _("closing standard input"));
error (EXIT_FAILURE, errno, _("closing standard input"));
else
die (EXIT_FAILURE, errno, "%s", quotef (infile));
error (EXIT_FAILURE, errno, "%s", quotef (infile));
}
exit (EXIT_SUCCESS);
@@ -999,10 +1123,10 @@ do_encode (FILE *in, char const *infile, FILE *out, idx_t wrap_column)
/* When wrapping, terminate last line. */
if (wrap_column && current_column > 0 && fputc ('\n', out) == EOF)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
if (ferror (in))
die (EXIT_FAILURE, errno, _("read error"));
error (EXIT_FAILURE, errno, _("read error"));
finish_and_exit (in, infile);
}
@@ -1014,11 +1138,12 @@ do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
idx_t sum;
struct base_decode_context ctx;
char padbuf[8] = "========";
inbuf = xmalloc (BASE_LENGTH (DEC_BLOCKSIZE));
outbuf = xmalloc (DEC_BLOCKSIZE);
#if BASE_TYPE == 42
ctx.inbuf = NULL;
ctx.inbuf = nullptr;
#endif
base_decode_ctx_init (&ctx);
@@ -1036,7 +1161,7 @@ do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
{
for (idx_t i = 0; n > 0 && i < n;)
{
if (isbase (inbuf[sum + i]) || inbuf[sum + i] == '=')
if (isubase (inbuf[sum + i]) || inbuf[sum + i] == '=')
i++;
else
memmove (inbuf + sum + i, inbuf + sum + i + 1, --n - i);
@@ -1046,7 +1171,7 @@ do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
sum += n;
if (ferror (in))
die (EXIT_FAILURE, errno, _("read error"));
error (EXIT_FAILURE, errno, _("read error"));
}
while (sum < BASE_LENGTH (DEC_BLOCKSIZE) && !feof (in));
@@ -1056,16 +1181,31 @@ do_decode (FILE *in, char const *infile, FILE *out, bool ignore_garbage)
telling it to flush what is in CTX. */
for (int k = 0; k < 1 + !!feof (in); k++)
{
if (k == 1 && ctx.i == 0)
break;
if (k == 1)
{
if (ctx.i == 0)
break;
/* auto pad input (at eof). */
idx_t auto_padding = REQUIRED_PADDING (ctx.i);
if (auto_padding && (sum == 0 || inbuf[sum - 1] != '='))
{
affirm (auto_padding <= sizeof (padbuf));
IF_LINT (free (inbuf));
sum = auto_padding;
inbuf = padbuf;
}
else
sum = 0; /* process ctx buffer only */
}
idx_t n = DEC_BLOCKSIZE;
ok = base_decode_ctx (&ctx, inbuf, (k == 0 ? sum : 0), outbuf, &n);
ok = base_decode_ctx (&ctx, inbuf, sum, outbuf, &n);
if (fwrite (outbuf, 1, n, out) < n)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
if (!ok)
die (EXIT_FAILURE, 0, _("invalid input"));
error (EXIT_FAILURE, 0, _("invalid input"));
}
}
while (!feof (in));
@@ -1099,7 +1239,7 @@ main (int argc, char **argv)
atexit (close_stdout);
while ((opt = getopt_long (argc, argv, "diw:", long_options, NULL)) != -1)
while ((opt = getopt_long (argc, argv, "diw:", long_options, nullptr)) != -1)
switch (opt)
{
case 'd':
@@ -1109,10 +1249,10 @@ main (int argc, char **argv)
case 'w':
{
intmax_t w;
strtol_error s_err = xstrtoimax (optarg, NULL, 10, &w, "");
strtol_error s_err = xstrtoimax (optarg, nullptr, 10, &w, "");
if (LONGINT_OVERFLOW < s_err || w < 0)
die (EXIT_FAILURE, 0, "%s: %s",
_("invalid wrap size"), quote (optarg));
error (EXIT_FAILURE, 0, "%s: %s",
_("invalid wrap size"), quote (optarg));
wrap_column = s_err == LONGINT_OVERFLOW || IDX_MAX < w ? 0 : w;
}
break;
@@ -1148,7 +1288,8 @@ main (int argc, char **argv)
{
case BASE64_OPTION:
base_length = base64_length_wrapper;
isbase = isbase64;
required_padding = base64_required_padding;
isubase = isubase64;
base_encode = base64_encode;
base_decode_ctx_init = base64_decode_ctx_init_wrapper;
base_decode_ctx = base64_decode_ctx_wrapper;
@@ -1156,7 +1297,8 @@ main (int argc, char **argv)
case BASE64URL_OPTION:
base_length = base64_length_wrapper;
isbase = isbase64url;
required_padding = base64_required_padding;
isubase = isubase64url;
base_encode = base64url_encode;
base_decode_ctx_init = base64url_decode_ctx_init_wrapper;
base_decode_ctx = base64url_decode_ctx_wrapper;
@@ -1164,7 +1306,8 @@ main (int argc, char **argv)
case BASE32_OPTION:
base_length = base32_length_wrapper;
isbase = isbase32;
required_padding = base32_required_padding;
isubase = isubase32;
base_encode = base32_encode;
base_decode_ctx_init = base32_decode_ctx_init_wrapper;
base_decode_ctx = base32_decode_ctx_wrapper;
@@ -1172,7 +1315,8 @@ main (int argc, char **argv)
case BASE32HEX_OPTION:
base_length = base32_length_wrapper;
isbase = isbase32hex;
required_padding = base32_required_padding;
isubase = isubase32hex;
base_encode = base32hex_encode;
base_decode_ctx_init = base32hex_decode_ctx_init_wrapper;
base_decode_ctx = base32hex_decode_ctx_wrapper;
@@ -1180,7 +1324,8 @@ main (int argc, char **argv)
case BASE16_OPTION:
base_length = base16_length;
isbase = isbase16;
required_padding = no_required_padding;
isubase = isubase16;
base_encode = base16_encode;
base_decode_ctx_init = base16_decode_ctx_init;
base_decode_ctx = base16_decode_ctx;
@@ -1188,7 +1333,8 @@ main (int argc, char **argv)
case BASE2MSBF_OPTION:
base_length = base2_length;
isbase = isbase2;
required_padding = no_required_padding;
isubase = isubase2;
base_encode = base2msbf_encode;
base_decode_ctx_init = base2_decode_ctx_init;
base_decode_ctx = base2msbf_decode_ctx;
@@ -1196,7 +1342,8 @@ main (int argc, char **argv)
case BASE2LSBF_OPTION:
base_length = base2_length;
isbase = isbase2;
required_padding = no_required_padding;
isubase = isubase2;
base_encode = base2lsbf_encode;
base_decode_ctx_init = base2_decode_ctx_init;
base_decode_ctx = base2lsbf_decode_ctx;
@@ -1204,7 +1351,8 @@ main (int argc, char **argv)
case Z85_OPTION:
base_length = z85_length;
isbase = isz85;
required_padding = no_required_padding;
isubase = isuz85;
base_encode = z85_encode;
base_decode_ctx_init = z85_decode_ctx_init;
base_decode_ctx = z85_decode_ctx;
@@ -1235,8 +1383,8 @@ main (int argc, char **argv)
else
{
input_fh = fopen (infile, "rb");
if (input_fh == NULL)
die (EXIT_FAILURE, errno, "%s", quotef (infile));
if (input_fh == nullptr)
error (EXIT_FAILURE, errno, "%s", quotef (infile));
}
fadvise (input_fh, FADVISE_SEQUENTIAL);

View File

@@ -19,13 +19,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include <getopt.h>
#include "blake2.h"
@@ -134,6 +127,11 @@ cleanup_buffer:
#if 0
#include <errno.h>
#include <getopt.h>
#include <string.h>
#include <unistd.h>
int blake2sp_stream( FILE *stream, void *resstream, size_t outbytes )
{
int ret = -1;
@@ -269,12 +267,12 @@ int main( int argc, char **argv )
while( 1 )
{
int option_index = 0;
char *end = NULL;
char *end = nullptr;
unsigned long outbits;
static struct option long_options[] = {
{ "help", no_argument, 0, 0 },
{ "tag", no_argument, 0, 0 },
{ NULL, 0, NULL, 0 }
{ nullptr, 0, nullptr, 0 }
};
c = getopt_long( argc, argv, "a:l:", long_options, &option_index );
@@ -351,7 +349,7 @@ int main( int argc, char **argv )
for( i = optind; i < argc; ++i )
{
FILE *f = NULL;
FILE *f = nullptr;
if( argv[i][0] == '-' && argv[i][1] == '\0' )
f = stdin;
else

View File

@@ -1,5 +1,5 @@
/* cat -- concatenate files and print on the standard output.
Copyright (C) 1988-2023 Free Software Foundation, Inc.
Copyright (C) 1988-2024 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,7 +19,7 @@
* Usually much faster than other versions of cat, the difference
is especially apparent when using the -v option.
By tege@sics.se, Torbjorn Granlund, advised by rms, Richard Stallman. */
By tege@sics.se, Torbjörn Granlund, advised by rms, Richard Stallman. */
#include <config.h>
@@ -34,10 +34,7 @@
#include "system.h"
#include "alignalloc.h"
#include "idx.h"
#include "ioblksize.h"
#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "full-write.h"
#include "safe-read.h"
@@ -47,7 +44,7 @@
#define PROGRAM_NAME "cat"
#define AUTHORS \
proper_name ("Torbjorn Granlund"), \
proper_name_lite ("Torbjorn Granlund", "Torbj\303\266rn Granlund"), \
proper_name ("Richard M. Stallman")
/* Name of input file. May be "-". */
@@ -179,7 +176,7 @@ simple_cat (char *buf, idx_t bufsize)
/* Write this block out. */
if (full_write (STDOUT_FILENO, buf, n_read) != n_read)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
}
}
@@ -194,7 +191,7 @@ write_pending (char *outbuf, char **bpout)
if (0 < n_write)
{
if (full_write (STDOUT_FILENO, outbuf, n_write) != n_write)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
*bpout = outbuf;
}
}
@@ -258,7 +255,7 @@ cat (char *inbuf, idx_t insize, char *outbuf, idx_t outsize,
do
{
if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
wp += outsize;
remaining_bytes = bpout - wp;
}
@@ -518,7 +515,7 @@ copy_cat (void)
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,
switch (copy_file_range (input_desc, nullptr, STDOUT_FILENO, nullptr,
copy_max, 0))
{
case 0:
@@ -554,16 +551,16 @@ main (int argc, char **argv)
static struct option const long_options[] =
{
{"number-nonblank", no_argument, NULL, 'b'},
{"number", no_argument, NULL, 'n'},
{"squeeze-blank", no_argument, NULL, 's'},
{"show-nonprinting", no_argument, NULL, 'v'},
{"show-ends", no_argument, NULL, 'E'},
{"show-tabs", no_argument, NULL, 'T'},
{"show-all", no_argument, NULL, 'A'},
{"number-nonblank", no_argument, nullptr, 'b'},
{"number", no_argument, nullptr, 'n'},
{"squeeze-blank", no_argument, nullptr, 's'},
{"show-nonprinting", no_argument, nullptr, 'v'},
{"show-ends", no_argument, nullptr, 'E'},
{"show-tabs", no_argument, nullptr, 'T'},
{"show-all", no_argument, nullptr, 'A'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
{nullptr, 0, nullptr, 0}
};
initialize_main (&argc, &argv);
@@ -581,7 +578,7 @@ main (int argc, char **argv)
/* Parse command line options. */
int c;
while ((c = getopt_long (argc, argv, "benstuvAET", long_options, NULL))
while ((c = getopt_long (argc, argv, "benstuvAET", long_options, nullptr))
!= -1)
{
switch (c)
@@ -643,10 +640,10 @@ main (int argc, char **argv)
/* Get device, i-node number, and optimal blocksize of output. */
if (fstat (STDOUT_FILENO, &stat_buf) < 0)
die (EXIT_FAILURE, errno, _("standard output"));
error (EXIT_FAILURE, errno, _("standard output"));
/* Optimal size of i/o operations of output. */
idx_t outsize = io_blksize (stat_buf);
idx_t outsize = io_blksize (&stat_buf);
/* Device and I-node number of the output. */
dev_t out_dev = stat_buf.st_dev;
@@ -700,7 +697,7 @@ main (int argc, char **argv)
}
/* Optimal size of i/o operations of input. */
idx_t insize = io_blksize (stat_buf);
idx_t insize = io_blksize (&stat_buf);
fdadvise (input_desc, 0, 0, FADVISE_SEQUENTIAL);
@@ -731,7 +728,7 @@ main (int argc, char **argv)
out_isreg && S_ISREG (stat_buf.st_mode) ? copy_cat () : 0;
if (copy_cat_status != 0)
{
inbuf = NULL;
inbuf = nullptr;
ok &= 0 < copy_cat_status;
}
else
@@ -768,9 +765,9 @@ main (int argc, char **argv)
on some paging implementations. */
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))
if (ckd_mul (&bufsize, insize, 4)
|| ckd_add (&bufsize, bufsize, outsize)
|| ckd_add (&bufsize, bufsize, LINE_COUNTER_BUF_LEN - 1))
xalloc_die ();
char *outbuf = xalignalloc (page_size, bufsize);
@@ -795,11 +792,11 @@ main (int argc, char **argv)
if (pending_cr)
{
if (full_write (STDOUT_FILENO, "\r", 1) != 1)
die (EXIT_FAILURE, errno, _("write error"));
write_error ();
}
if (have_read_stdin && close (STDIN_FILENO) < 0)
die (EXIT_FAILURE, errno, _("closing standard input"));
error (EXIT_FAILURE, errno, _("closing standard input"));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@@ -1,5 +1,5 @@
/* chcon -- change security context of files
Copyright (C) 2005-2023 Free Software Foundation, Inc.
Copyright (C) 2005-2024 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,8 +22,6 @@
#include "system.h"
#include "dev-ino.h"
#include "die.h"
#include "error.h"
#include "ignore-value.h"
#include "quote.h"
#include "root-dev-ino.h"
@@ -48,7 +46,7 @@ static bool recurse;
static bool verbose;
/* Pointer to the device and inode numbers of '/', when --recursive.
Otherwise NULL. */
Otherwise nullptr. */
static struct dev_ino *root_dev_ino;
/* The name of the context file is being given. */
@@ -72,20 +70,20 @@ enum
static struct option const long_options[] =
{
{"recursive", no_argument, NULL, 'R'},
{"dereference", no_argument, NULL, DEREFERENCE_OPTION},
{"no-dereference", no_argument, NULL, 'h'},
{"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
{"preserve-root", no_argument, NULL, PRESERVE_ROOT},
{"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
{"user", required_argument, NULL, 'u'},
{"role", required_argument, NULL, 'r'},
{"type", required_argument, NULL, 't'},
{"range", required_argument, NULL, 'l'},
{"verbose", no_argument, NULL, 'v'},
{"recursive", no_argument, nullptr, 'R'},
{"dereference", no_argument, nullptr, DEREFERENCE_OPTION},
{"no-dereference", no_argument, nullptr, 'h'},
{"no-preserve-root", no_argument, nullptr, NO_PRESERVE_ROOT},
{"preserve-root", no_argument, nullptr, PRESERVE_ROOT},
{"reference", required_argument, nullptr, REFERENCE_FILE_OPTION},
{"user", required_argument, nullptr, 'u'},
{"role", required_argument, nullptr, 'r'},
{"type", required_argument, nullptr, 't'},
{"range", required_argument, nullptr, 'l'},
{"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
{nullptr, 0, nullptr, 0}
};
/* Given a security context, CONTEXT, derive a context_t (*RET),
@@ -141,12 +139,12 @@ compute_context_from_mask (char const *context, context_t *ret)
static int
change_file_context (int fd, char const *file)
{
char *file_context = NULL;
char *file_context = nullptr;
context_t context IF_LINT (= 0);
char const * context_string;
int errors = 0;
if (specified_context == NULL)
if (specified_context == nullptr)
{
int status = (affect_symlink_referent
? getfileconat (fd, file, &file_context)
@@ -162,7 +160,7 @@ change_file_context (int fd, char const *file)
/* If the file doesn't have a context, and we're not setting all of
the context components, there isn't really an obvious default.
Thus, we just give up. */
if (file_context == NULL)
if (file_context == nullptr)
{
error (0, 0, _("can't apply partial context to unlabeled file %s"),
quoteaf (file));
@@ -179,7 +177,7 @@ change_file_context (int fd, char const *file)
context_string = specified_context;
}
if (file_context == NULL || ! STREQ (context_string, file_context))
if (file_context == nullptr || ! STREQ (context_string, file_context))
{
int fail = (affect_symlink_referent
? setfileconat (fd, file, context_string)
@@ -193,7 +191,7 @@ change_file_context (int fd, char const *file)
}
}
if (specified_context == NULL)
if (specified_context == nullptr)
{
context_free (context);
freecon (file_context);
@@ -305,7 +303,7 @@ process_file (FTS *fts, FTSENT *ent)
}
/* Recursively operate on the specified FILES (the last entry
of which is NULL). BIT_FLAGS controls how fts works.
of which is null). BIT_FLAGS controls how fts works.
Return true if successful. */
static bool
@@ -313,14 +311,14 @@ process_files (char **files, int bit_flags)
{
bool ok = true;
FTS *fts = xfts_open (files, bit_flags, NULL);
FTS *fts = xfts_open (files, bit_flags, nullptr);
while (true)
{
FTSENT *ent;
ent = fts_read (fts);
if (ent == NULL)
if (ent == nullptr)
{
if (errno != 0)
{
@@ -421,7 +419,7 @@ main (int argc, char **argv)
bool ok;
bool preserve_root = false;
bool component_specified = false;
char *reference_file = NULL;
char *reference_file = nullptr;
int optc;
initialize_main (&argc, &argv);
@@ -432,7 +430,8 @@ main (int argc, char **argv)
atexit (close_stdout);
while ((optc = getopt_long (argc, argv, "HLPRhvu:r:t:l:", long_options, NULL))
while ((optc = getopt_long (argc, argv, "HLPRhvu:r:t:l:",
long_options, nullptr))
!= -1)
{
switch (optc)
@@ -514,14 +513,14 @@ main (int argc, char **argv)
if (bit_flags == FTS_PHYSICAL)
{
if (dereference == 1)
die (EXIT_FAILURE, 0,
_("-R --dereference requires either -H or -L"));
error (EXIT_FAILURE, 0,
_("-R --dereference requires either -H or -L"));
affect_symlink_referent = false;
}
else
{
if (dereference == 0)
die (EXIT_FAILURE, 0, _("-R -h requires -P"));
error (EXIT_FAILURE, 0, _("-R -h requires -P"));
affect_symlink_referent = true;
}
}
@@ -542,26 +541,26 @@ main (int argc, char **argv)
if (reference_file)
{
char *ref_context = NULL;
char *ref_context = nullptr;
if (getfilecon (reference_file, &ref_context) < 0)
die (EXIT_FAILURE, errno, _("failed to get security context of %s"),
quoteaf (reference_file));
error (EXIT_FAILURE, errno, _("failed to get security context of %s"),
quoteaf (reference_file));
specified_context = ref_context;
}
else if (component_specified)
{
/* FIXME: it's already null, so this is a no-op. */
specified_context = NULL;
specified_context = nullptr;
}
else
{
specified_context = argv[optind++];
if (0 < is_selinux_enabled ()
&& security_check_context (specified_context) < 0)
die (EXIT_FAILURE, errno, _("invalid context: %s"),
quote (specified_context));
error (EXIT_FAILURE, errno, _("invalid context: %s"),
quote (specified_context));
}
if (reference_file && component_specified)
@@ -574,13 +573,13 @@ main (int argc, char **argv)
{
static struct dev_ino dev_ino_buf;
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (root_dev_ino == NULL)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
if (root_dev_ino == nullptr)
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
else
{
root_dev_ino = NULL;
root_dev_ino = nullptr;
}
ok = process_files (argv + optind, bit_flags | FTS_NOSTAT);

View File

@@ -1,317 +0,0 @@
/* chgrp -- change group ownership of files
Copyright (C) 1989-2023 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/>. */
/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include <grp.h>
#include <getopt.h>
#include "system.h"
#include "chown-core.h"
#include "die.h"
#include "error.h"
#include "fts_.h"
#include "quote.h"
#include "root-dev-ino.h"
#include "xstrtol.h"
/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "chgrp"
#define AUTHORS \
proper_name ("David MacKenzie"), \
proper_name ("Jim Meyering")
#if ! HAVE_ENDGRENT
# define endgrent() ((void) 0)
#endif
/* The argument to the --reference option. Use the group ID of this file.
This file must exist. */
static char *reference_file;
/* For long options that have no equivalent short option, use a
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
DEREFERENCE_OPTION = CHAR_MAX + 1,
NO_PRESERVE_ROOT,
PRESERVE_ROOT,
REFERENCE_FILE_OPTION
};
static struct option const long_options[] =
{
{"recursive", no_argument, NULL, 'R'},
{"changes", no_argument, NULL, 'c'},
{"dereference", no_argument, NULL, DEREFERENCE_OPTION},
{"no-dereference", no_argument, NULL, 'h'},
{"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
{"preserve-root", no_argument, NULL, PRESERVE_ROOT},
{"quiet", no_argument, NULL, 'f'},
{"silent", no_argument, NULL, 'f'},
{"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
{"verbose", no_argument, NULL, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
};
/* Return the group ID of NAME, or -1 if no name was specified. */
static gid_t
parse_group (char const *name)
{
gid_t gid = -1;
if (*name)
{
struct group *grp = getgrnam (name);
if (grp)
gid = grp->gr_gid;
else
{
uintmax_t tmp;
if (! (xstrtoumax (name, NULL, 10, &tmp, "") == LONGINT_OK
&& tmp <= GID_T_MAX))
die (EXIT_FAILURE, 0, _("invalid group: %s"),
quote (name));
gid = tmp;
}
endgrent (); /* Save a file descriptor. */
}
return gid;
}
void
usage (int status)
{
if (status != EXIT_SUCCESS)
emit_try_help ();
else
{
printf (_("\
Usage: %s [OPTION]... GROUP FILE...\n\
or: %s [OPTION]... --reference=RFILE FILE...\n\
"),
program_name, program_name);
fputs (_("\
Change the group of each FILE to GROUP.\n\
With --reference, change the group of each FILE to that of RFILE.\n\
\n\
"), stdout);
fputs (_("\
-c, --changes like verbose but report only when a change is made\n\
-f, --silent, --quiet suppress most error messages\n\
-v, --verbose output a diagnostic for every file processed\n\
"), stdout);
fputs (_("\
--dereference affect the referent of each symbolic link (this is\n\
the default), rather than the symbolic link itself\n\
-h, --no-dereference affect symbolic links instead of any referenced file\n\
"), stdout);
fputs (_("\
(useful only on systems that can change the\n\
ownership of a symlink)\n\
"), stdout);
fputs (_("\
--no-preserve-root do not treat '/' specially (the default)\n\
--preserve-root fail to operate recursively on '/'\n\
"), stdout);
fputs (_("\
--reference=RFILE use RFILE's group rather than specifying a GROUP.\n\
RFILE is always dereferenced if a symbolic link.\n\
"), stdout);
fputs (_("\
-R, --recursive operate on files and directories recursively\n\
"), stdout);
fputs (_("\
\n\
The following options modify how a hierarchy is traversed when the -R\n\
option is also specified. If more than one is specified, only the final\n\
one takes effect.\n\
\n\
-H if a command line argument is a symbolic link\n\
to a directory, traverse it\n\
-L traverse every symbolic link to a directory\n\
encountered\n\
-P do not traverse any symbolic links (default)\n\
\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
printf (_("\
\n\
Examples:\n\
%s staff /u Change the group of /u to \"staff\".\n\
%s -hR staff /u Change the group of /u and subfiles to \"staff\".\n\
"),
program_name, program_name);
emit_ancillary_info (PROGRAM_NAME);
}
exit (status);
}
int
main (int argc, char **argv)
{
bool preserve_root = false;
gid_t gid;
/* Bit flags that control how fts works. */
int bit_flags = FTS_PHYSICAL;
/* 1 if --dereference, 0 if --no-dereference, -1 if neither has been
specified. */
int dereference = -1;
struct Chown_option chopt;
bool ok;
int optc;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
atexit (close_stdout);
chopt_init (&chopt);
while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL))
!= -1)
{
switch (optc)
{
case 'H': /* Traverse command-line symlinks-to-directories. */
bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
break;
case 'L': /* Traverse all symlinks-to-directories. */
bit_flags = FTS_LOGICAL;
break;
case 'P': /* Traverse no symlinks-to-directories. */
bit_flags = FTS_PHYSICAL;
break;
case 'h': /* --no-dereference: affect symlinks */
dereference = 0;
break;
case DEREFERENCE_OPTION: /* --dereference: affect the referent
of each symlink */
dereference = 1;
break;
case NO_PRESERVE_ROOT:
preserve_root = false;
break;
case PRESERVE_ROOT:
preserve_root = true;
break;
case REFERENCE_FILE_OPTION:
reference_file = optarg;
break;
case 'R':
chopt.recurse = true;
break;
case 'c':
chopt.verbosity = V_changes_only;
break;
case 'f':
chopt.force_silent = true;
break;
case 'v':
chopt.verbosity = V_high;
break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
default:
usage (EXIT_FAILURE);
}
}
if (chopt.recurse)
{
if (bit_flags == FTS_PHYSICAL)
{
if (dereference == 1)
die (EXIT_FAILURE, 0,
_("-R --dereference requires either -H or -L"));
dereference = 0;
}
}
else
{
bit_flags = FTS_PHYSICAL;
}
chopt.affect_symlink_referent = (dereference != 0);
if (argc - optind < (reference_file ? 1 : 2))
{
if (argc <= optind)
error (0, 0, _("missing operand"));
else
error (0, 0, _("missing operand after %s"), quote (argv[argc - 1]));
usage (EXIT_FAILURE);
}
if (reference_file)
{
struct stat ref_stats;
if (stat (reference_file, &ref_stats))
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf (reference_file));
gid = ref_stats.st_gid;
chopt.group_name = gid_to_name (ref_stats.st_gid);
}
else
{
char *group_name = argv[optind++];
chopt.group_name = (*group_name ? xstrdup (group_name) : NULL);
gid = parse_group (group_name);
}
if (chopt.recurse && preserve_root)
{
static struct dev_ino dev_ino_buf;
chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (chopt.root_dev_ino == NULL)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
bit_flags |= FTS_DEFER_STAT;
ok = chown_files (argv + optind, bit_flags,
(uid_t) -1, gid,
(uid_t) -1, (gid_t) -1, &chopt);
main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@@ -1,5 +1,5 @@
/* chmod -- change permission modes of files
Copyright (C) 1989-2023 Free Software Foundation, Inc.
Copyright (C) 1989-2024 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,9 +22,8 @@
#include <sys/types.h>
#include "system.h"
#include "assure.h"
#include "dev-ino.h"
#include "die.h"
#include "error.h"
#include "filemode.h"
#include "ignore-value.h"
#include "modechange.h"
@@ -75,6 +74,10 @@ static mode_t umask_value;
/* If true, change the modes of directories recursively. */
static bool recurse;
/* 1 if --dereference, 0 if --no-dereference, -1 if neither has been
specified. */
static int dereference = -1;
/* If true, force silence (suppress most of error messages). */
static bool force_silent;
@@ -87,31 +90,34 @@ static bool diagnose_surprises;
static enum Verbosity verbosity = V_off;
/* Pointer to the device and inode numbers of '/', when --recursive.
Otherwise NULL. */
Otherwise nullptr. */
static struct dev_ino *root_dev_ino;
/* For long options that have no equivalent short option, use a
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
NO_PRESERVE_ROOT = CHAR_MAX + 1,
DEREFERENCE_OPTION = CHAR_MAX + 1,
NO_PRESERVE_ROOT,
PRESERVE_ROOT,
REFERENCE_FILE_OPTION
};
static struct option const long_options[] =
{
{"changes", no_argument, NULL, 'c'},
{"recursive", no_argument, NULL, 'R'},
{"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
{"preserve-root", no_argument, NULL, PRESERVE_ROOT},
{"quiet", no_argument, NULL, 'f'},
{"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
{"silent", no_argument, NULL, 'f'},
{"verbose", no_argument, NULL, 'v'},
{"changes", no_argument, nullptr, 'c'},
{"dereference", no_argument, nullptr, DEREFERENCE_OPTION},
{"recursive", no_argument, nullptr, 'R'},
{"no-dereference", no_argument, nullptr, 'h'},
{"no-preserve-root", no_argument, nullptr, NO_PRESERVE_ROOT},
{"preserve-root", no_argument, nullptr, PRESERVE_ROOT},
{"quiet", no_argument, nullptr, 'f'},
{"reference", required_argument, nullptr, REFERENCE_FILE_OPTION},
{"silent", no_argument, nullptr, 'f'},
{"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
{nullptr, 0, nullptr, 0}
};
/* Return true if the chmodable permission bits of FILE changed.
@@ -191,7 +197,7 @@ describe_change (char const *file, struct change_status const *ch)
printf (fmt, quoted_file, m, &perms[1]);
return;
default:
abort ();
affirm (false);
}
printf (fmt, quoted_file, old_m, &old_perms[1], m, &perms[1]);
}
@@ -206,8 +212,9 @@ process_file (FTS *fts, FTSENT *ent)
char const *file_full_name = ent->fts_path;
char const *file = ent->fts_accpath;
const struct stat *file_stats = ent->fts_statp;
struct change_status ch = { 0, };
struct change_status ch = {0};
ch.status = CH_NO_STAT;
struct stat stat_buf;
switch (ent->fts_info)
{
@@ -245,9 +252,30 @@ process_file (FTS *fts, FTSENT *ent)
break;
case FTS_SLNONE:
if (! force_silent)
error (0, 0, _("cannot operate on dangling symlink %s"),
quoteaf (file_full_name));
if (dereference)
{
if (! force_silent)
error (0, 0, _("cannot operate on dangling symlink %s"),
quoteaf (file_full_name));
break;
}
ch.status = CH_NOT_APPLIED;
break;
case FTS_SL:
if (dereference == 1)
{
if (fstatat (fts->fts_cwd_fd, file, &stat_buf, 0) != 0)
{
if (! force_silent)
error (0, errno, _("cannot dereference %s"),
quoteaf (file_full_name));
break;
}
file_stats = &stat_buf;
}
ch.status = CH_NOT_APPLIED;
break;
case FTS_DC: /* directory that causes cycles */
@@ -273,19 +301,28 @@ process_file (FTS *fts, FTSENT *ent)
return false;
}
if (ch.status == CH_NOT_APPLIED && ! S_ISLNK (file_stats->st_mode))
if (ch.status == CH_NOT_APPLIED)
{
ch.old_mode = file_stats->st_mode;
ch.new_mode = mode_adjust (ch.old_mode, S_ISDIR (ch.old_mode) != 0,
umask_value, change, NULL);
if (chmodat (fts->fts_cwd_fd, file, ch.new_mode) == 0)
umask_value, change, nullptr);
bool follow_symlink = !!dereference;
if (dereference == -1) /* -H with/without -R, -P without -R. */
follow_symlink = ent->fts_level == 0;
if (fchmodat (fts->fts_cwd_fd, file, ch.new_mode,
follow_symlink ? 0 : AT_SYMLINK_NOFOLLOW) == 0)
ch.status = CH_SUCCEEDED;
else
{
if (! force_silent)
error (0, errno, _("changing permissions of %s"),
quoteaf (file_full_name));
ch.status = CH_FAILED;
if (! is_ENOTSUP (errno))
{
if (! force_silent)
error (0, errno, _("changing permissions of %s"),
quoteaf (file_full_name));
ch.status = CH_FAILED;
}
/* else treat not supported as not applied. */
}
}
@@ -303,7 +340,8 @@ process_file (FTS *fts, FTSENT *ent)
if (CH_NO_CHANGE_REQUESTED <= ch.status && diagnose_surprises)
{
mode_t naively_expected_mode =
mode_adjust (ch.old_mode, S_ISDIR (ch.old_mode) != 0, 0, change, NULL);
mode_adjust (ch.old_mode, S_ISDIR (ch.old_mode) != 0,
0, change, nullptr);
if (ch.new_mode & ~naively_expected_mode)
{
char new_perms[12];
@@ -326,7 +364,7 @@ process_file (FTS *fts, FTSENT *ent)
}
/* Recursively change the modes of the specified FILES (the last entry
of which is NULL). BIT_FLAGS controls how fts works.
of which is null). BIT_FLAGS controls how fts works.
Return true if successful. */
static bool
@@ -334,14 +372,14 @@ process_files (char **files, int bit_flags)
{
bool ok = true;
FTS *fts = xfts_open (files, bit_flags, NULL);
FTS *fts = xfts_open (files, bit_flags, nullptr);
while (true)
{
FTSENT *ent;
ent = fts_read (fts);
if (ent == NULL)
if (ent == nullptr)
{
if (errno != 0)
{
@@ -387,6 +425,11 @@ With --reference, change the mode of each FILE to that of RFILE.\n\
-c, --changes like verbose but report only when a change is made\n\
-f, --silent, --quiet suppress most error messages\n\
-v, --verbose output a diagnostic for every file processed\n\
"), stdout);
fputs (_("\
--dereference affect the referent of each symbolic link,\n\
rather than the symbolic link itself\n\
-h, --no-dereference affect each symbolic link, rather than the referent\n\
"), stdout);
fputs (_("\
--no-preserve-root do not treat '/' specially (the default)\n\
@@ -399,6 +442,7 @@ With --reference, change the mode of each FILE to that of RFILE.\n\
fputs (_("\
-R, --recursive change files and directories recursively\n\
"), stdout);
emit_symlink_recurse_options ("-H");
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\
@@ -416,13 +460,14 @@ Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.\n\
int
main (int argc, char **argv)
{
char *mode = NULL;
size_t mode_len = 0;
size_t mode_alloc = 0;
char *mode = nullptr;
idx_t mode_len = 0;
idx_t mode_alloc = 0;
bool ok;
bool preserve_root = false;
char const *reference_file = NULL;
char const *reference_file = nullptr;
int c;
int bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -435,13 +480,35 @@ main (int argc, char **argv)
recurse = force_silent = diagnose_surprises = false;
while ((c = getopt_long (argc, argv,
("Rcfvr::w::x::X::s::t::u::g::o::a::,::+::=::"
("HLPRcfhvr::w::x::X::s::t::u::g::o::a::,::+::=::"
"0::1::2::3::4::5::6::7::"),
long_options, NULL))
long_options, nullptr))
!= -1)
{
switch (c)
{
case 'H': /* Traverse command-line symlinks-to-directories. */
bit_flags = FTS_COMFOLLOW | FTS_PHYSICAL;
break;
case 'L': /* Traverse all symlinks-to-directories. */
bit_flags = FTS_LOGICAL;
break;
case 'P': /* Traverse no symlinks-to-directories. */
bit_flags = FTS_PHYSICAL;
break;
case 'h': /* --no-dereference: affect symlinks */
dereference = 0;
break;
case DEREFERENCE_OPTION: /* --dereference: affect the referent
of each symlink */
dereference = 1;
break;
case 'r':
case 'w':
case 'x':
@@ -457,7 +524,7 @@ main (int argc, char **argv)
case '=':
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
/* Support nonportable uses like "chmod -w", but diagnose
/* Support non-portable uses like "chmod -w", but diagnose
surprises due to umask confusion. Even though "--", "--r",
etc., are valid modes, there is no "case '-'" here since
getopt_long reserves leading "--" for long options. */
@@ -468,14 +535,13 @@ main (int argc, char **argv)
comma, and the new string (e.g., "-s,-rwx"). */
char const *arg = argv[optind - 1];
size_t arg_len = strlen (arg);
size_t mode_comma_len = mode_len + !!mode_len;
size_t new_mode_len = mode_comma_len + arg_len;
idx_t arg_len = strlen (arg);
idx_t mode_comma_len = mode_len + !!mode_len;
idx_t new_mode_len = mode_comma_len + arg_len;
assume (0 <= new_mode_len); /* Pacify GCC bug #109613. */
if (mode_alloc <= new_mode_len)
{
mode_alloc = new_mode_len + 1;
mode = X2REALLOC (mode, &mode_alloc);
}
mode = xpalloc (mode, &mode_alloc,
new_mode_len + 1 - mode_alloc, -1, 1);
mode[mode_len] = ',';
memcpy (mode + mode_comma_len, arg, arg_len + 1);
mode_len = new_mode_len;
@@ -511,6 +577,20 @@ main (int argc, char **argv)
}
}
if (recurse)
{
if (bit_flags == FTS_PHYSICAL)
{
if (dereference == 1)
error (EXIT_FAILURE, 0,
_("-R --dereference requires either -H or -L"));
dereference = 0;
}
}
if (dereference == -1 && bit_flags == FTS_LOGICAL)
dereference = 1;
if (reference_file)
{
if (mode)
@@ -538,8 +618,8 @@ main (int argc, char **argv)
{
change = mode_create_from_ref (reference_file);
if (!change)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf (reference_file));
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf (reference_file));
}
else
{
@@ -556,17 +636,17 @@ main (int argc, char **argv)
{
static struct dev_ino dev_ino_buf;
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (root_dev_ino == NULL)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
if (root_dev_ino == nullptr)
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
else
{
root_dev_ino = NULL;
root_dev_ino = nullptr;
}
ok = process_files (argv + optind,
FTS_COMFOLLOW | FTS_PHYSICAL | FTS_DEFER_STAT);
bit_flags |= FTS_DEFER_STAT;
ok = process_files (argv + optind, bit_flags);
main_exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}

2
src/chown-chgrp.c Normal file
View File

@@ -0,0 +1,2 @@
#include "chown.h"
int chown_mode = CHOWN_CHGRP;

2
src/chown-chown.c Normal file
View File

@@ -0,0 +1,2 @@
#include "chown.h"
int chown_mode = CHOWN_CHOWN;

View File

@@ -1,5 +1,5 @@
/* chown-core.c -- core functions for changing ownership.
Copyright (C) 2000-2023 Free Software Foundation, Inc.
Copyright (C) 2000-2024 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,8 +23,8 @@
#include <grp.h>
#include "system.h"
#include "assure.h"
#include "chown-core.h"
#include "error.h"
#include "ignore-value.h"
#include "root-dev-ino.h"
#include "xfts.h"
@@ -43,7 +43,7 @@ enum RCH_status
/* required_uid and/or required_gid are specified, but don't match */
RC_excluded,
/* SAME_INODE check failed */
/* The file was replaced by another file during the requested change. */
RC_inode_changed,
/* open/fchown isn't needed, isn't safe, or doesn't work due to
@@ -58,12 +58,12 @@ extern void
chopt_init (struct Chown_option *chopt)
{
chopt->verbosity = V_off;
chopt->root_dev_ino = NULL;
chopt->root_dev_ino = nullptr;
chopt->affect_symlink_referent = true;
chopt->recurse = false;
chopt->force_silent = false;
chopt->user_name = NULL;
chopt->group_name = NULL;
chopt->user_name = nullptr;
chopt->group_name = nullptr;
}
extern void
@@ -122,7 +122,7 @@ uid_to_name (uid_t uid)
static char *
user_group_str (char const *user, char const *group)
{
char *spec = NULL;
char *spec = nullptr;
if (user)
{
@@ -145,7 +145,7 @@ user_group_str (char const *user, char const *group)
}
/* Tell the user how/if the user and group of FILE have been changed.
If USER is NULL, give the group-oriented messages.
If USER is null, give the group-oriented messages.
CHANGED describes what (if anything) has happened. */
static void
@@ -165,7 +165,8 @@ describe_change (char const *file, enum Change_status changed,
}
spec = user_group_str (user, group);
old_spec = user_group_str (user ? old_user : NULL, group ? old_group : NULL);
old_spec = user_group_str (user ? old_user : nullptr,
group ? old_group : nullptr);
switch (changed)
{
@@ -188,7 +189,7 @@ describe_change (char const *file, enum Change_status changed,
: _("failed to change ownership of %s\n"));
free (old_spec);
old_spec = spec;
spec = NULL;
spec = nullptr;
}
break;
case CH_NO_CHANGE_REQUESTED:
@@ -197,7 +198,7 @@ describe_change (char const *file, enum Change_status changed,
: _("ownership of %s retained\n"));
break;
default:
abort ();
affirm (false);
}
printf (fmt, quoteaf (file), old_spec, spec);
@@ -254,21 +255,16 @@ restricted_chown (int cwd_fd, char const *file,
if (fstat (fd, &st) != 0)
status = RC_error;
else if (! SAME_INODE (*orig_st, st))
else if (! psame_inode (orig_st, &st))
status = RC_inode_changed;
else if ((required_uid == (uid_t) -1 || required_uid == st.st_uid)
&& (required_gid == (gid_t) -1 || required_gid == st.st_gid))
{
#if HAVE_FCHOWN
if (fchown (fd, uid, gid) == 0)
{
status = (close (fd) == 0
? RC_ok : RC_error);
return status;
}
else
{
status = RC_error;
}
return close (fd) < 0 ? RC_error : RC_ok;
#endif
status = RC_error;
}
int saved_errno = errno;
@@ -370,7 +366,7 @@ change_file_owner (FTS *fts, FTSENT *ent,
if (!ok)
{
do_chown = false;
file_stats = NULL;
file_stats = nullptr;
}
else if (required_uid == (uid_t) -1 && required_gid == (gid_t) -1
&& chopt->verbosity == V_off
@@ -424,7 +420,7 @@ change_file_owner (FTS *fts, FTSENT *ent,
/* Ignore any error due to lack of support; POSIX requires
this behavior for top-level symbolic links with -h, and
implies that it's required for all symbolic links. */
if (!ok && errno == EOPNOTSUPP)
if (!ok && is_ENOTSUP (errno))
{
ok = true;
symlink_changed = false;
@@ -466,7 +462,7 @@ change_file_owner (FTS *fts, FTSENT *ent,
break;
default:
abort ();
unreachable ();
}
}
@@ -498,14 +494,16 @@ change_file_owner (FTS *fts, FTSENT *ent,
: !symlink_changed ? CH_NOT_APPLIED
: !changed ? CH_NO_CHANGE_REQUESTED
: 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 *old_usr = (file_stats
? uid_to_name (file_stats->st_uid) : nullptr);
char *old_grp = (file_stats
? gid_to_name (file_stats->st_gid) : nullptr);
char *new_usr = chopt->user_name
? chopt->user_name : uid != -1
? uid_to_str (uid) : NULL;
? uid_to_str (uid) : nullptr;
char *new_grp = chopt->group_name
? chopt->group_name : gid != -1
? gid_to_str (gid) : NULL;
? gid_to_str (gid) : nullptr;
describe_change (file_full_name, ch_status,
old_usr, old_grp,
new_usr, new_grp);
@@ -548,14 +546,14 @@ chown_files (char **files, int bit_flags,
? 0
: FTS_NOSTAT);
FTS *fts = xfts_open (files, bit_flags | stat_flags, NULL);
FTS *fts = xfts_open (files, bit_flags | stat_flags, nullptr);
while (true)
{
FTSENT *ent;
ent = fts_read (fts);
if (ent == NULL)
if (ent == nullptr)
{
if (errno != 0)
{

View File

@@ -1,6 +1,6 @@
/* chown-core.h -- types and prototypes shared by chown and chgrp.
Copyright (C) 2000-2023 Free Software Foundation, Inc.
Copyright (C) 2000-2024 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
@@ -50,7 +50,7 @@ struct Chown_option
bool recurse;
/* Pointer to the device and inode numbers of '/', when --recursive.
Need not be freed. Otherwise NULL. */
Need not be freed. Otherwise nullptr. */
struct dev_ino *root_dev_ino;
/* This corresponds to the --dereference (opposite of -h) option. */

View File

@@ -1,5 +1,5 @@
/* chown -- change user and group ownership of files
Copyright (C) 1989-2023 Free Software Foundation, Inc.
/* chown, chgrp -- change user and group ownership of files
Copyright (C) 1989-2024 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,16 +22,15 @@
#include <getopt.h>
#include "system.h"
#include "chown.h"
#include "chown-core.h"
#include "die.h"
#include "error.h"
#include "fts_.h"
#include "quote.h"
#include "root-dev-ino.h"
#include "userspec.h"
/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "chown"
#define PROGRAM_NAME (chown_mode == CHOWN_CHOWN ? "chown" : "chgrp")
#define AUTHORS \
proper_name ("David MacKenzie"), \
@@ -54,20 +53,20 @@ enum
static struct option const long_options[] =
{
{"recursive", no_argument, NULL, 'R'},
{"changes", no_argument, NULL, 'c'},
{"dereference", no_argument, NULL, DEREFERENCE_OPTION},
{"from", required_argument, NULL, FROM_OPTION},
{"no-dereference", no_argument, NULL, 'h'},
{"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
{"preserve-root", no_argument, NULL, PRESERVE_ROOT},
{"quiet", no_argument, NULL, 'f'},
{"silent", no_argument, NULL, 'f'},
{"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
{"verbose", no_argument, NULL, 'v'},
{"recursive", no_argument, nullptr, 'R'},
{"changes", no_argument, nullptr, 'c'},
{"dereference", no_argument, nullptr, DEREFERENCE_OPTION},
{"from", required_argument, nullptr, FROM_OPTION},
{"no-dereference", no_argument, nullptr, 'h'},
{"no-preserve-root", no_argument, nullptr, NO_PRESERVE_ROOT},
{"preserve-root", no_argument, nullptr, PRESERVE_ROOT},
{"quiet", no_argument, nullptr, 'f'},
{"silent", no_argument, nullptr, 'f'},
{"reference", required_argument, nullptr, REFERENCE_FILE_OPTION},
{"verbose", no_argument, nullptr, 'v'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
{nullptr, 0, nullptr, 0}
};
void
@@ -78,14 +77,23 @@ usage (int status)
else
{
printf (_("\
Usage: %s [OPTION]... [OWNER][:[GROUP]] FILE...\n\
Usage: %s [OPTION]... %s FILE...\n\
or: %s [OPTION]... --reference=RFILE FILE...\n\
"),
program_name, program_name);
fputs (_("\
program_name,
chown_mode == CHOWN_CHOWN ? _("[OWNER][:[GROUP]]") : _("GROUP"),
program_name);
if (chown_mode == CHOWN_CHOWN)
fputs (_("\
Change the owner and/or group of each FILE to OWNER and/or GROUP.\n\
With --reference, change the owner and group of each FILE to those of RFILE.\n\
\n\
"), stdout);
else
fputs (_("\
Change the group of each FILE to GROUP.\n\
With --reference, change the group of each FILE to that of RFILE.\n\
\n\
"), stdout);
fputs (_("\
-c, --changes like verbose but report only when a change is made\n\
@@ -103,9 +111,9 @@ With --reference, change the owner and group of each FILE to those of RFILE.\n\
"), stdout);
fputs (_("\
--from=CURRENT_OWNER:CURRENT_GROUP\n\
change the owner and/or group of each file only if\n\
change the ownership of each file only if\n\
its current owner and/or group match those specified\n\
here. Either may be omitted, in which case a match\n\
here. Either may be omitted, in which case a match\n\
is not required for the omitted attribute\n\
"), stdout);
fputs (_("\
@@ -113,34 +121,25 @@ With --reference, change the owner and group of each FILE to those of RFILE.\n\
--preserve-root fail to operate recursively on '/'\n\
"), stdout);
fputs (_("\
--reference=RFILE use RFILE's owner and group rather than specifying\n\
OWNER:GROUP values. RFILE is always dereferenced.\n\
--reference=RFILE use RFILE's ownership rather than specifying values\n\
RFILE is always dereferenced if a symbolic link.\n\
"), stdout);
fputs (_("\
-R, --recursive operate on files and directories recursively\n\
"), stdout);
fputs (_("\
\n\
The following options modify how a hierarchy is traversed when the -R\n\
option is also specified. If more than one is specified, only the final\n\
one takes effect.\n\
\n\
-H if a command line argument is a symbolic link\n\
to a directory, traverse it\n\
-L traverse every symbolic link to a directory\n\
encountered\n\
-P do not traverse any symbolic links (default)\n\
\n\
"), stdout);
emit_symlink_recurse_options ("-P");
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\
if (chown_mode == CHOWN_CHOWN)
fputs (_("\
\n\
Owner is unchanged if missing. Group is unchanged if missing, but changed\n\
to login group if implied by a ':' following a symbolic OWNER.\n\
OWNER and GROUP may be numeric as well as symbolic.\n\
"), stdout);
printf (_("\
if (chown_mode == CHOWN_CHOWN)
printf (_("\
\n\
Examples:\n\
%s root /u Change the owner of /u to \"root\".\n\
@@ -148,6 +147,14 @@ Examples:\n\
%s -hR root /u Change the owner of /u and subfiles to \"root\".\n\
"),
program_name, program_name, program_name);
else
printf (_("\
\n\
Examples:\n\
%s staff /u Change the group of /u to \"staff\".\n\
%s -hR staff /u Change the group of /u and subfiles to \"staff\".\n\
"),
program_name, program_name);
emit_ancillary_info (PROGRAM_NAME);
}
exit (status);
@@ -187,7 +194,7 @@ main (int argc, char **argv)
chopt_init (&chopt);
while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL))
while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, nullptr))
!= -1)
{
switch (optc)
@@ -230,7 +237,7 @@ main (int argc, char **argv)
bool warn;
char const *e = parse_user_spec_warn (optarg,
&required_uid, &required_gid,
NULL, NULL, &warn);
nullptr, nullptr, &warn);
if (e)
error (warn ? 0 : EXIT_FAILURE, 0, "%s: %s", e, quote (optarg));
break;
@@ -264,8 +271,8 @@ main (int argc, char **argv)
if (bit_flags == FTS_PHYSICAL)
{
if (dereference == 1)
die (EXIT_FAILURE, 0,
_("-R --dereference requires either -H or -L"));
error (EXIT_FAILURE, 0,
_("-R --dereference requires either -H or -L"));
dereference = 0;
}
}
@@ -288,27 +295,41 @@ main (int argc, char **argv)
{
struct stat ref_stats;
if (stat (reference_file, &ref_stats))
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf (reference_file));
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf (reference_file));
uid = ref_stats.st_uid;
if (chown_mode == CHOWN_CHOWN)
{
uid = ref_stats.st_uid;
chopt.user_name = uid_to_name (ref_stats.st_uid);
}
gid = ref_stats.st_gid;
chopt.user_name = uid_to_name (ref_stats.st_uid);
chopt.group_name = gid_to_name (ref_stats.st_gid);
}
else
{
char *ug = argv[optind];
if (chown_mode == CHOWN_CHGRP)
{
ug = xmalloc (1 + strlen (argv[optind]) + 1);
stpcpy (stpcpy (ug, ":"), argv[optind]);
}
bool warn;
char const *e = parse_user_spec_warn (argv[optind], &uid, &gid,
char const *e = parse_user_spec_warn (ug, &uid, &gid,
&chopt.user_name,
&chopt.group_name, &warn);
if (ug != argv[optind])
free (ug);
if (e)
error (warn ? 0 : EXIT_FAILURE, 0, "%s: %s", e, quote (argv[optind]));
/* If a group is specified but no user, set the user name to the
empty string so that diagnostics say "ownership :GROUP"
rather than "group GROUP". */
if (!chopt.user_name && chopt.group_name)
if (chown_mode == CHOWN_CHOWN && !chopt.user_name && chopt.group_name)
chopt.user_name = xstrdup ("");
optind++;
@@ -318,9 +339,9 @@ main (int argc, char **argv)
{
static struct dev_ino dev_ino_buf;
chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (chopt.root_dev_ino == NULL)
die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
if (chopt.root_dev_ino == nullptr)
error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
quoteaf ("/"));
}
bit_flags |= FTS_DEFER_STAT;

7
src/chown.h Normal file
View File

@@ -0,0 +1,7 @@
/* This is for the 'chown' program. */
#define CHOWN_CHOWN 1
/* This is for the 'chgrp' program. */
#define CHOWN_CHGRP 2
extern int chown_mode;

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