mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-08-12 03:51:30 +02:00
split: port ‘split -n N /dev/null’ better to macOS
* src/split.c (input_file_size): Do not bother with lseek if the initial read probe reaches EOF, since the file size is known then. This works better on macOS, which doesn’t allow lseek on /dev/null. Do not special-case size-zero files, as the issue can occur with any size file (though /proc files are the most common). If the current position is past end of file, treat this as size zero regardless of whether the file has a usable st_size. Pass through lseek -1 return values rather than using ‘return -1’; this makes the code a bit easier to analyze (and a bit faster). Avoid undefined behavior if the size calculation overflows. (lines_chunk_split): Do not bother with lseek if it would have no effect if successful. This works better on macOS, which doesn’t allow lseek on /dev/null. * tests/split/l-chunk.sh: Adjust to match fixed behavior.
This commit is contained in:
@@ -24,9 +24,10 @@ echo "split: invalid number of chunks: '1o'" > exp
|
||||
returns_ 1 split -n l/1o 2>err || fail=1
|
||||
compare exp err || fail=1
|
||||
|
||||
echo "split: -: cannot determine file size" > exp
|
||||
: | returns_ 1 split -n l/1 2>err || fail=1
|
||||
compare exp err || fail=1
|
||||
rm -f x* || fail=1
|
||||
: | split -n l/1 || fail=1
|
||||
compare /dev/null xaa || fail=1
|
||||
test ! -f xab || fail=1
|
||||
|
||||
# N can be greater than the file size
|
||||
# in which case no data is extracted, or empty files are written
|
||||
|
||||
Reference in New Issue
Block a user