From: Jonathan Cameron <jic23@cam.ac.uk>
To: linux-kernel@vger.kernel.org
Cc: greg@kroah.com, rusty@rustcorp.com.au, adobriyan@gmail.com,
Jonathan Cameron <jic23@cam.ac.uk>
Subject: [PATCH 1/3] Add a usr_strtobool function matching semantics of existing in kernel equivalents
Date: Thu, 24 Mar 2011 13:23:43 +0000 [thread overview]
Message-ID: <1300973025-32497-2-git-send-email-jic23@cam.ac.uk> (raw)
In-Reply-To: <1300973025-32497-1-git-send-email-jic23@cam.ac.uk>
This is a renamed and relocated fixed version of previous kstrtobool RFC
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
include/linux/string.h | 1 +
lib/string.c | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index a716ee2..1977cc0 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -123,6 +123,7 @@ extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
extern void argv_free(char **argv);
extern bool sysfs_streq(const char *s1, const char *s2);
+extern int usr_strtobool(const char *s, bool *res);
#ifdef CONFIG_BINARY_PRINTF
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
diff --git a/lib/string.c b/lib/string.c
index f71bead..121bd65 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);
+/**
+ * usr_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 usr_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(usr_strtobool);
+
#ifndef __HAVE_ARCH_MEMSET
/**
* memset - Fill a region of memory with the given value
--
1.7.3.4
next prev parent reply other threads:[~2011-03-24 13:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-24 13:23 [RFC PATCH 0/3 V2] Introduce usr_strtobool (previously kstrtobool) Jonathan Cameron
2011-03-24 13:23 ` Jonathan Cameron [this message]
2011-04-19 1:36 ` [PATCH 1/3] Add a usr_strtobool function matching semantics of existing in kernel equivalents Rusty Russell
2011-04-19 11:31 ` Jonathan Cameron
2011-03-24 13:23 ` [PATCH 2/3] debugfs: move to new usr_strtobool Jonathan Cameron
2011-03-24 13:23 ` [PATCH 3/3] params.c: Use new usr_strtobool function to process boolean inputs Jonathan Cameron
2011-04-15 13:27 ` [RFC PATCH 0/3 V2] Introduce usr_strtobool (previously kstrtobool) Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1300973025-32497-2-git-send-email-jic23@cam.ac.uk \
--to=jic23@cam.ac.uk \
--cc=adobriyan@gmail.com \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®