diff options
| author | Dave Young <dyoung@redhat.com> | 2014-08-14 05:15:27 -0400 |
|---|---|---|
| committer | Matt Fleming <matt.fleming@intel.com> | 2014-10-03 13:40:58 -0400 |
| commit | 6ccc72b87b83ece31c2a75bbe07f440b0378f7a9 (patch) | |
| tree | 777aaf2d1e492963dc65bff61c236edb31532650 /lib | |
| parent | b2e0a54a1296a91b800f316df7bef7d1905e4fd0 (diff) | |
lib: Add a generic cmdline parse function parse_option_str
There should be a generic function to parse params like a=b,c
Adding parse_option_str in lib/cmdline.c which will return true
if there's specified option set in the params.
Also updated efi=old_map parsing code to use the new function
Signed-off-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/cmdline.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/cmdline.c b/lib/cmdline.c index 76a712e6e20e..8f13cf73c2ec 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c | |||
| @@ -160,3 +160,32 @@ unsigned long long memparse(const char *ptr, char **retptr) | |||
| 160 | return ret; | 160 | return ret; |
| 161 | } | 161 | } |
| 162 | EXPORT_SYMBOL(memparse); | 162 | EXPORT_SYMBOL(memparse); |
| 163 | |||
| 164 | /** | ||
| 165 | * parse_option_str - Parse a string and check an option is set or not | ||
| 166 | * @str: String to be parsed | ||
| 167 | * @option: option name | ||
| 168 | * | ||
| 169 | * This function parses a string containing a comma-separated list of | ||
| 170 | * strings like a=b,c. | ||
| 171 | * | ||
| 172 | * Return true if there's such option in the string, or return false. | ||
| 173 | */ | ||
| 174 | bool parse_option_str(const char *str, const char *option) | ||
| 175 | { | ||
| 176 | while (*str) { | ||
| 177 | if (!strncmp(str, option, strlen(option))) { | ||
| 178 | str += strlen(option); | ||
| 179 | if (!*str || *str == ',') | ||
| 180 | return true; | ||
| 181 | } | ||
| 182 | |||
| 183 | while (*str && *str != ',') | ||
| 184 | str++; | ||
| 185 | |||
| 186 | if (*str == ',') | ||
| 187 | str++; | ||
| 188 | } | ||
| 189 | |||
| 190 | return false; | ||
| 191 | } | ||
