This was added in the following upstream commit:
commit d0f1fed29e6e73d9d17f4c91a5896a4ce3938d45
Author: Jonathan Cameron <[email protected]>
Date: Tue Apr 19 12:43:45 2011 +0100
Add a strtobool function matching semantics of existing in kernel
equivalents
Signed-off-by: Hauke Mehrtens <[email protected]>
---
backport/backport-include/linux/string.h | 5 +++++
backport/compat/compat-3.0.c | 29 +++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/backport/backport-include/linux/string.h
b/backport/backport-include/linux/string.h
index 819d141..f9f1750 100644
--- a/backport/backport-include/linux/string.h
+++ b/backport/backport-include/linux/string.h
@@ -8,4 +8,9 @@
extern size_t memweight(const void *ptr, size_t bytes);
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
+#define strtobool LINUX_BACKPORT(strtobool)
+extern int strtobool(const char *s, bool *res);
+#endif
+
#endif /* __BACKPORT_LINUX_STRING_H */
diff --git a/backport/compat/compat-3.0.c b/backport/compat/compat-3.0.c
index 9841019..1bed6a6 100644
--- a/backport/compat/compat-3.0.c
+++ b/backport/compat/compat-3.0.c
@@ -60,3 +60,32 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16,
u16);
kstrto_from_user(kstrtos16_from_user, kstrtos16, s16);
kstrto_from_user(kstrtou8_from_user, kstrtou8, u8);
kstrto_from_user(kstrtos8_from_user, kstrtos8, s8);
+
+/**
+ * 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_GPL(strtobool);
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe backports" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html