diff options
Diffstat (limited to 'lib/cmdline.c')
-rw-r--r-- | lib/cmdline.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/cmdline.c b/lib/cmdline.c index d11fdc579170..b390dd03363b 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -35,25 +35,37 @@ static int get_range(char **str, int *pint, int n) /** * get_option - Parse integer from an option string * @str: option string - * @pint: (output) integer value parsed from @str + * @pint: (optional output) integer value parsed from @str * * Read an int from an option string; if available accept a subsequent * comma as well. * + * When @pint is NULL the function can be used as a validator of + * the current option in the string. + * * Return values: * 0 - no int in string * 1 - int found, no subsequent comma * 2 - int found including a subsequent comma * 3 - hyphen found to denote a range + * + * Leading hyphen without integer is no integer case, but we consume it + * for the sake of simplification. */ int get_option(char **str, int *pint) { char *cur = *str; + int value; if (!cur || !(*cur)) return 0; - *pint = simple_strtol(cur, str, 0); + if (*cur == '-') + value = -simple_strtoull(++cur, str, 0); + else + value = simple_strtoull(cur, str, 0); + if (pint) + *pint = value; if (cur == *str) return 0; if (**str == ',') { |