ls: add --null option (Bug#49716)

* NEWS, doc/coreutils.texi (General output formatting):
* src/ls.c (usage): Document this.
* src/ls.c (NULL_OPTION): New constant.
(long_options): Add --null.
(eolbyte): New static var.
(dired_dump_obstack, main, print_dir, print_current_files)
(print_many_per_line, print_horizontal, print_with_separator):
Output eolbyte instead of '\n'.
(decode_switches): Decode --null.
* tests/ls/null-option.sh: New file.
* tests/local.mk (all_tests): Add it.
This commit is contained in:
Paul Eggert
2021-07-25 21:24:02 -07:00
parent 39673b6d4c
commit 7d44ac224c
5 changed files with 66 additions and 14 deletions

33
tests/ls/null-option.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
# Verify behavior of ls --null.
# Copyright 2021 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/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ ls
mkdir dir && touch dir/a dir/b dir/cc || framework_failure_
LC_ALL=C ls --null dir >out || fail=1
tr '\n' '\0' <<EOF >exp
a
b
cc
EOF
compare exp out || fail=1
Exit $fail