Compare commits

...

187 Commits
v9.4 ... 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
852 changed files with 4457 additions and 3776 deletions

View File

@@ -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

@@ -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

1
.gitignore vendored
View File

@@ -87,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

View File

@@ -1 +1 @@
9.3
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

View File

@@ -616,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.30
gen_start_ver = 8.31
.PHONY: gen-ChangeLog
gen-ChangeLog:
$(AM_V_GEN)if test -d .git; then \

133
NEWS
View File

@@ -1,5 +1,136 @@
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
@@ -5765,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

2
README
View File

@@ -131,7 +131,7 @@ 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

@@ -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

View File

@@ -238,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
@@ -412,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
@@ -566,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

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

View File

@@ -3,9 +3,9 @@
# Bootstrap this package from checked-out sources.
scriptversion=2023-07-01.18; # UTC
scriptversion=2023-12-10.18; # UTC
# 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
@@ -37,9 +37,9 @@ medir=`dirname "$me"`
# A library of shell functions for autopull.sh, autogen.sh, and bootstrap.
scriptlibversion=2023-07-01.17; # UTC
scriptlibversion=2023-12-10.18; # UTC
# 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
@@ -659,7 +659,9 @@ Optional environment variables:
Use this if you already have gnulib sources
and history on your machine, and do not want
to waste your bandwidth downloading them again.
GNULIB_URL Cloneable URL of the gnulib repository.
GNULIB_URL URL of the gnulib repository. The default is
$default_gnulib_url,
which is Gnulib's upstream repository.
Options:
--bootstrap-sync if this bootstrap script is not identical to
@@ -775,7 +777,7 @@ autopull()
if $use_gnulib || $bootstrap_sync; then
prepare_GNULIB_SRCDIR
if $bootstrap_sync; then
upgrade_bootstrap
upgrade_bootstrap "$@"
fi
fi
@@ -1347,7 +1349,9 @@ Optional environment variables:
have gnulib sources on your machine, and
do not want to waste your bandwidth downloading
them again.
GNULIB_URL Cloneable URL of the gnulib repository.
GNULIB_URL URL of the gnulib repository. The default is
$default_gnulib_url,
which is Gnulib's upstream repository.
Options:
@@ -1492,7 +1496,7 @@ check_build_prerequisites $use_git
if $bootstrap_sync; then
prepare_GNULIB_SRCDIR
upgrade_bootstrap
upgrade_bootstrap "$@"
# Since we have now upgraded if needed, no need to try it a second time below.
bootstrap_sync=false
fi

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.
@@ -39,23 +41,24 @@ gnulib_modules="
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
@@ -117,7 +120,6 @@ gnulib_modules="
fts
full-read
full-write
getgroups
gethrxtime
getline
getloadavg
@@ -125,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
@@ -154,7 +151,6 @@ gnulib_modules="
isblank
largefile
lchmod
lchown
ldtoastr
lib-ignore
libgmp
@@ -168,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
@@ -190,13 +187,12 @@ gnulib_modules="
mkostemp
mkstemp
mktime
nullptr
modechange
mountlist
mpsort
netinet_in
nproc
nstrftime
nullptr
obstack
open
openat-safer
@@ -224,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
@@ -248,6 +240,7 @@ gnulib_modules="
settime
sig2str
sigaction
skipchars
smack
ssize_t
stat-macros
@@ -257,9 +250,8 @@ gnulib_modules="
stdckdint
stdlib-safer
stpcpy
stpncpy
strdup-posix
strncat
strnlen
strnumcmp
strsignal
strtoimax
@@ -276,7 +268,6 @@ gnulib_modules="
timer-time
timespec
tmpdir
tzset
uname
unicodeio
unistd-safer
@@ -296,9 +287,6 @@ gnulib_modules="
verify
verror
version-etc-fsf
wchar-single
wcswidth
wcwidth
winsz-ioctl
winsz-termios
write-any-file

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"

