summaryrefslogtreecommitdiffstats
path: root/lib/strutils.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2011-10-14 22:32:15 +0200
committerKarel Zak2011-10-17 11:06:48 +0200
commitaf7df9ee67248029aa47a3e5b2db6e8cbe1915fd (patch)
tree601641a175483e90dfb3432467af0bde82139f9e /lib/strutils.c
parentfstrim: fix section number in referral to manpage (diff)
downloadkernel-qcow2-util-linux-af7df9ee67248029aa47a3e5b2db6e8cbe1915fd.tar.gz
kernel-qcow2-util-linux-af7df9ee67248029aa47a3e5b2db6e8cbe1915fd.tar.xz
kernel-qcow2-util-linux-af7df9ee67248029aa47a3e5b2db6e8cbe1915fd.zip
lib,strutils: add default value to parse_range()
This function currently sets the low or high values to 0 when the string doesn't contain a value, like '123:' or ':123'. In order to make it more flexible, we allow it to be passed an arbitrary value. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'lib/strutils.c')
-rw-r--r--lib/strutils.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/strutils.c b/lib/strutils.c
index fb1822976..6b2ec799e 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -464,18 +464,19 @@ int string_to_bitarray(const char *list,
/*
* Parse the lower and higher values in a string containing
* "lower:higher" or "lower-higher" format. Note that either
- * the lower or the higher values may be missing.
+ * the lower or the higher values may be missing, and the def
+ * value will be assigned to it by default.
*
* Returns: 0 on success, <0 on error.
*/
-int parse_range(const char *str, int *lower, int *upper)
+int parse_range(const char *str, int *lower, int *upper, int def)
{
char *end = NULL;
if (!str)
return 0;
- *upper = *lower = 0;
+ *upper = *lower = def;
errno = 0;
if (*str == ':') { /* <:N> */