diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-12-22 14:31:44 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-12-26 12:57:16 +0000 |
commit | e17e5f40b81447a2af65b0e64a3295d5e2e86753 (patch) | |
tree | 762ad410249552a67b467941acbcde0f8d3019a2 /tests/misc | |
parent | 94d2c6848b17b4e14235e80e6fa6af37aa76217b (diff) | |
download | coreutils-e17e5f40b81447a2af65b0e64a3295d5e2e86753.tar.xz |
wc: with only --bytes, determine size more efficiently
* src/wc.c (wc): Avoid reading the end of the file
when the size is not a multiple of PAGE_SIZE,
as the special case handling for files in /proc and /sys
is only required when st_size is 0 or a multiple of PAGE_SIZE.
* tests/misc/wc-proc.sh: Add a test case.
Diffstat (limited to 'tests/misc')
-rwxr-xr-x | tests/misc/wc-proc.sh | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/misc/wc-proc.sh b/tests/misc/wc-proc.sh index d6a36ba18..c50d7832b 100755 --- a/tests/misc/wc-proc.sh +++ b/tests/misc/wc-proc.sh @@ -19,6 +19,7 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ wc +# Ensure we read() /proc files to determine content length for file in /proc/version /sys/kernel/profiling; do if test -r $file; then cp -f $file copy && @@ -29,4 +30,16 @@ for file in /proc/version /sys/kernel/profiling; do fi done +# Ensure we handle cases where we don't read() +truncate -s 2 no_read || framework_failure_ +# read() used when multiple of page size +truncate -s 1048576 do_read || framework_failure_ +wc -c no_read do_read > out || fail=1 +cat <<\EOF > exp + 2 no_read +1048576 do_read +1048578 total +EOF +compare exp out || fail=1 + Exit $fail |