[PATCH 2/2] setenv: align with POSIX in handling of setenv(var, "")

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Nov 12 12:23:47 EST 2020


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 at pengutronix.de>
---
 common/env.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/common/env.c b/common/env.c
index fbaaac4f2f5c..2830551bc0a1 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)
-- 
2.28.0




More information about the barebox mailing list