aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-01-05 14:48:44 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-01-05 14:48:44 +0200
commit0e9e21139dc19f81d38957035a4ba603917cb77b (patch)
tree1388566d553f9f3ae6b77111bb03a3277cdbb9a1
parent576b7a70dbf6c43651dc77db3a0104c019eed018 (diff)
downloadstdu-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.
-rw-r--r--README2
-rw-r--r--stdu.c22
2 files changed, 14 insertions, 10 deletions
diff --git a/README b/README
index de272e3..21caa6c 100644
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
-stdu 1.1.0 README
+stdu 1.1.1 README
=================
`stdu` is a program for monitoring the amount of
diff --git a/stdu.c b/stdu.c
index e549440..24833a0 100644
--- a/stdu.c
+++ b/stdu.c
@@ -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;