diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-01-05 14:48:44 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-01-05 14:48:44 +0200 |
commit | 0e9e21139dc19f81d38957035a4ba603917cb77b (patch) | |
tree | 1388566d553f9f3ae6b77111bb03a3277cdbb9a1 /stdu.c | |
parent | 576b7a70dbf6c43651dc77db3a0104c019eed018 (diff) | |
download | stdu-0e9e21139dc19f81d38957035a4ba603917cb77b.tar.gz stdu-0e9e21139dc19f81d38957035a4ba603917cb77b.zip |
Bug fix for `--forward`HEADwork/1.1.1master
`--forward` used printf for outputting data to stdout, which failed with binary data that didn\'t first of all neccessarily contain null bytes and secondly could contain unexpected null bytes. Also fixed the trailing newline appended to files when using `--forward`. That bug in turn was caused by the newline getting sent to the wrong place - it was meant to the user.
Diffstat (limited to 'stdu.c')
-rw-r--r-- | stdu.c | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -83,7 +83,7 @@ Print amount of data piped to stdin.\n\ int previous_line_strlen = 0; while (1) { - /* output */ + /* output to the user */ if (conf->human_readable && base == 10) { int res = ull_floored_with_prefix( &stdout_buffer, @@ -166,9 +166,9 @@ Print amount of data piped to stdin.\n\ } bytes_read += new_read_bytes; - /* writing */ + /* writing forwarded data */ if (conf->forward) { - printf("%s", buf); + fwrite(buf, 1, new_read_bytes, stdout); } /* resizing buffer and blocksize to read as much as possible @@ -176,11 +176,15 @@ Print amount of data piped to stdin.\n\ */ if (bufsize_tries <= 0) continue; if (conf->precision == 0) continue; - blocksize = exp_notated_to_ull(ull_ceiled_exponent_notation_base( - bytes_read + 1, - conf->precision, - base)) - - bytes_read; + + blocksize = exp_notated_to_ull( + ull_ceiled_exponent_notation_base( + bytes_read + 1, + conf->precision, + base + ) + ) - bytes_read; + if (blocksize > bufsize) { tmpbuf = malloc(bufsize * 2); if (tmpbuf == NULL) { @@ -193,7 +197,7 @@ Print amount of data piped to stdin.\n\ } } } - printf("\n"); + fprintf(progress_destination, "\n"); free(stdout_buffer); return 0; |