mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] setenv: align with POSIX in handling of setenv(var, "")
Date: Thu, 12 Nov 2020 18:23:47 +0100	[thread overview]
Message-ID: <20201112172347.385-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20201112172347.385-1-a.fatoum@pengutronix.de>

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>
---
 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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-11-12 17:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 17:23 [PATCH 1/2] fs: introduce unsetenv() to prepare for changing setenv(var, "") behavior Ahmad Fatoum
2020-11-12 17:23 ` Ahmad Fatoum [this message]
2020-11-13  8:26   ` [PATCH] fixup! setenv: align with POSIX in handling of setenv(var, "") Ahmad Fatoum
2020-11-16  8:21     ` Sascha Hauer
2020-11-16  8:58       ` Ahmad Fatoum
2020-11-23 15:48 ` [PATCH 1/2] fs: introduce unsetenv() to prepare for changing setenv(var, "") behavior Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201112172347.385-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox