diff options
author | Mattias Andrée <maandree@kth.se> | 2018-08-26 22:04:46 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-08-26 22:04:46 +0200 |
commit | 2fee848b54e9b0860e31b30ecc86fbeced590fde (patch) | |
tree | 5fca49d730d4f944e6f33534373bf40f571f4c58 /vputenvf.c | |
parent | m + add tests (diff) | |
download | libsimple-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.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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; + } } |