summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2020-11-26 19:31:54 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-11-27 10:02:36 +0100
commit8f57bc80c3e6a9f1c5318b52b98e9cc3268d10a8 (patch)
tree4bdd637c26eeacb9928cf36f2e91ca09a5084c6b /commands
parent870f45338872b5ac02b2f87b6409036a6292ecf3 (diff)
downloadbarebox-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 'commands')
-rw-r--r--commands/export.c4
-rw-r--r--commands/global.c6
-rw-r--r--commands/nv.c9
-rw-r--r--commands/setenv.c10
4 files changed, 8 insertions, 21 deletions
diff --git a/commands/export.c b/commands/export.c
index 8972b7d528..c69f1595c6 100644
--- a/commands/export.c
+++ b/commands/export.c
@@ -20,10 +20,8 @@ static int do_export(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
while (i < argc) {
- if ((ptr = strchr(argv[i], '='))) {
- *ptr++ = 0;
+ if ((ptr = parse_assignment(argv[i])))
setenv(argv[i], ptr);
- }
if (export(argv[i])) {
printf("could not export: %s\n", argv[i]);
return 1;
diff --git a/commands/global.c b/commands/global.c
index 15b6a9f3d3..cf8e9a5b48 100644
--- a/commands/global.c
+++ b/commands/global.c
@@ -37,11 +37,7 @@ static int do_global(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
for (i = 0; i < argc; i++) {
- value = strchr(argv[i], '=');
- if (value) {
- *value = 0;
- value++;
- }
+ value = parse_assignment(argv[i]);
if (do_remove)
globalvar_remove(argv[i]);
diff --git a/commands/nv.c b/commands/nv.c
index a1cff08ee4..c60bb41677 100644
--- a/commands/nv.c
+++ b/commands/nv.c
@@ -55,13 +55,8 @@ static int do_nv(int argc, char *argv[])
for (i = 0; i < argc; i++) {
int ret;
- value = strchr(argv[i], '=');
- if (value) {
- *value = 0;
- value++;
- } else {
- value = "";
- }
+
+ value = parse_assignment(argv[i]) ?: "";
if (do_remove) {
ret = nvvar_remove(argv[i]);
diff --git a/commands/setenv.c b/commands/setenv.c
index 9aeb8f010b..99604c35c3 100644
--- a/commands/setenv.c
+++ b/commands/setenv.c
@@ -9,17 +9,15 @@
static int do_setenv(int argc, char *argv[])
{
- char *equal;
+ char *val;
int ret;
if (argc < 2)
return COMMAND_ERROR_USAGE;
- equal = strrchr(argv[1], '=');
- if (equal) {
- equal[0] = '\0';
- argv[2] = &equal[1];
- }
+ val = parse_assignment(argv[1]);
+ if (val)
+ argv[2] = val;
if (argv[2])
ret = setenv(argv[1], argv[2]);