aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c19
-rw-r--r--lib/lib.h3
2 files changed, 22 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.
+ }
+}
diff --git a/lib/lib.h b/lib/lib.h
index 2b452566..5e5cbdf1 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -175,3 +175,6 @@ int update_password(char *filename, char* username, char* encrypted);
// du helper functions
char* make_human_readable(unsigned long long size, unsigned long unit);
+
+// cut helper functions
+unsigned long get_int_value(const char *numstr, unsigned lowrange, unsigned highrange);