2010-01-08 03:42:27 -08:00
|
|
|
#!/bin/sh
|
|
|
|
|
# test splitting into 3 chunks
|
|
|
|
|
|
2025-01-01 09:14:56 +00:00
|
|
|
# Copyright (C) 2010-2025 Free Software Foundation, Inc.
|
2010-01-08 03:42:27 -08:00
|
|
|
|
|
|
|
|
# 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
|
2017-09-19 01:13:23 -07:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2010-01-08 03:42:27 -08:00
|
|
|
|
2012-09-02 21:55:12 +02:00
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
2010-01-08 03:42:27 -08:00
|
|
|
print_ver_ split
|
|
|
|
|
|
|
|
|
|
# N can be greater than the file size
|
|
|
|
|
# in which case no data is extracted, or empty files are written
|
|
|
|
|
split -n 10 /dev/null || fail=1
|
|
|
|
|
test "$(stat -c %s x* | uniq -c | sed 's/^ *//; s/ /x/')" = "10x0" || fail=1
|
2014-07-13 23:48:38 +01:00
|
|
|
rm -f x??
|
2010-01-08 03:42:27 -08:00
|
|
|
|
2023-03-04 11:41:03 -08:00
|
|
|
printf 'abc' > abc || framework_failure_
|
|
|
|
|
printf 'a' > exp-a || framework_failure_
|
|
|
|
|
printf 'b' > exp-b || framework_failure_
|
|
|
|
|
printf 'c' > exp-c || framework_failure_
|
|
|
|
|
printf 'ab' > exp-ab || framework_failure_
|
|
|
|
|
split -n 4 abc || fail=1
|
|
|
|
|
compare exp-a xaa || fail=1
|
|
|
|
|
compare exp-b xab || fail=1
|
|
|
|
|
compare exp-c xac || fail=1
|
|
|
|
|
compare /dev/null xad || fail=1
|
|
|
|
|
test ! -f xae || fail=1
|
|
|
|
|
rm -f x??
|
|
|
|
|
split -n 2 abc || fail=1
|
|
|
|
|
compare exp-ab xaa || fail=1
|
|
|
|
|
compare exp-c xab || fail=1
|
|
|
|
|
test ! -f xac || fail=1
|
|
|
|
|
rm -f x??
|
|
|
|
|
|
2016-11-24 00:03:16 +00:00
|
|
|
# When extracting K of N where N > file size
|
|
|
|
|
# no data is extracted, and no files are written
|
|
|
|
|
split -n 2/3 /dev/null || fail=1
|
|
|
|
|
returns_ 1 stat x?? 2>/dev/null || fail=1
|
|
|
|
|
|
2010-01-08 03:42:27 -08:00
|
|
|
# Ensure --elide-empty-files is honored
|
|
|
|
|
split -e -n 10 /dev/null || fail=1
|
2016-11-24 00:03:16 +00:00
|
|
|
returns_ 1 stat x?? 2>/dev/null || fail=1
|
2010-01-08 03:42:27 -08:00
|
|
|
|
2014-10-08 01:14:57 +01:00
|
|
|
printf '1\n2\n3\n4\n5\n' > input || framework_failure_
|
2023-03-04 11:41:03 -08:00
|
|
|
printf '1\n2\n' > exp-1 || framework_failure_
|
|
|
|
|
printf '3\n4' > exp-2 || framework_failure_
|
|
|
|
|
printf '\n5\n' > exp-3 || framework_failure_
|
2010-01-08 03:42:27 -08:00
|
|
|
|
2014-10-08 01:14:57 +01:00
|
|
|
for file in input /proc/version /sys/kernel/profiling; do
|
2014-10-07 18:08:25 -07:00
|
|
|
test -f $file || continue
|
|
|
|
|
|
2021-01-25 14:12:48 +00:00
|
|
|
for blksize in 1 2 4096; do
|
|
|
|
|
if ! test "$file" = 'input'; then
|
|
|
|
|
# For /proc like files we must be able to read all
|
|
|
|
|
# into the internal buffer to be able to determine size.
|
|
|
|
|
test "$blksize" = 4096 || continue
|
|
|
|
|
fi
|
wc: don't miscount /sys and similar file systems
Fix similar problems in head, od, split, tac, and tail.
Reported by George Shuklin in: http://bugs.gnu.org/18621
* NEWS: Document this.
* src/head.c (elseek): Move up.
(elide_tail_bytes_pipe, elide_tail_lines_pipe): New arg
CURRENT_POS. All uses changed.
(elide_tail_bytes_file, elide_tail_lines_file):
New arg ST and remove arg SIZE. All uses changed.
* src/head.c (elide_tail_bytes_file):
* src/od.c (skip): Avoid optimization for /sys files, where
st_size is bogus and st_size == st_blksize.
Don't report error at EOF when not optimizing.
* src/head.c, src/od.c, src/tail.c: Include "stat-size.h".
* src/split.c (input_file_size): New function.
(bytes_split, lines_chunk_split, bytes_chunk_extract): New arg
INITIAL_READ. All uses changed. Use it to double-check st_size.
* src/tac.c (tac_seekable): New arg FILE_POS. All uses changed.
(copy_to_temp): Return size of temp file. All uses changed.
* src/tac.c (tac_seekable):
* src/tail.c (tail_bytes):
* src/wc.c (wc):
Don't trust st_size; double-check by reading.
* src/wc.c (wc): New arg CURRENT_POS. All uses changed.
* tests/local.mk (all_tests): Add tests/misc/wc-proc.sh,
tests/misc/od-j.sh, tests/tail-2/tail-c.sh.
* tests/misc/head-c.sh:
* tests/misc/tac-2-nonseekable.sh:
* tests/split/b-chunk.sh:
Add tests for problems with /proc and /sys files.
* tests/misc/od-j.sh, tests/misc/wc-proc.sh, tests/tail-2/tail-c.sh:
New files.
2014-10-07 16:46:08 -07:00
|
|
|
|
2021-01-25 14:12:48 +00:00
|
|
|
split -n 3 ---io-blksize=$blksize $file > out || fail=1
|
|
|
|
|
split -n 1/3 ---io-blksize=$blksize $file > b1 || fail=1
|
|
|
|
|
split -n 2/3 ---io-blksize=$blksize $file > b2 || fail=1
|
|
|
|
|
split -n 3/3 ---io-blksize=$blksize $file > b3 || fail=1
|
wc: don't miscount /sys and similar file systems
Fix similar problems in head, od, split, tac, and tail.
Reported by George Shuklin in: http://bugs.gnu.org/18621
* NEWS: Document this.
* src/head.c (elseek): Move up.
(elide_tail_bytes_pipe, elide_tail_lines_pipe): New arg
CURRENT_POS. All uses changed.
(elide_tail_bytes_file, elide_tail_lines_file):
New arg ST and remove arg SIZE. All uses changed.
* src/head.c (elide_tail_bytes_file):
* src/od.c (skip): Avoid optimization for /sys files, where
st_size is bogus and st_size == st_blksize.
Don't report error at EOF when not optimizing.
* src/head.c, src/od.c, src/tail.c: Include "stat-size.h".
* src/split.c (input_file_size): New function.
(bytes_split, lines_chunk_split, bytes_chunk_extract): New arg
INITIAL_READ. All uses changed. Use it to double-check st_size.
* src/tac.c (tac_seekable): New arg FILE_POS. All uses changed.
(copy_to_temp): Return size of temp file. All uses changed.
* src/tac.c (tac_seekable):
* src/tail.c (tail_bytes):
* src/wc.c (wc):
Don't trust st_size; double-check by reading.
* src/wc.c (wc): New arg CURRENT_POS. All uses changed.
* tests/local.mk (all_tests): Add tests/misc/wc-proc.sh,
tests/misc/od-j.sh, tests/tail-2/tail-c.sh.
* tests/misc/head-c.sh:
* tests/misc/tac-2-nonseekable.sh:
* tests/split/b-chunk.sh:
Add tests for problems with /proc and /sys files.
* tests/misc/od-j.sh, tests/misc/wc-proc.sh, tests/tail-2/tail-c.sh:
New files.
2014-10-07 16:46:08 -07:00
|
|
|
|
2021-01-25 14:12:48 +00:00
|
|
|
case $file in
|
|
|
|
|
input)
|
|
|
|
|
compare exp-1 xaa || fail=1
|
|
|
|
|
compare exp-2 xab || fail=1
|
|
|
|
|
compare exp-3 xac || fail=1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
wc: don't miscount /sys and similar file systems
Fix similar problems in head, od, split, tac, and tail.
Reported by George Shuklin in: http://bugs.gnu.org/18621
* NEWS: Document this.
* src/head.c (elseek): Move up.
(elide_tail_bytes_pipe, elide_tail_lines_pipe): New arg
CURRENT_POS. All uses changed.
(elide_tail_bytes_file, elide_tail_lines_file):
New arg ST and remove arg SIZE. All uses changed.
* src/head.c (elide_tail_bytes_file):
* src/od.c (skip): Avoid optimization for /sys files, where
st_size is bogus and st_size == st_blksize.
Don't report error at EOF when not optimizing.
* src/head.c, src/od.c, src/tail.c: Include "stat-size.h".
* src/split.c (input_file_size): New function.
(bytes_split, lines_chunk_split, bytes_chunk_extract): New arg
INITIAL_READ. All uses changed. Use it to double-check st_size.
* src/tac.c (tac_seekable): New arg FILE_POS. All uses changed.
(copy_to_temp): Return size of temp file. All uses changed.
* src/tac.c (tac_seekable):
* src/tail.c (tail_bytes):
* src/wc.c (wc):
Don't trust st_size; double-check by reading.
* src/wc.c (wc): New arg CURRENT_POS. All uses changed.
* tests/local.mk (all_tests): Add tests/misc/wc-proc.sh,
tests/misc/od-j.sh, tests/tail-2/tail-c.sh.
* tests/misc/head-c.sh:
* tests/misc/tac-2-nonseekable.sh:
* tests/split/b-chunk.sh:
Add tests for problems with /proc and /sys files.
* tests/misc/od-j.sh, tests/misc/wc-proc.sh, tests/tail-2/tail-c.sh:
New files.
2014-10-07 16:46:08 -07:00
|
|
|
|
2021-01-25 14:12:48 +00:00
|
|
|
compare xaa b1 || fail=1
|
|
|
|
|
compare xab b2 || fail=1
|
|
|
|
|
compare xac b3 || fail=1
|
|
|
|
|
cat xaa xab xac | compare - $file || fail=1
|
|
|
|
|
test -f xad && fail=1
|
|
|
|
|
done
|
wc: don't miscount /sys and similar file systems
Fix similar problems in head, od, split, tac, and tail.
Reported by George Shuklin in: http://bugs.gnu.org/18621
* NEWS: Document this.
* src/head.c (elseek): Move up.
(elide_tail_bytes_pipe, elide_tail_lines_pipe): New arg
CURRENT_POS. All uses changed.
(elide_tail_bytes_file, elide_tail_lines_file):
New arg ST and remove arg SIZE. All uses changed.
* src/head.c (elide_tail_bytes_file):
* src/od.c (skip): Avoid optimization for /sys files, where
st_size is bogus and st_size == st_blksize.
Don't report error at EOF when not optimizing.
* src/head.c, src/od.c, src/tail.c: Include "stat-size.h".
* src/split.c (input_file_size): New function.
(bytes_split, lines_chunk_split, bytes_chunk_extract): New arg
INITIAL_READ. All uses changed. Use it to double-check st_size.
* src/tac.c (tac_seekable): New arg FILE_POS. All uses changed.
(copy_to_temp): Return size of temp file. All uses changed.
* src/tac.c (tac_seekable):
* src/tail.c (tail_bytes):
* src/wc.c (wc):
Don't trust st_size; double-check by reading.
* src/wc.c (wc): New arg CURRENT_POS. All uses changed.
* tests/local.mk (all_tests): Add tests/misc/wc-proc.sh,
tests/misc/od-j.sh, tests/tail-2/tail-c.sh.
* tests/misc/head-c.sh:
* tests/misc/tac-2-nonseekable.sh:
* tests/split/b-chunk.sh:
Add tests for problems with /proc and /sys files.
* tests/misc/od-j.sh, tests/misc/wc-proc.sh, tests/tail-2/tail-c.sh:
New files.
2014-10-07 16:46:08 -07:00
|
|
|
done
|
2010-01-08 03:42:27 -08:00
|
|
|
|
|
|
|
|
Exit $fail
|