diff options
author | Simon Glass <sjg@chromium.org> | 2020-11-04 17:13:46 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-11-06 03:42:10 +0000 |
commit | 29c78b9d50929ae3a2d78752a50314305ab515da (patch) | |
tree | e45598c021acb56e07aa6bc16e09ded157378a5e /zephyr | |
parent | ced69556fb003c0336aa3cf74962127f622aa7ca (diff) | |
download | chrome-ec-29c78b9d50929ae3a2d78752a50314305ab515da.tar.gz |
zephyr: Provide parse_bool()
Add this function to the shim so it can be used in the keyboard code.
Drop strtoul() for now since it has the wrong signature.
BUG=b:167405015
BRANCH=none
TEST=zmake configure .../zephyr-chrome/projects/experimental/volteer \
-B /tmp/z/cos
zmake build /tmp/z/cos
See there are no errors
Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: I694369feb192cf49addb7444908b89b6081bffa1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2521360
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/shim/src/util.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/zephyr/shim/src/util.c b/zephyr/shim/src/util.c index 6cd6e0dc68..9538a82ac0 100644 --- a/zephyr/shim/src/util.c +++ b/zephyr/shim/src/util.c @@ -6,6 +6,7 @@ #include <common.h> #include <stdlib.h> #include <ctype.h> +#include <util.h> /* Int and Long are same size, just forward to existing Long implementation */ int strtoi(const char *nptr, char **endptr, int base) @@ -25,3 +26,23 @@ int strcasecmp(const char *s1, const char *s2) } while (*(s1++) && *(s2++)); return 0; } + +int parse_bool(const char *s, int *dest) +{ + /* off, disable, false, no */ + if (!strcasecmp(s, "off") || !strncasecmp(s, "dis", 3) || + tolower(*s) == 'f' || tolower(*s) == 'n') { + *dest = 0; + return 1; + } + + /* on, enable, true, yes */ + if (!strcasecmp(s, "on") || !strncasecmp(s, "ena", 3) || + tolower(*s) == 't' || tolower(*s) == 'y') { + *dest = 1; + return 1; + } + + /* dunno */ + return 0; +} |