summaryrefslogtreecommitdiff
path: root/common/env.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-11-12 18:23:47 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-11-23 16:48:12 +0100
commit656a6f0e97770bb8a2a1a76734a87abbbeff7d56 (patch)
tree2565bf7019c5c9f7288035acaa62d5b9b3d51a6d /common/env.c
parent51178d4979c9caeef95d616dcd3d47bdcd81a58e (diff)
downloadbarebox-656a6f0e97770bb8a2a1a76734a87abbbeff7d56.tar.gz
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>
Diffstat (limited to 'common/env.c')
-rw-r--r--common/env.c12
1 files changed, 9 insertions, 3 deletions
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)