diff options
author | Jonathan Cameron <jic23@cam.ac.uk> | 2011-04-19 07:43:45 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-05-19 03:25:28 -0400 |
commit | d0f1fed29e6e73d9d17f4c91a5896a4ce3938d45 (patch) | |
tree | d44eae96f46e728cb9d87bca1b2494022bf590a9 /lib/string.c | |
parent | 6845756b29e4c4e7db41e2d75cafa9d091bc1c07 (diff) |
Add a strtobool function matching semantics of existing in kernel equivalents
This is a rename of the usr_strtobool proposal, which was a renamed,
relocated and fixed version of previous kstrtobool RFC
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/string.c')
-rw-r--r-- | lib/string.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c index f71bead1be3e..01fad9b203e1 100644 --- a/lib/string.c +++ b/lib/string.c | |||
@@ -535,6 +535,35 @@ bool sysfs_streq(const char *s1, const char *s2) | |||
535 | } | 535 | } |
536 | EXPORT_SYMBOL(sysfs_streq); | 536 | EXPORT_SYMBOL(sysfs_streq); |
537 | 537 | ||
538 | /** | ||
539 | * strtobool - convert common user inputs into boolean values | ||
540 | * @s: input string | ||
541 | * @res: result | ||
542 | * | ||
543 | * This routine returns 0 iff the first character is one of 'Yy1Nn0'. | ||
544 | * Otherwise it will return -EINVAL. Value pointed to by res is | ||
545 | * updated upon finding a match. | ||
546 | */ | ||
547 | int strtobool(const char *s, bool *res) | ||
548 | { | ||
549 | switch (s[0]) { | ||
550 | case 'y': | ||
551 | case 'Y': | ||
552 | case '1': | ||
553 | *res = true; | ||
554 | break; | ||
555 | case 'n': | ||
556 | case 'N': | ||
557 | case '0': | ||
558 | *res = false; | ||
559 | break; | ||
560 | default: | ||
561 | return -EINVAL; | ||
562 | } | ||
563 | return 0; | ||
564 | } | ||
565 | EXPORT_SYMBOL(strtobool); | ||
566 | |||
538 | #ifndef __HAVE_ARCH_MEMSET | 567 | #ifndef __HAVE_ARCH_MEMSET |
539 | /** | 568 | /** |
540 | * memset - Fill a region of memory with the given value | 569 | * memset - Fill a region of memory with the given value |