aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/string.h1
-rw-r--r--lib/string.c29
2 files changed, 30 insertions, 0 deletions
diff --git a/include/linux/string.h b/include/linux/string.h
index a716ee2a8adb..a176db2f2c85 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);
123extern void argv_free(char **argv); 123extern void argv_free(char **argv);
124 124
125extern bool sysfs_streq(const char *s1, const char *s2); 125extern bool sysfs_streq(const char *s1, const char *s2);
126extern int strtobool(const char *s, bool *res);
126 127
127#ifdef CONFIG_BINARY_PRINTF 128#ifdef CONFIG_BINARY_PRINTF
128int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args); 129int 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 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}
536EXPORT_SYMBOL(sysfs_streq); 536EXPORT_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 */
547int 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}
565EXPORT_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