aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-23 06:35:29 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-23 06:35:29 -0500
commit6d2c1195f8a3792da1749466b6af587b2154062c (patch)
tree3f3704cbfad93dfac6eacb1664508c62708530eb
parent35587b5e3614b9f74040730b23acb88c080535b2 (diff)
downloaduxd-6d2c1195f8a3792da1749466b6af587b2154062c.tar.gz
-l arg: allow redundadnt b/B for bytes, error on any other suffix
-rw-r--r--uxd.c13
1 files changed, 9 insertions, 4 deletions
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;
}