From 6d2c1195f8a3792da1749466b6af587b2154062c Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 23 Dec 2024 06:35:29 -0500 Subject: -l arg: allow redundadnt b/B for bytes, error on any other suffix --- uxd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'uxd.c') diff --git a/uxd.c b/uxd.c index e5317ce..ef86bb7 100644 --- a/uxd.c +++ b/uxd.c @@ -250,11 +250,12 @@ long parse_number(int opt, const char *s) { if(e == s) number_err(opt); - /* buglets here: 100x is correctly rejected, but 100kx is allowed - (the x is ignored). not gonna worry about it. some people might - even make use of it: 100kb or 100Kb will work. */ - switch(*e) { + switch(e[0]) { case 0: break; + case 'b': + case 'B': + if(e[1]) number_err(opt); + break; /* allow & ignore b/B for "bytes" */ case 'k': result *= 1024L; break; case 'm': result *= 1048576L; break; case 'g': result *= 1073741824L; break; @@ -265,6 +266,10 @@ long parse_number(int opt, const char *s) { number_err(opt); } + /* allow e.g. "kb" for kilobytes (but reject e.g. "kx") */ + if(e[0] && e[1] && e[1] != 'b' && e[1] != 'B') + number_err(opt); + return result; } -- cgit v1.2.3