summaryrefslogtreecommitdiff
path: root/env.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-19 22:26:06 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-19 22:26:06 -0400
commita9baddd7d07b9fe15e212985a808a79773ec72e4 (patch)
treefce0a089eedeacef8b25b409c2ba50f5f30a8327 /env.c
downloadlibc-testsuite-a9baddd7d07b9fe15e212985a808a79773ec72e4.tar.gz
initial check-in, taken from old libc svn repo with significant additions
Diffstat (limited to 'env.c')
-rw-r--r--env.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/env.c b/env.c
new file mode 100644
index 0000000..3214ed2
--- /dev/null
+++ b/env.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#define TEST(r, f, x, m) ( \
+((r) = (f)) == (x) || \
+(printf(__FILE__ ":%d: %s failed (" m ")\n", __LINE__, #f, r, x, strerror(errno)), err++, 0) )
+
+#define TEST_S(s, x, m) ( \
+!strcmp((s),(x)) || \
+(printf(__FILE__ ":%d: [%s] != [%s] (%s)\n", __LINE__, s, x, m), err++, 0) )
+
+extern char **environ;
+int clearenv(void);
+
+int test_env(void)
+{
+ int i;
+ int err=0;
+ char a[100], b[100], *s;
+ FILE *f;
+
+ TEST(i, (clearenv(), !environ || !*environ), 1, "failed");
+ TEST(i, putenv("TEST=1"), 0, "failed");
+ TEST(s, environ[1], 0, "%p != 0");
+ TEST_S((s=getenv("TEST")), "1", "failed");
+ TEST(i, unsetenv("TEST"), 0, "failed");
+ TEST(i, !*environ, 1, "failed");
+ TEST(i, setenv("TEST", "2", 0), 0, "failed");
+ TEST_S((s=getenv("TEST")), "2", "failed");
+ TEST(i, setenv("TEST", "3", 0), 0, "failed");
+ TEST_S((s=getenv("TEST")), "2", "failed");
+ TEST(i, setenv("TEST", "3", 1), 0, "failed");
+ TEST_S((s=getenv("TEST")), "3", "failed");
+
+ return err;
+}