diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2020-11-26 19:31:54 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-11-27 10:02:36 +0100 |
commit | 8f57bc80c3e6a9f1c5318b52b98e9cc3268d10a8 (patch) | |
tree | 4bdd637c26eeacb9928cf36f2e91ca09a5084c6b /common | |
parent | 870f45338872b5ac02b2f87b6409036a6292ecf3 (diff) | |
download | barebox-8f57bc80c3e6a9f1c5318b52b98e9cc3268d10a8.tar.gz barebox-8f57bc80c3e6a9f1c5318b52b98e9cc3268d10a8.tar.xz |
commands: implement and use parse_assignment helper
We have the split by '=' snippet at multiple locations that parse
key=value pairs. Consolidate them to a single location. This makes code
a bit easier to read at the cost of an extra 8 bytes (LZO-compressed
THUMB2 barebox, static inline version is bigger).
No functional change.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/bootchooser.c | 4 | ||||
-rw-r--r-- | common/fastboot.c | 4 | ||||
-rw-r--r-- | common/hush.c | 3 |
3 files changed, 3 insertions, 8 deletions
diff --git a/common/bootchooser.c b/common/bootchooser.c index 7aa59d8a82..e982c22730 100644 --- a/common/bootchooser.c +++ b/common/bootchooser.c @@ -151,14 +151,12 @@ static int pr_setenv(struct bootchooser *bc, const char *fmt, ...) if (!str) return -ENOMEM; - val = strchr(str, '='); + val = parse_assignment(str); if (!val) { ret = -EINVAL; goto err; } - *val++ = '\0'; - oldval = getenv(str); if (!oldval || strcmp(oldval, val)) { if (bc->state) diff --git a/common/fastboot.c b/common/fastboot.c index 1b6dc28d8e..10b4ccf716 100644 --- a/common/fastboot.c +++ b/common/fastboot.c @@ -823,14 +823,12 @@ static void cb_oem_setenv(struct fastboot *fb, const char *cmd) pr_debug("%s: \"%s\"\n", __func__, cmd); - value = strchr(var, '='); + value = parse_assignment(var); if (!value) { ret = -EINVAL; goto out; } - *value++ = 0; - ret = setenv(var, value); if (ret) goto out; diff --git a/common/hush.c b/common/hush.c index a6fc4485bf..109bae4d3f 100644 --- a/common/hush.c +++ b/common/hush.c @@ -1117,12 +1117,11 @@ static int set_local_var(const char *s, int flg_export) /* Assume when we enter this function that we are already in * NAME=VALUE format. So the first order of business is to * split 's' on the '=' into 'name' and 'value' */ - value = strchr(name, '='); + value = parse_assignment(name); if (!value) { free(name); return -1; } - *value++ = 0; remove_quotes_in_str(value); |