diff options
author | B. Watson <urchlay@slackware.uk> | 2024-12-23 06:35:29 -0500 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-12-23 06:35:29 -0500 |
commit | 6d2c1195f8a3792da1749466b6af587b2154062c (patch) | |
tree | 3f3704cbfad93dfac6eacb1664508c62708530eb /uxd.c | |
parent | 35587b5e3614b9f74040730b23acb88c080535b2 (diff) | |
download | uxd-6d2c1195f8a3792da1749466b6af587b2154062c.tar.gz |
-l arg: allow redundadnt b/B for bytes, error on any other suffix
Diffstat (limited to 'uxd.c')
-rw-r--r-- | uxd.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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; } |