diff options
Diffstat (limited to 'stdu.c')
-rw-r--r-- | stdu.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -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); |