diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-20 14:35:33 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-20 14:47:33 -0400 |
commit | b99e4850df86dfd9dc2cf3f3494e403ff8b46876 (patch) | |
tree | a753ac7dbea39674d34d97f74a6456b349a30dce /tools/lib | |
parent | 8e99b6d4533cf3f49dcd813155a513a5b572baef (diff) |
tools lib: Update copy of strtobool from the kernel sources
Getting support for "on", "off" introduced in a81a5a17d44b ("lib: add
"on"/"off" support to kstrtobool") and making it check for NULL,
introduced in ef951599074b ("lib: move strtobool() to kstrtobool()").
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Kees Cook <keescook@chromium.org>
Link: http://lkml.kernel.org/n/tip-mu8ghin4rklacmmubzwv8td7@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/string.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/tools/lib/string.c b/tools/lib/string.c index bd239bc1d557..a4246f14ded1 100644 --- a/tools/lib/string.c +++ b/tools/lib/string.c | |||
@@ -39,27 +39,45 @@ void *memdup(const void *src, size_t len) | |||
39 | * @s: input string | 39 | * @s: input string |
40 | * @res: result | 40 | * @res: result |
41 | * | 41 | * |
42 | * This routine returns 0 iff the first character is one of 'Yy1Nn0'. | 42 | * This routine returns 0 iff the first character is one of 'Yy1Nn0', or |
43 | * Otherwise it will return -EINVAL. Value pointed to by res is | 43 | * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value |
44 | * updated upon finding a match. | 44 | * pointed to by res is updated upon finding a match. |
45 | */ | 45 | */ |
46 | int strtobool(const char *s, bool *res) | 46 | int strtobool(const char *s, bool *res) |
47 | { | 47 | { |
48 | if (!s) | ||
49 | return -EINVAL; | ||
50 | |||
48 | switch (s[0]) { | 51 | switch (s[0]) { |
49 | case 'y': | 52 | case 'y': |
50 | case 'Y': | 53 | case 'Y': |
51 | case '1': | 54 | case '1': |
52 | *res = true; | 55 | *res = true; |
53 | break; | 56 | return 0; |
54 | case 'n': | 57 | case 'n': |
55 | case 'N': | 58 | case 'N': |
56 | case '0': | 59 | case '0': |
57 | *res = false; | 60 | *res = false; |
58 | break; | 61 | return 0; |
62 | case 'o': | ||
63 | case 'O': | ||
64 | switch (s[1]) { | ||
65 | case 'n': | ||
66 | case 'N': | ||
67 | *res = true; | ||
68 | return 0; | ||
69 | case 'f': | ||
70 | case 'F': | ||
71 | *res = false; | ||
72 | return 0; | ||
73 | default: | ||
74 | break; | ||
75 | } | ||
59 | default: | 76 | default: |
60 | return -EINVAL; | 77 | break; |
61 | } | 78 | } |
62 | return 0; | 79 | |
80 | return -EINVAL; | ||
63 | } | 81 | } |
64 | 82 | ||
65 | /** | 83 | /** |