aboutsummaryrefslogtreecommitdiff
path: root/stdu.c
diff options
context:
space:
mode:
Diffstat (limited to 'stdu.c')
-rw-r--r--stdu.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/stdu.c b/stdu.c
index 64f19a5..466d2f5 100644
--- a/stdu.c
+++ b/stdu.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <errno.h>
#include <stdbool.h>
+#include <limits.h>
#include "intmath.h"
#include "formatting.h"
@@ -26,6 +27,17 @@ int main (int argc, char* argv[]) {
Config* conf = (Config*) res.result;
+ if (conf->help) {
+ printf(
+"Usage: stdu [-h] [-p n]\n\
+Print amount of data piped to stdin.\n\
+--help | -?: print this help message\n\
+--human-readable | -h: output in a human readable format\n\
+--precision n | -p n | -pn: output with n significant digits\n "
+ );
+ return 0;
+ }
+
unsigned int base = 10;
if (conf->human_readable && conf->precision == 0) {
conf->precision = 1;
@@ -38,6 +50,15 @@ int main (int argc, char* argv[]) {
unsigned long long bytes_read = 0;
size_t new_read_bytes = 0;
if (conf->precision != 0) {
+ int max_precision = int_logn(base, (unsigned int) INT_MAX);
+ if (conf->precision > max_precision) {
+ fprintf(
+ stderr,
+ "Overflow error: precision may not be greater than %d\n",
+ max_precision
+ );
+ return 1;
+ }
blocksize = exp_notated_to_ull(ull_ceiled_exponent_notation_base(
bytes_read + 1,
conf->precision,