aboutsummaryrefslogtreecommitdiff
path: root/stdu.c
diff options
context:
space:
mode:
authorJoel Kronqvist <joelkronqvist@proton.me>2024-04-07 13:31:07 +0300
committerJoel Kronqvist <joelkronqvist@proton.me>2024-04-07 13:41:46 +0300
commit4ff6a08d73f0ef1e2fcb7a93a74cc6fa66c24e2b (patch)
tree40694627aac44a3f1eb52293b830337b81af69fb /stdu.c
parentf975594e55bdc05ee436bc7bdcd6e09aec5357b1 (diff)
downloadstdu-4ff6a08d73f0ef1e2fcb7a93a74cc6fa66c24e2b.tar.gz
stdu-4ff6a08d73f0ef1e2fcb7a93a74cc6fa66c24e2b.zip
Bigger `bytes_read` & removed redundant code handling impossible signed `bytes_read`
Diffstat (limited to 'stdu.c')
-rw-r--r--stdu.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/stdu.c b/stdu.c
index f2273f7..64f19a5 100644
--- a/stdu.c
+++ b/stdu.c
@@ -34,10 +34,11 @@ int main (int argc, char* argv[]) {
int blocksize = 1;
size_t bufsize = 1;
- unsigned int bytes_read = 0;
+ int bufsize_tries = 10;
+ unsigned long long bytes_read = 0;
size_t new_read_bytes = 0;
if (conf->precision != 0) {
- blocksize = exp_notated_to_int(int_ceiled_exponent_notation_base(
+ blocksize = exp_notated_to_ull(ull_ceiled_exponent_notation_base(
bytes_read + 1,
conf->precision,
base))
@@ -55,14 +56,14 @@ int main (int argc, char* argv[]) {
while (1) {
/* output */
if (conf->human_readable && base == 10) {
- int res = int_floored_with_prefix(
+ int res = ull_floored_with_prefix(
&stdout_buffer,
&stdout_buffer_size,
bytes_read,
conf->precision
);
if (res < 0) {
- printf("\r%u \
+ printf("\r%llu \
(error when getting prefix)",
bytes_read);
continue;
@@ -75,13 +76,13 @@ int main (int argc, char* argv[]) {
previous_line_strlen
= int_max(res, previous_line_strlen);
} else if (conf->human_readable && base == 1024) {
- int success = int_floored_with_binary_prefix(
+ int success = ull_floored_with_binary_prefix(
&stdout_buffer,
&stdout_buffer_size,
bytes_read
);
if (success < 0) {
- printf("\r%u \
+ printf("\r%llu \
(error when getting prefix)",
bytes_read);
}
@@ -91,7 +92,7 @@ int main (int argc, char* argv[]) {
stdout_buffer
);
} else {
- printf("\r%u", bytes_read);
+ printf("\r%llu", bytes_read);
}
if (fflush(stdout) == EOF) {
printf("\n");
@@ -120,8 +121,9 @@ int main (int argc, char* argv[]) {
/* resizing buffer and blocksize to read as much as possible
* at once
*/
+ if (bufsize_tries <= 0) continue;
if (conf->precision == 0) continue;
- blocksize = exp_notated_to_int(int_ceiled_exponent_notation_base(
+ blocksize = exp_notated_to_ull(ull_ceiled_exponent_notation_base(
bytes_read + 1,
conf->precision,
base))
@@ -129,6 +131,7 @@ int main (int argc, char* argv[]) {
if (blocksize > bufsize) {
tmpbuf = malloc(bufsize * 2);
if (tmpbuf == NULL) {
+ bufsize_tries--;
free(tmpbuf);
} else {
free(buf);