summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@cam.ac.uk>2011-04-19 13:43:45 +0200
committerRusty Russell <rusty@rustcorp.com.au>2011-05-19 09:25:28 +0200
commitd0f1fed29e6e73d9d17f4c91a5896a4ce3938d45 (patch)
treed44eae96f46e728cb9d87bca1b2494022bf590a9 /lib
parentmodpost: Update 64k section support for binutils 2.18.50 (diff)
downloadlinux-d0f1fed29e6e73d9d17f4c91a5896a4ce3938d45.tar.xz
linux-d0f1fed29e6e73d9d17f4c91a5896a4ce3938d45.zip
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')
-rw-r--r--lib/string.c29
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)
}
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