From 2fee848b54e9b0860e31b30ecc86fbeced590fde Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 26 Aug 2018 22:04:46 +0200 Subject: Fix vputenvf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- vputenvf.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vputenvf.c b/vputenvf.c index 0d66b0c..53ddb30 100644 --- a/vputenvf.c +++ b/vputenvf.c @@ -8,7 +8,7 @@ libsimple_vputenvf(const char *fmt, va_list ap) { va_list ap2; int n; - char *s; + char *s, *p; va_copy(ap2, ap); n = vsnprintf(NULL, 0, fmt, ap2); va_end(ap2); @@ -16,7 +16,14 @@ libsimple_vputenvf(const char *fmt, va_list ap) return -1; s = alloca((size_t)n + 1); vsprintf(s, fmt, ap); - return putenv(s); + p = strchr(s, '='); + if (p) { + *p++ = '\0'; + return setenv(s, p, 1); + } else { + s = strdup(s); + return s ? putenv(s) : -1; + } } -- cgit v1.2.3-70-g09d2