diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2020-11-12 18:23:47 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-11-23 16:48:12 +0100 |
commit | 656a6f0e97770bb8a2a1a76734a87abbbeff7d56 (patch) | |
tree | 2565bf7019c5c9f7288035acaa62d5b9b3d51a6d | |
parent | 51178d4979c9caeef95d616dcd3d47bdcd81a58e (diff) | |
download | barebox-656a6f0e97770bb8a2a1a76734a87abbbeff7d56.tar.gz barebox-656a6f0e97770bb8a2a1a76734a87abbbeff7d56.tar.xz |
setenv: align with POSIX in handling of setenv(var, "")
setenv(var, "") to delete var is a barebox idiosyncrasy. Previous commit
added unsetenv and changed all users of setenv(var, ""), so lets set the
behavior of setenv to what's expected: set var to the empty string.
Previously, "" was turned into NULL, which meant it wasn't possible to
set variables to the empty string from the shell. This is now possible.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | commands/setenv.c | 3 | ||||
-rw-r--r-- | common/env.c | 12 |
2 files changed, 10 insertions, 5 deletions
diff --git a/commands/setenv.c b/commands/setenv.c index 6992f604f5..9aeb8f010b 100644 --- a/commands/setenv.c +++ b/commands/setenv.c @@ -18,8 +18,7 @@ static int do_setenv(int argc, char *argv[]) equal = strrchr(argv[1], '='); if (equal) { equal[0] = '\0'; - if (equal[1]) - argv[2] = &equal[1]; + argv[2] = &equal[1]; } if (argv[2]) diff --git a/common/env.c b/common/env.c index fbaaac4f2f..2830551bc0 100644 --- a/common/env.c +++ b/common/env.c @@ -251,15 +251,21 @@ static int dev_setenv(const char *name, const char *val) return -ENODEV; } +/** + * setenv - set environment variables + * @_name - Variable name + * @value - the value to set, empty string not handled specially + * + * Returns 0 for success and a negative error code otherwise + * Use unsetenv() to unset. + */ + int setenv(const char *_name, const char *value) { char *name = strdup(_name); int ret = 0; struct list_head *list; - if (value && !*value) - value = NULL; - if (strchr(name, '.')) { ret = dev_setenv(name, value); if (ret) |