aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-11-16 12:26:48 -0600
committerRob Landley <rob@landley.net>2012-11-16 12:26:48 -0600
commit734b530f3797d6d11dc3ab996a889482cc88a8ab (patch)
treefd3cb74348445ccfe3d6738061ab49f4a5a2efe2 /lib/lib.c
parent4521f416ba8422563db6a762061a4a960db1bbf7 (diff)
downloadtoybox-734b530f3797d6d11dc3ab996a889482cc88a8ab.tar.gz
Add cut from Jason Kyungwan Han.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 18578815..49f2be5e 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1099,3 +1099,22 @@ char* make_human_readable(unsigned long long size, unsigned long unit)
}
return NULL; //not reached
}
+
+/*
+ * used to get the interger value.
+ */
+unsigned long get_int_value(const char *numstr, unsigned lowrange, unsigned highrange)
+{
+ unsigned long rvalue = 0;
+ char *ptr;
+ if(*numstr == '-' || *numstr == '+' || isspace(*numstr)) perror_exit("invalid number '%s'", numstr);
+ errno = 0;
+ rvalue = strtoul(numstr, &ptr, 10);
+ if(errno || numstr == ptr) perror_exit("invalid number '%s'", numstr);
+ if(*ptr) perror_exit("invalid number '%s'", numstr);
+ if(rvalue >= lowrange && rvalue <= highrange) return rvalue;
+ else {
+ perror_exit("invalid number '%s'", numstr);
+ return rvalue; //Not reachable; to avoid waring message.
+ }
+}