|
@@ -116,7 +116,7 @@ char *get_options(const char *str, int nints, int *ints)
|
|
/**
|
|
/**
|
|
* memparse - parse a string with mem suffixes into a number
|
|
* memparse - parse a string with mem suffixes into a number
|
|
* @ptr: Where parse begins
|
|
* @ptr: Where parse begins
|
|
- * @retptr: (output) Pointer to next char after parse completes
|
|
|
|
|
|
+ * @retptr: (output) Optional pointer to next char after parse completes
|
|
*
|
|
*
|
|
* Parses a string into a number. The number stored at @ptr is
|
|
* Parses a string into a number. The number stored at @ptr is
|
|
* potentially suffixed with %K (for kilobytes, or 1024 bytes),
|
|
* potentially suffixed with %K (for kilobytes, or 1024 bytes),
|
|
@@ -126,11 +126,13 @@ char *get_options(const char *str, int nints, int *ints)
|
|
* megabyte, or one gigabyte, respectively.
|
|
* megabyte, or one gigabyte, respectively.
|
|
*/
|
|
*/
|
|
|
|
|
|
-unsigned long long memparse (char *ptr, char **retptr)
|
|
|
|
|
|
+unsigned long long memparse(char *ptr, char **retptr)
|
|
{
|
|
{
|
|
- unsigned long long ret = simple_strtoull (ptr, retptr, 0);
|
|
|
|
|
|
+ char *endptr; /* local pointer to end of parsed string */
|
|
|
|
|
|
- switch (**retptr) {
|
|
|
|
|
|
+ unsigned long long ret = simple_strtoull(ptr, &endptr, 0);
|
|
|
|
+
|
|
|
|
+ switch (*endptr) {
|
|
case 'G':
|
|
case 'G':
|
|
case 'g':
|
|
case 'g':
|
|
ret <<= 10;
|
|
ret <<= 10;
|
|
@@ -140,10 +142,14 @@ unsigned long long memparse (char *ptr, char **retptr)
|
|
case 'K':
|
|
case 'K':
|
|
case 'k':
|
|
case 'k':
|
|
ret <<= 10;
|
|
ret <<= 10;
|
|
- (*retptr)++;
|
|
|
|
|
|
+ endptr++;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (retptr)
|
|
|
|
+ *retptr = endptr;
|
|
|
|
+
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|