diff options
Diffstat (limited to '')
-rw-r--r-- | vputenvf.c | 39 |
1 files changed, 34 insertions, 5 deletions
@@ -1,9 +1,10 @@ /* See LICENSE file for copyright and license details. */ #include "libsimple.h" +#ifndef TEST int -libsimple_vputenvf(const char *fmt, va_list ap) /* TODO test */ +libsimple_vputenvf(const char *fmt, va_list ap) { va_list ap2; int n; @@ -13,11 +14,39 @@ libsimple_vputenvf(const char *fmt, va_list ap) /* TODO test */ va_end(ap2); if (n < 0) return -1; - if ((size_t)n == SIZE_MAX) { - errno = ENOMEM; - return -1; - } s = alloca((size_t)n + 1); vsprintf(s, fmt, ap); return putenv(s); } + + +#else +#include "test.h" + +int +main(void) +{ + unsetenv("X"); + assert(!getenv("X")); + unsetenv("Y"); + assert(!getenv("Y")); + + putenvf("X=xyz"); + assert(!strcmpnul(getenv("X"), "xyz")); + putenvf("Y=xyz"); + assert(!strcmpnul(getenv("Y"), "xyz")); + + putenvf("X=x%sz", "abc"); + assert(!strcmpnul(getenv("X"), "xabcz")); + putenvf("Y=x%sz", "abc"); + assert(!strcmpnul(getenv("Y"), "xabcz")); + + putenvf("X=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("X"), "10xabcz-11")); + putenvf("Y=%ix%sz%i", 10, "abc", -11); + assert(!strcmpnul(getenv("Y"), "10xabcz-11")); + + return 0; +} + +#endif |