X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fstring.c;h=01fad9b203e192eb8a3299d669c29e11e4cf2e04;hb=d0f1fed29e6e73d9d17f4c91a5896a4ce3938d45;hp=f71bead1be3efaf5694cbbe1df1d59edb18b74ae;hpb=6845756b29e4c4e7db41e2d75cafa9d091bc1c07;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git diff --git a/lib/string.c b/lib/string.c index f71bead..01fad9b 100644 --- a/lib/string.c +++ b/lib/string.c @@ -535,6 +535,35 @@ 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 + * + * 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 0; +} +EXPORT_SYMBOL(strtobool); + #ifndef __HAVE_ARCH_MEMSET /** * memset - Fill a region of memory with the given value