aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vputenvf.c11
1 files 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;
+ }
}