10
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
@@ -48,7 +48,7 @@ export VERBOSE = yes
# 4914152 9e
export XZ_OPT = -8e
old_NEWS_hash = c550e6659b8350f62d9cd0483bf0c199
old_NEWS_hash = d66ee7a9fdb974017a4a17cf358d047d
# Add an exemption for sc_makefile_at_at_check.
_makefile_at_at_check_exceptions = \
@@ -841,7 +841,8 @@ exclude_file_name_regexp--sc_trailing_blank = \
exclude_file_name_regexp--sc_system_h_headers = \
^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)$$
@@ -926,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])
@@ -213,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])
@@ -340,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])
@@ -471,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])
@@ -493,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([[
@@ -507,18 +559,68 @@ 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
# 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);
}
]])
],[
utils_cv_ieee_16_bit_supported=yes
],[
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_CACHE_VAL([utils_cv_pclmul_intrinsic_exists],[
AC_LINK_IFELSE(
[AC_LANG_SOURCE([[
#include <x86intrin.h>
@@ -533,21 +635,22 @@ AC_LINK_IFELSE(
}
]])
],[
pclmul_intrinsic_exists=yes
utils_cv_pclmul_intrinsic_exists=yes
],[
pclmul_intrinsic_exists=no
])
AC_MSG_RESULT([$pclmul_intrinsic_exists])
if test $pclmul_intrinsic_exists = yes; 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 $pclmul_intrinsic_exists = yes])
[test $utils_cv_pclmul_intrinsic_exists = yes])
CFLAGS=$ac_save_CFLAGS
CFLAGS="-mavx2 $CFLAGS"
AC_MSG_CHECKING([for avx2 intrinsics])
AC_CACHE_VAL([utils_cv_avx2_intrinsic_exists],[
AC_LINK_IFELSE(
[AC_LANG_SOURCE([[
#include <x86intrin.h>
@@ -561,16 +664,16 @@ AC_LINK_IFELSE(
}
]])
],[
avx2_intrinsic_exists=yes
utils_cv_avx2_intrinsic_exists=yes
],[
avx2_intrinsic_exists=no
])
AC_MSG_RESULT([$avx2_intrinsic_exists])
if test $avx2_intrinsic_exists = yes; 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 $avx2_intrinsic_exists = yes])
[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

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

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

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

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 = nullptr;
wchar_t *str_wc = nullptr;
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 (nullptr, 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 == nullptr)
{
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 (nullptr, str_wc, 0) + 1;
}
newstr = malloc (src_size);
if (newstr == nullptr)
{
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 nullptr 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 = nullptr;
while (req >= size)
{
char *nbuf;
size = req + 1; /* Space for NUL. */
nbuf = realloc (buf, size);
if (nbuf == nullptr)
{
free (buf);
buf = nullptr;
break;
}
buf = nbuf;
*width = orig_width;
req = mbsalign (src, buf, size, width, align, flags);
if (req == SIZE_MAX)
{
free (buf);
buf = nullptr;
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
@@ -41,7 +41,7 @@ main (int argc, char **argv)
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);
}

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

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
@@ -46,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
@@ -271,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

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

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
@@ -24,9 +24,9 @@
#include <stddef.h>
#include <stdlib.h>
#include "error.h"
#include "quote.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.

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

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

View File

@@ -1,147 +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;
#ifdef __ANDROID__
/* On Android ≥ 5.0, the default locale is the "C.UTF-8" locale, not the
"C" locale. Furthermore, when you attempt to set the "C" or "POSIX"
locale via setlocale(), what you get is a "C" locale with UTF-8 encoding,
that is, effectively the "C.UTF-8" locale. */
if (MB_CUR_MAX == 1)
#endif
{
/* 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

2
gnulib

Submodule gnulib updated: bb5bb43a1e...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

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,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>.

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

@@ -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

@@ -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,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,5 +1,5 @@
# 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
@@ -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

View File

@@ -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

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,6 +23,7 @@
#include <sys/types.h>
#include "system.h"
#include "assure.h"
#include "c-ctype.h"
#include "fadvise.h"
#include "quote.h"
@@ -172,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)
@@ -188,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)
@@ -203,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. */
@@ -216,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
@@ -319,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
@@ -432,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');
}
@@ -471,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;
@@ -485,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
@@ -499,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;
}
}
@@ -519,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;
}
@@ -530,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;
}
@@ -583,7 +708,7 @@ z85_length (int len)
}
static bool
isz85 (char ch)
isuz85 (unsigned char ch)
{
return c_isalnum (ch) || strchr (".-:+=^!/*?&<>()[]{}@%$#", ch) != nullptr;
}
@@ -765,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';
}
@@ -781,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++)
@@ -789,6 +914,7 @@ base2msbf_encode (char const *restrict in, idx_t inlen,
*out++ = c & 0x80 ? '1' : '0';
c <<= 1;
}
inlen--;
outlen -= 8;
++in;
}
@@ -798,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++)
@@ -806,6 +932,7 @@ base2lsbf_encode (char const *restrict in, idx_t inlen,
*out++ = c & 0x01 ? '1' : '0';
c >>= 1;
}
inlen--;
outlen -= 8;
++in;
}
@@ -844,7 +971,7 @@ base2lsbf_decode_ctx (struct base_decode_context *ctx,
continue;
}
if (!isbase2 (*in))
if (!isubase2 (*in))
return false;
bool bit = (*in == '1');
@@ -888,7 +1015,7 @@ base2msbf_decode_ctx (struct base_decode_context *ctx,
continue;
}
if (!isbase2 (*in))
if (!isubase2 (*in))
return false;
bool bit = (*in == '1');
@@ -1011,6 +1138,7 @@ 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);
@@ -1033,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);
@@ -1053,10 +1181,25 @@ 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)
write_error ();
@@ -1145,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;
@@ -1153,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;
@@ -1161,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;
@@ -1169,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;
@@ -1177,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;
@@ -1185,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;
@@ -1193,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;
@@ -1201,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;

View File

@@ -19,12 +19,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include <getopt.h>
#include "blake2.h"
@@ -133,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;

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
@@ -23,7 +23,6 @@
#include <config.h>
#include <stdckdint.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
@@ -644,7 +643,7 @@ main (int argc, char **argv)
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;
@@ -698,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);

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

View File

