Pádraig Brady <[email protected]> writes:

> * src/cksum.c (main): Avoid the overhead of line buffering with -z,
> which might also negatively impact the interleaved output if
> there were newlines in file names.
> ---
>  src/cksum.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/src/cksum.c b/src/cksum.c
> index 1fdfcf8fd..9d9b9e157 100644
> --- a/src/cksum.c
> +++ b/src/cksum.c
> @@ -1605,10 +1605,6 @@ main (int argc, char **argv)
>  
>    atexit (close_stdout);
>  
> -  /* Line buffer stdout to ensure lines are written atomically and 
> immediately
> -     so that processes running in parallel do not intersperse their output.  
> */
> -  setvbuf (stdout, NULL, _IOLBF, 0);
> -
>  #if HASH_ALGO_SUM
>    char const *short_opts = "rs";
>  #elif HASH_ALGO_CKSUM
> @@ -1710,6 +1706,11 @@ main (int argc, char **argv)
>          usage (EXIT_FAILURE);
>        }
>  
> +  /* Flush newline-delimited records promptly
> +     so that processes running in parallel avoid interspersing their output. 
>  */
> +  if (digest_delim == '\n')
> +    setvbuf (stdout, NULL, _IOLBF, 0);
> +

Ah, nice catch. So it would previously split some (albeit uncommon) file names:

    $ touch a$'\n'b
    $ strace -e trace='/write' cksum -z --untagged -a sha2 -l 256 \
        a$'\n'b >/dev/null
    write(1, "e3b0c44298fc1c149afbf4c8996fb924"..., 68) = 68
    write(1, "b\0", 2)                      = 2
    +++ exited with 0 +++

Collin

Reply via email to