aboutsummaryrefslogtreecommitdiffstats
path: root/vputenvf.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-26 22:04:46 +0200
committerMattias Andrée <maandree@kth.se>2018-08-26 22:04:46 +0200
commit2fee848b54e9b0860e31b30ecc86fbeced590fde (patch)
tree5fca49d730d4f944e6f33534373bf40f571f4c58 /vputenvf.c
parentm + add tests (diff)
downloadlibsimple-2fee848b54e9b0860e31b30ecc86fbeced590fde.tar.gz
libsimple-2fee848b54e9b0860e31b30ecc86fbeced590fde.tar.bz2
libsimple-2fee848b54e9b0860e31b30ecc86fbeced590fde.tar.xz
Fix vputenvf
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'vputenvf.c')
-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;
+ }
}