Repository navigation
wc: derive column width from the size of stdin - #14187
Socialpranker wants to merge 2 commits into
Conversation
|
Side-by-side check against GNU
|
|
GNU testsuite comparison: |
|
A bunch of jobs are failing |
|
Is there a bug somewhere about this issue? |
|
No, there's no filed issue — I found it by diffing uutils against GNU coreutils on the same inputs. The reproducer is in the description above: GNU prints The red CI here isn't from this change: the same jobs (wasm32-wasip1, i686-pc-windows-msvc, and others) are failing on main right now. |
97fa3cd to
61a55cc
Compare
|
rebased. had to update test_count_bytes_from_repeated_redirected_stdin, GNU prints ' 6 -' there, and skipped it on wasi |
e399c33 to
e82d03c
Compare
e82d03c to
9e3c2f1
Compare
A regular file redirected onto stdin has a size known up front, so it sets the column width the same way a named file does, as GNU wc does. Pipes and other streams keep the minimum-width fallback.
9e3c2f1 to
08894a7
Compare
|
Rebased onto main to rerun CI. None of the earlier failures were in |
wcpads its counts to a width derived from the total size of its inputs, butstdin was always treated as a stream of unknown length, even when it is a
regular file whose size
fstatreports up front. The same 839-byte filetherefore printed differently depending on how it was handed to
wc:GNU
wcprints18 20 839in both cases; it only falls back to the minimumwidth when the size genuinely is not known in advance.
This PR takes the size of stdin from its metadata when stdin is a regular file
and feeds it into the existing width computation, so:
wc < filematcheswc file;-argument contributes the size of stdin to the total, the way a namedfile does (
wc - other-file < filewidens to fitsize(file) + size(other));cat file | wcandwc < /dev/nullstill use the minimum width of 7;named file behaves.
The digit-width calculation that was inline in
compute_number_widthis pulledout into a small
width_ofhelper so both the stdin-only and the mixed-inputpaths share it.
Testing: new
test_stdin_size_dictates_widthintests/by-util/test_wc.rscovers the three cases (regular file on stdin, the same content piped in, and
-mixed with a named file). It fails on the currentmainand passes withthis change. The full
wcsuite is green (58 passed),cargo fmt --checkandcargo clippy -p uu_wc --all-targetsare clean.Behaviour was established by observing GNU
wc's output on a Debian system —no GNU source was consulted.