@@ -1,315 +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 "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, nullptr, 'R'},
{"changes", no_argument, nullptr, 'c'},
{"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},
{"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},
{nullptr, 0, nullptr, 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, nullptr, 10, &tmp, "") == LONGINT_OK
&& tmp <= GID_T_MAX))
error (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, nullptr))
!= -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)
error (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))
error (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) : nullptr);
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 == nullptr)
error (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
@@ -74,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;
@@ -93,7 +97,8 @@ static struct dev_ino *root_dev_ino;
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
};
@@ -101,7 +106,9 @@ enum
static struct option const long_options[] =
{
{"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'},
@@ -205,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)
{
@@ -244,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 */
@@ -272,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, nullptr);
if (chmodat (fts->fts_cwd_fd, file, ch.new_mode) == 0)
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. */
}
}
@@ -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 (_("\
@@ -423,6 +467,7 @@ main (int argc, char **argv)
bool preserve_root = false;
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, 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':
@@ -510,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)
@@ -564,8 +645,8 @@ main (int argc, char **argv)
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
@@ -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
@@ -255,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;
@@ -425,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;

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

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,6 +22,7 @@
#include <getopt.h>
#include "system.h"
#include "chown.h"
#include "chown-core.h"
#include "fts_.h"
#include "quote.h"
@@ -29,7 +30,7 @@
#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"), \
@@ -76,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\
@@ -101,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 (_("\
@@ -111,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\
@@ -146,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);
@@ -289,24 +298,38 @@ main (int argc, char **argv)
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++;

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;

View File

@@ -1,5 +1,5 @@
/* chroot -- run command or shell with special root directory
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
@@ -17,6 +17,7 @@
/* Written by Roland McGrath. */
#include <config.h>
#include <ctype.h>
#include <getopt.h>
#include <stdio.h>
#include <sys/types.h>

View File

@@ -1,5 +1,5 @@
/* cksum -- calculate and print POSIX checksums and sizes of files
Copyright (C) 1992-2023 Free Software Foundation, Inc.
Copyright (C) 1992-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 @@
/* cksum -- calculate and print POSIX checksums and sizes of files
Copyright (C) 1992-2023 Free Software Foundation, Inc.
Copyright (C) 1992-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 @@
/* comm -- compare two sorted files line by line.
Copyright (C) 1986-2023 Free Software Foundation, Inc.
Copyright (C) 1986-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,10 +36,6 @@
proper_name ("Richard M. Stallman"), \
proper_name ("David MacKenzie")
/* Undefine, to avoid warning about redefinition on some systems. */
#undef min
#define min(x, y) ((x) < (y) ? (x) : (y))
/* True if the LC_COLLATE locale is hard. */
static bool hard_LC_COLLATE;
@@ -149,7 +145,7 @@ and column three contains lines common to both files.\n\
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\
\n\
Note, comparisons honor the rules specified by 'LC_COLLATE'.\n\
Comparisons honor the rules specified by 'LC_COLLATE'.\n\
"), stdout);
printf (_("\
\n\
@@ -319,7 +315,7 @@ compare_files (char **infiles)
thisline[1]->buffer, thisline[1]->length - 1);
else
{
size_t len = min (thisline[0]->length, thisline[1]->length) - 1;
size_t len = MIN (thisline[0]->length, thisline[1]->length) - 1;
order = memcmp (thisline[0]->buffer, thisline[1]->buffer, len);
if (order == 0)
order = ((thisline[0]->length > thisline[1]->length)

View File

@@ -1,5 +1,5 @@
/* copy.c -- core functions for copying files and directories
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
@@ -17,7 +17,6 @@
/* Extracted from cp.c and librarified by Jim Meyering. */
#include <config.h>
#include <stdckdint.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@@ -92,11 +91,6 @@
# include <sys/clonefile.h>
#endif
#ifndef HAVE_FCHOWN
# define HAVE_FCHOWN false
# define fchown(fd, uid, gid) (-1)
#endif
#ifndef USE_ACL
# define USE_ACL 0
#endif
@@ -772,7 +766,7 @@ copy_attr (char const *src_path, int src_fd,
? check_selinux_attr : nullptr);
# if 4 < __GNUC__ + (8 <= __GNUC_MINOR__)
/* Pacify gcc -Wsuggest-attribute=format through at least GCC 11.2.1. */
/* Pacify gcc -Wsuggest-attribute=format through at least GCC 13.2.1. */
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
# endif
@@ -881,6 +875,34 @@ copy_dir (char const *src_name_in, char const *dst_name_in,
return ok;
}
/* Change the file mode bits of the file identified by DESC or
DIRFD+NAME to MODE. Use DESC if DESC is valid and fchmod is
available, DIRFD+NAME otherwise. */
static int
fchmod_or_lchmod (int desc, int dirfd, char const *name, mode_t mode)
{
#if HAVE_FCHMOD
if (0 <= desc)
return fchmod (desc, mode);
#endif
return lchmodat (dirfd, name, mode);
}
/* Change the ownership of the file identified by DESC or
DIRFD+NAME to UID+GID. Use DESC if DESC is valid and fchown is
available, DIRFD+NAME otherwise. */
static int
fchown_or_lchown (int desc, int dirfd, char const *name, uid_t uid, gid_t gid)
{
#if HAVE_FCHOWN
if (0 <= desc)
return fchown (desc, uid, gid);
#endif
return lchownat (dirfd, name, uid, gid);
}
/* Set the owner and owning group of DEST_DESC to the st_uid and
st_gid fields of SRC_SB. If DEST_DESC is undefined (-1), set
the owner and owning group of DST_NAME aka DST_DIRFD+DST_RELNAME
@@ -927,34 +949,16 @@ set_owner (const struct cp_options *x, char const *dst_name,
}
}
if (HAVE_FCHOWN && dest_desc != -1)
{
if (fchown (dest_desc, uid, gid) == 0)
return 1;
if (errno == EPERM || errno == EINVAL)
{
/* We've failed to set *both*. Now, try to set just the group
ID, but ignore any failure here, and don't change errno. */
int saved_errno = errno;
ignore_value (fchown (dest_desc, -1, gid));
errno = saved_errno;
}
}
else
{
if (lchownat (dst_dirfd, dst_relname, uid, gid) == 0)
return 1;
if (errno == EPERM || errno == EINVAL)
{
/* We've failed to set *both*. Now, try to set just the group
ID, but ignore any failure here, and don't change errno. */
int saved_errno = errno;
ignore_value (lchownat (dst_dirfd, dst_relname, -1, gid));
errno = saved_errno;
}
}
if (fchown_or_lchown (dest_desc, dst_dirfd, dst_relname, uid, gid) == 0)
return 1;
if (! chown_failure_ok (x))
/* The ownership change failed. If the failure merely means we lack
privileges to change owner+group, try to change just the group
and ignore any failure of this. Otherwise, report an error. */
if (chown_failure_ok (x))
ignore_value (fchown_or_lchown (dest_desc, dst_dirfd, dst_relname,
-1, gid));
else
{
error (0, errno, _("failed to preserve ownership for %s"),
quoteaf (dst_name));
@@ -1016,23 +1020,23 @@ set_process_security_ctx (char const *src_name, char const *dst_name,
/* Set the default context for the process to match the source. */
bool all_errors = !x->data_copy_required || x->require_preserve_context;
bool some_errors = !all_errors && !x->reduce_diagnostics;
char *con;
char *con_raw;
if (0 <= lgetfilecon (src_name, &con))
if (0 <= lgetfilecon_raw (src_name, &con_raw))
{
if (setfscreatecon (con) < 0)
if (setfscreatecon_raw (con_raw) < 0)
{
if (all_errors || (some_errors && !errno_unsupported (errno)))
error (0, errno,
_("failed to set default file creation context to %s"),
quote (con));
quote (con_raw));
if (x->require_preserve_context)
{
freecon (con);
freecon (con_raw);
return false;
}
}
freecon (con);
freecon (con_raw);
}
else
{
@@ -1088,20 +1092,6 @@ set_file_security_ctx (char const *dst_name,
return true;
}
/* Change the file mode bits of the file identified by DESC or
DIRFD+NAME to MODE. Use DESC if DESC is valid and fchmod is
available, DIRFD+NAME otherwise. */
static int
fchmod_or_lchmod (int desc, int dirfd, char const *name, mode_t mode)
{
#if HAVE_FCHMOD
if (0 <= desc)
return fchmod (desc, mode);
#endif
return lchmodat (dirfd, name, mode);
}
#ifndef HAVE_STRUCT_STAT_ST_BLOCKS
# define HAVE_STRUCT_STAT_ST_BLOCKS 0
#endif
@@ -1143,7 +1133,7 @@ infer_scantype (int fd, struct stat const *sb,
suggests the file is sparse. */
if (! (HAVE_STRUCT_STAT_ST_BLOCKS
&& S_ISREG (sb->st_mode)
&& ST_NBLOCKS (*sb) < sb->st_size / ST_NBLOCKSIZE))
&& STP_NBLOCKS (sb) < sb->st_size / ST_NBLOCKSIZE))
return PLAIN_SCANTYPE;
#ifdef SEEK_HOLE
@@ -1229,20 +1219,21 @@ handle_clone_fail (int dst_dirfd, char const *dst_relname,
*NEW_DST is initially as in copy_internal.
If successful, set *NEW_DST to true if the destination file was created and
to false otherwise; if unsuccessful, perhaps set *NEW_DST to some value.
SRC_SB is the result of calling follow_fstatat on SRC_NAME. */
SRC_SB is the result of calling follow_fstatat on SRC_NAME;
it might be updated by calling fstat again on the same file,
to give it slightly more up-to-date contents. */
static bool
copy_reg (char const *src_name, char const *dst_name,
int dst_dirfd, char const *dst_relname,
const struct cp_options *x,
mode_t dst_mode, mode_t omitted_permissions, bool *new_dst,
struct stat const *src_sb)
struct stat *src_sb)
{
char *buf = nullptr;
int dest_desc;
int dest_errno;
int source_desc;
mode_t src_mode = src_sb->st_mode;
mode_t extra_permissions;
struct stat sb;
struct stat src_open_sb;
@@ -1273,7 +1264,7 @@ copy_reg (char const *src_name, char const *dst_name,
/* Compare the source dev/ino from the open file to the incoming,
saved ones obtained via a previous call to stat. */
if (! SAME_INODE (*src_sb, src_open_sb))
if (! psame_inode (src_sb, &src_open_sb))
{
error (0, 0,
_("skipping file %s, as it was replaced while being copied"),
@@ -1282,6 +1273,11 @@ copy_reg (char const *src_name, char const *dst_name,
goto close_src_desc;
}
/* Might as well tell the caller about the latest version of the
source file status, since we have it already. */
*src_sb = src_open_sb;
mode_t src_mode = src_sb->st_mode;
/* The semantics of the following open calls are mandated
by the specs for both cp and mv. */
if (! *new_dst)
@@ -1547,8 +1543,8 @@ copy_reg (char const *src_name, char const *dst_name,
if (data_copy_required)
{
/* Choose a suitable buffer size; it may be adjusted later. */
size_t buf_size = io_blksize (sb);
size_t hole_size = ST_BLKSIZE (sb);
size_t buf_size = io_blksize (&sb);
size_t hole_size = STP_BLKSIZE (&sb);
/* Deal with sparse files. */
enum scantype scantype = infer_scantype (source_desc, &src_open_sb,
@@ -1576,7 +1572,7 @@ copy_reg (char const *src_name, char const *dst_name,
Note we read in multiples of the reported block size
to support (unusual) devices that have this constraint. */
size_t blcm_max = MIN (SIZE_MAX, SSIZE_MAX);
size_t blcm = buffer_lcm (io_blksize (src_open_sb), buf_size,
size_t blcm = buffer_lcm (io_blksize (&src_open_sb), buf_size,
blcm_max);
/* Do not bother with a buffer larger than the input file, plus one
@@ -1746,7 +1742,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
struct stat tmp_src_sb;
bool same_link;
bool same = SAME_INODE (*src_sb, *dst_sb);
bool same = psame_inode (src_sb, dst_sb);
*return_now = false;
@@ -1807,7 +1803,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
src_sb_link = &tmp_src_sb;
dst_sb_link = &tmp_dst_sb;
same_link = SAME_INODE (*src_sb_link, *dst_sb_link);
same_link = psame_inode (src_sb_link, dst_sb_link);
/* If both are symlinks, then it's ok, but only if the destination
will be unlinked before being opened. This is like the test
@@ -1895,7 +1891,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
hard links to the same file. */
if (!S_ISLNK (src_sb_link->st_mode) && !S_ISLNK (dst_sb_link->st_mode))
{
if (!SAME_INODE (*src_sb_link, *dst_sb_link))
if (!psame_inode (src_sb_link, dst_sb_link))
return true;
/* If they are the same file, it's ok if we're making hard links. */
@@ -1956,7 +1952,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
else if (fstatat (dst_dirfd, dst_relname, &tmp_dst_sb, 0) != 0)
return true;
if ( ! SAME_INODE (tmp_src_sb, tmp_dst_sb))
if (!psame_inode (&tmp_src_sb, &tmp_dst_sb))
return true;
if (x->hard_link)
@@ -2079,9 +2075,10 @@ abandon_move (const struct cp_options *x,
If BACKUP_DST_NAME is non-null, then also indicate that it is
the name of a backup file. */
static void
emit_verbose (char const *src, char const *dst, char const *backup_dst_name)
emit_verbose (char const *format, char const *src, char const *dst,
char const *backup_dst_name)
{
printf ("%s -> %s", quoteaf_n (0, src), quoteaf_n (1, dst));
printf (format, quoteaf_n (0, src), quoteaf_n (1, dst));
if (backup_dst_name)
printf (_(" (backup: %s)"), quoteaf (backup_dst_name));
putchar ('\n');
@@ -2175,7 +2172,7 @@ source_is_dst_backup (char const *srcbase, struct stat const *src_st,
struct stat dst_back_sb;
int dst_back_status = fstatat (dst_dirfd, dst_back, &dst_back_sb, 0);
free (dst_back);
return dst_back_status == 0 && SAME_INODE (*src_st, dst_back_sb);
return dst_back_status == 0 && psame_inode (src_st, &dst_back_sb);
}
/* Copy the file SRC_NAME to the file DST_NAME aka DST_DIRFD+DST_RELNAME.
@@ -2220,22 +2217,16 @@ copy_internal (char const *src_name, char const *dst_name,
bool dest_is_symlink = false;
bool have_dst_lstat = false;
/* Whether the destination is (or was) known to be new, updated as
more info comes in. This may become true if the destination is a
dangling symlink, in contexts where dangling symlinks should be
treated the same as nonexistent files. */
bool new_dst = 0 < nonexistent_dst;
*copy_into_self = false;
int rename_errno = x->rename_errno;
if (x->move_mode)
if (x->move_mode && !x->exchange)
{
if (rename_errno < 0)
rename_errno = (renameatu (AT_FDCWD, src_name, dst_dirfd, drelname,
RENAME_NOREPLACE)
? errno : 0);
nonexistent_dst = *rename_succeeded = new_dst = rename_errno == 0;
nonexistent_dst = *rename_succeeded = rename_errno == 0;
}
if (rename_errno == 0
@@ -2293,8 +2284,21 @@ copy_internal (char const *src_name, char const *dst_name,
bool dereference = should_dereference (x, command_line_arg);
if (nonexistent_dst <= 0)
/* Whether the destination is (or was) known to be new, updated as
more info comes in. This may become true if the destination is a
dangling symlink, in contexts where dangling symlinks should be
treated the same as nonexistent files. */
bool new_dst = 0 < nonexistent_dst;
if (! new_dst)
{
/* Normally, fill in DST_SB or set NEW_DST so that later code
can use DST_SB if NEW_DST is false. However, don't bother
doing this when rename_errno == EEXIST and X->interactive is
I_ALWAYS_NO or I_ALWAYS_SKIP, something that can happen only
with mv in which case x->update must be false which means
that even if !NEW_DST the move will be abandoned without
looking at DST_SB. */
if (! (rename_errno == EEXIST
&& (x->interactive == I_ALWAYS_NO
|| x->interactive == I_ALWAYS_SKIP)))
@@ -2308,30 +2312,31 @@ copy_internal (char const *src_name, char const *dst_name,
bool use_lstat
= ((! S_ISREG (src_mode)
&& (! x->copy_as_regular
|| S_ISDIR (src_mode) || S_ISLNK (src_mode)))
|| (S_ISDIR (src_mode) && !x->keep_directory_symlink)
|| S_ISLNK (src_mode)))
|| x->move_mode || x->symbolic_link || x->hard_link
|| x->backup_type != no_backups
|| x->unlink_dest_before_opening);
int fstatat_flags = use_lstat ? AT_SYMLINK_NOFOLLOW : 0;
if (!use_lstat && nonexistent_dst < 0)
new_dst = true;
else if (follow_fstatat (dst_dirfd, drelname, &dst_sb, fstatat_flags)
== 0)
else if (0 <= follow_fstatat (dst_dirfd, drelname, &dst_sb,
use_lstat ? AT_SYMLINK_NOFOLLOW : 0))
{
have_dst_lstat = use_lstat;
rename_errno = EEXIST;
}
else if (errno == ENOENT)
new_dst = true;
else if (errno == ELOOP && !use_lstat
&& x->unlink_dest_after_failed_open)
{
/* cp -f's destination might be a symlink loop.
Leave new_dst=false so that we try to unlink later. */
}
else
{
if (errno == ELOOP && x->unlink_dest_after_failed_open)
/* leave new_dst=false so we unlink later. */;
else if (errno != ENOENT)
{
error (0, errno, _("cannot stat %s"), quoteaf (dst_name));
return false;
}
else
new_dst = true;
error (0, errno, _("cannot stat %s"), quoteaf (dst_name));
return false;
}
}
@@ -2445,72 +2450,36 @@ skip:
if (return_now)
return return_val;
if (!S_ISDIR (dst_sb.st_mode))
/* Copying a directory onto a non-directory, or vice versa,
is ok only with --backup or --exchange. */
if (!S_ISDIR (src_mode) != !S_ISDIR (dst_sb.st_mode)
&& x->backup_type == no_backups && !x->exchange)
{
if (S_ISDIR (src_mode))
{
if (x->move_mode && x->backup_type != no_backups)
{
/* Moving a directory onto an existing
non-directory is ok only with --backup. */
}
else
{
error (0, 0,
_("cannot overwrite non-directory %s with directory %s"),
quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
return false;
}
}
/* Don't let the user destroy their data, even if they try hard:
This mv command must fail (likewise for cp):
rm -rf a b c; mkdir a b c; touch a/f b/f; mv a/f b/f c
Otherwise, the contents of b/f would be lost.
In the case of 'cp', b/f would be lost if the user simulated
a move using cp and rm.
Note that it works fine if you use --backup=numbered. */
if (command_line_arg
&& x->backup_type != numbered_backups
&& seen_file (x->dest_info, dst_relname, &dst_sb))
{
error (0, 0,
_("will not overwrite just-created %s with %s"),
quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
return false;
}
error (0, 0,
_(S_ISDIR (src_mode)
? ("cannot overwrite non-directory %s "
"with directory %s")
: ("cannot overwrite directory %s "
"with non-directory %s")),
quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
return false;
}
if (!S_ISDIR (src_mode))
/* Don't let the user destroy their data, even if they try hard:
This mv command must fail (likewise for cp):
rm -rf a b c; mkdir a b c; touch a/f b/f; mv a/f b/f c
Otherwise, the contents of b/f would be lost.
In the case of 'cp', b/f would be lost if the user simulated
a move using cp and rm.
Nothing is lost if you use --backup=numbered or --exchange. */
if (!S_ISDIR (dst_sb.st_mode) && command_line_arg
&& x->backup_type != numbered_backups && !x->exchange
&& seen_file (x->dest_info, dst_relname, &dst_sb))
{
if (S_ISDIR (dst_sb.st_mode))
{
if (x->move_mode && x->backup_type != no_backups)
{
/* Moving a non-directory onto an existing
directory is ok only with --backup. */
}
else
{
error (0, 0,
_("cannot overwrite directory %s with non-directory"),
quoteaf (dst_name));
return false;
}
}
}
if (x->move_mode)
{
/* Don't allow user to move a directory onto a non-directory. */
if (S_ISDIR (src_sb.st_mode) && !S_ISDIR (dst_sb.st_mode)
&& x->backup_type == no_backups)
{
error (0, 0,
_("cannot move directory onto non-directory: %s -> %s"),
quotef_n (0, src_name), quotef_n (0, dst_name));
return false;
}
error (0, 0,
_("will not overwrite just-created %s with %s"),
quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
return false;
}
char const *srcbase;
@@ -2596,22 +2565,16 @@ skip:
&& ! x->move_mode
&& x->backup_type == no_backups)
{
bool lstat_ok = true;
struct stat tmp_buf;
struct stat *dst_lstat_sb;
/* If we did not follow symlinks above, good: use that data.
Otherwise, use AT_SYMLINK_NOFOLLOW, in case dst_name is a symlink. */
if (have_dst_lstat)
dst_lstat_sb = &dst_sb;
else if (fstatat (dst_dirfd, drelname, &tmp_buf, AT_SYMLINK_NOFOLLOW)
== 0)
dst_lstat_sb = &tmp_buf;
else
lstat_ok = false;
struct stat tmp_buf;
struct stat *dst_lstat_sb
= (have_dst_lstat ? &dst_sb
: fstatat (dst_dirfd, drelname, &tmp_buf, AT_SYMLINK_NOFOLLOW) < 0
? nullptr : &tmp_buf);
/* Never copy through a symlink we've just created. */
if (lstat_ok
if (dst_lstat_sb
&& S_ISLNK (dst_lstat_sb->st_mode)
&& seen_file (x->dest_info, dst_relname, dst_lstat_sb))
{
@@ -2627,7 +2590,7 @@ skip:
sure we'll create a directory. Also don't announce yet when moving
so we can distinguish renames versus copies. */
if (x->verbose && !x->move_mode && !S_ISDIR (src_mode))
emit_verbose (src_name, dst_name, dst_backup);
emit_verbose ("%s -> %s", src_name, dst_name, dst_backup);
/* Associate the destination file name with the source device and inode
so that if we encounter a matching dev/ino pair in the source tree
@@ -2659,7 +2622,7 @@ skip:
Also, with --recursive, record dev/ino of each command-line directory.
We'll use that info to detect this problem: cp -R dir dir. */
if (rename_errno == 0)
if (rename_errno == 0 || x->exchange)
earlier_file = nullptr;
else if (x->recursive && S_ISDIR (src_mode))
{
@@ -2755,16 +2718,18 @@ skip:
if (x->move_mode)
{
if (rename_errno == EEXIST)
rename_errno = (renameat (AT_FDCWD, src_name, dst_dirfd, drelname) == 0
rename_errno = ((renameatu (AT_FDCWD, src_name, dst_dirfd, drelname,
x->exchange ? RENAME_EXCHANGE : 0)
== 0)
? 0 : errno);
if (rename_errno == 0)
{
if (x->verbose)
{
printf (_("renamed "));
emit_verbose (src_name, dst_name, dst_backup);
}
emit_verbose (x->exchange
? _("exchanged %s <-> %s")
: _("renamed %s -> %s"),
src_name, dst_name, dst_backup);
if (x->set_security_context)
{
@@ -2783,7 +2748,7 @@ skip:
_destination_ dev/ino, since the rename above can't have
changed those, and 'mv' always uses lstat.
We could limit it further by operating
only on non-directories. */
only on non-directories when !x->exchange. */
record_file (x->dest_info, dst_relname, &src_sb);
}
@@ -2830,7 +2795,7 @@ skip:
where you'd replace '18' with the integer in parentheses that
was output from the perl one-liner above.
If necessary, of course, change '/tmp' to some other directory. */
if (rename_errno != EXDEV || x->no_copy)
if (rename_errno != EXDEV || x->no_copy || x->exchange)
{
/* There are many ways this can happen due to a race condition.
When something happens between the initial follow_fstatat and the
@@ -2843,25 +2808,29 @@ skip:
destination file are made too restrictive, the rename will
fail. Etc. */
char const *quoted_dst_name = quoteaf_n (1, dst_name);
switch (rename_errno)
{
case EDQUOT: case EEXIST: case EISDIR: case EMLINK:
case ENOSPC: case ETXTBSY:
if (x->exchange)
error (0, rename_errno, _("cannot exchange %s and %s"),
quoteaf_n (0, src_name), quoted_dst_name);
else
switch (rename_errno)
{
case EDQUOT: case EEXIST: case EISDIR: case EMLINK:
case ENOSPC: case ETXTBSY:
#if ENOTEMPTY != EEXIST
case ENOTEMPTY:
case ENOTEMPTY:
#endif
/* The destination must be the problem. Don't mention
the source as that is more likely to confuse the user
than be helpful. */
error (0, rename_errno, _("cannot overwrite %s"),
quoted_dst_name);
break;
/* The destination must be the problem. Don't mention
the source as that is more likely to confuse the user
than be helpful. */
error (0, rename_errno, _("cannot overwrite %s"),
quoted_dst_name);
break;
default:
error (0, rename_errno, _("cannot move %s to %s"),
quoteaf_n (0, src_name), quoted_dst_name);
break;
}
default:
error (0, rename_errno, _("cannot move %s to %s"),
quoteaf_n (0, src_name), quoted_dst_name);
break;
}
forget_created (src_sb.st_ino, src_sb.st_dev);
return false;
}
@@ -2885,10 +2854,7 @@ skip:
}
if (x->verbose && !S_ISDIR (src_mode))
{
printf (_("copied "));
emit_verbose (src_name, dst_name, dst_backup);
}
emit_verbose (_("copied %s -> %s"), src_name, dst_name, dst_backup);
new_dst = true;
}
@@ -2988,7 +2954,7 @@ skip:
if (x->move_mode)
printf (_("created directory %s\n"), quoteaf (dst_name));
else
emit_verbose (src_name, dst_name, nullptr);
emit_verbose ("%s -> %s", src_name, dst_name, nullptr);
}
}
else
@@ -3044,7 +3010,7 @@ skip:
|| stat (".", &dot_sb) != 0
|| (fstatat (dst_dirfd, dst_parent, &dst_parent_sb,
0) != 0)
|| SAME_INODE (dot_sb, dst_parent_sb));
|| psame_inode (&dot_sb, &dst_parent_sb));
free (dst_parent);
if (! in_current_dir)
@@ -3302,6 +3268,9 @@ skip:
{
int default_permissions = S_ISDIR (src_mode) || S_ISSOCK (src_mode)
? S_IRWXUGO : MODE_RW_UGO;
dst_mode = dst_sb.st_mode;
if (S_ISDIR (src_mode)) /* Keep set-group-ID for directories. */
default_permissions |= (dst_mode & S_ISGID);
if (set_acl (dst_name, -1, default_permissions & ~cached_umask ()) != 0)
return false;
}
@@ -3458,9 +3427,16 @@ chown_failure_ok (struct cp_options const *x)
{
/* If non-root uses -p, it's ok if we can't preserve ownership.
But root probably wants to know, e.g. if NFS disallows it,
or if the target system doesn't support file ownership. */
or if the target system doesn't support file ownership.
return ((errno == EPERM || errno == EINVAL) && !x->chown_privileges);
Treat EACCES like EPERM and EINVAL to work around a bug in Linux
CIFS <https://bugs.gnu.org/65599>. Although this means coreutils
will ignore EACCES errors that it should report, problems should
occur only when some other process is racing with coreutils and
coreutils is not immune to races anyway. */
return ((errno == EPERM || errno == EINVAL || errno == EACCES)
&& !x->chown_privileges);
}
/* Similarly, return true if it's OK for chmod and similar operations
@@ -3470,7 +3446,8 @@ chown_failure_ok (struct cp_options const *x)
static bool
owner_failure_ok (struct cp_options const *x)
{
return ((errno == EPERM || errno == EINVAL) && !x->owner_privileges);
return ((errno == EPERM || errno == EINVAL || errno == EACCES)
&& !x->owner_privileges);
}
/* Return the user's umask, caching the result.

View File

@@ -1,5 +1,5 @@
/* core functions for copying files and directories
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
@@ -68,6 +68,9 @@ enum Update_type
/* Leave existing files. */
UPDATE_NONE,
/* Leave existing files, but exit failure if existing files. */
UPDATE_NONE_FAIL,
};
/* This type is used to help mv (via copy.c) distinguish these cases. */
@@ -129,8 +132,8 @@ struct cp_options
if SET_MODE is nonzero. */
mode_t mode;
/* If true, copy all files except (directories and, if not dereferencing
them, symbolic links,) as if they were regular files. */
/* If true, copy all files except directories (and, if not dereferencing
them, symbolic links) as if they were regular files. */
bool copy_as_regular;
/* If true, remove each existing destination nondirectory before
@@ -152,6 +155,10 @@ struct cp_options
If that fails and NO_COPY, fail instead of copying. */
bool move_mode, no_copy;
/* Exchange instead of renaming. Valid only if MOVE_MODE and if
BACKUP_TYPE == no_backups. */
bool exchange;
/* If true, install(1) is the caller. */
bool install_mode;
@@ -256,6 +263,9 @@ struct cp_options
/* If true, display the names of the files before copying them. */
bool verbose;
/* If true, follow existing symlinks to directories when copying. */
bool keep_directory_symlink;
/* If true, display details of how files were copied. */
bool debug;
@@ -294,15 +304,6 @@ struct cp_options
Hash_table *src_info;
};
/* Arrange to make rename calls go through the wrapper function
on systems with a rename function that fails for a source file name
specified with a trailing slash. */
# if RENAME_TRAILING_SLASH_BUG
int rpl_rename (char const *, char const *);
# undef rename
# define rename rpl_rename
# endif
bool copy (char const *src_name, char const *dst_name,
int dst_dirfd, char const *dst_relname,
int nonexistent_dst, const struct cp_options *options,

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