X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=lib%2Fstring.c;h=ed83562a53ae5c57b7c55232cf703d3e4de90c58;hb=d9cb5bfcc3339f1a63df8fe0af8cece33c83c3af;hp=0323c0d5629af31e674bcfa24624e0917e2bb80d;hpb=5d50ac70fe98518dbf620bfba8184254663125eb;p=mirror_ubuntu-artful-kernel.git diff --git a/lib/string.c b/lib/string.c index 0323c0d5629a..ed83562a53ae 100644 --- a/lib/string.c +++ b/lib/string.c @@ -631,33 +631,30 @@ bool sysfs_streq(const char *s1, const char *s2) EXPORT_SYMBOL(sysfs_streq); /** - * strtobool - convert common user inputs into boolean values - * @s: input string - * @res: result + * match_string - matches given string in an array + * @array: array of strings + * @n: number of strings in the array or -1 for NULL terminated arrays + * @string: string to match with * - * This routine returns 0 iff the first character is one of 'Yy1Nn0'. - * Otherwise it will return -EINVAL. Value pointed to by res is - * updated upon finding a match. - */ -int strtobool(const char *s, bool *res) -{ - switch (s[0]) { - case 'y': - case 'Y': - case '1': - *res = true; - break; - case 'n': - case 'N': - case '0': - *res = false; - break; - default: - return -EINVAL; + * Return: + * index of a @string in the @array if matches, or %-EINVAL otherwise. + */ +int match_string(const char * const *array, size_t n, const char *string) +{ + int index; + const char *item; + + for (index = 0; index < n; index++) { + item = array[index]; + if (!item) + break; + if (!strcmp(item, string)) + return index; } - return 0; + + return -EINVAL; } -EXPORT_SYMBOL(strtobool); +EXPORT_SYMBOL(match_string); #ifndef __HAVE_ARCH_MEMSET /**