|
nsz |
7308b3 |
#define _XOPEN_SOURCE 700
|
|
nsz |
7308b3 |
#include "test.h"
|
|
nsz |
7308b3 |
#include <stdlib.h>
|
|
nsz |
7308b3 |
#include <string.h>
|
|
nsz |
7308b3 |
#include <errno.h>
|
|
nsz |
7308b3 |
#include <unistd.h>
|
|
nsz |
7308b3 |
|
|
nsz |
7308b3 |
extern char **environ;
|
|
nsz |
7308b3 |
int clearenv(void);
|
|
nsz |
7308b3 |
|
|
nsz |
7308b3 |
void test_env() {
|
|
nsz |
7308b3 |
char *s;
|
|
nsz |
7308b3 |
int r;
|
|
nsz |
7308b3 |
|
|
nsz |
7308b3 |
if (clearenv() || (environ && *environ))
|
|
nsz |
7308b3 |
error("clrearenv: %s\n", strerror(errno));
|
|
nsz |
7308b3 |
if (putenv("TEST=1"))
|
|
nsz |
7308b3 |
error("putenv: %s\n", strerror(errno));
|
|
nsz |
7308b3 |
if ((s=environ[1]))
|
|
nsz |
7308b3 |
error("environ[1]: %p, wanted 0\n", s);
|
|
nsz |
7308b3 |
if (!(s=getenv("TEST")))
|
|
nsz |
7308b3 |
error("getenv(\"TEST\"): 0, wanted \"1\"\n");
|
|
nsz |
7308b3 |
if (strcmp(s,"1") != 0)
|
|
nsz |
7308b3 |
error("getenv(\"TEST\"): \"%s\", wanted \"1\"\n", s);
|
|
nsz |
7308b3 |
if (unsetenv("TEST"))
|
|
nsz |
7308b3 |
error("unsetenv: %s\n", strerror(errno));
|
|
nsz |
7308b3 |
if ((s=*environ))
|
|
nsz |
7308b3 |
error("*environ: %p != 0\n", s);
|
|
nsz |
7308b3 |
if ((s=getenv("TEST")))
|
|
nsz |
7308b3 |
error("getenv(\"TEST\"): %p, wanted 0\n", s);
|
|
nsz |
7308b3 |
if (setenv("TEST", "2", 0))
|
|
nsz |
7308b3 |
error("setenv: %s\n", strerror(errno));
|
|
nsz |
7308b3 |
if (strcmp(s=getenv("TEST"),"2") != 0)
|
|
nsz |
7308b3 |
error("getenv(\"TEST\"): \"%s\", wanted \"2\"\n", s);
|
|
nsz |
7308b3 |
if (setenv("TEST", "3", 0))
|
|
nsz |
7308b3 |
error("setenv: %s\n", strerror(errno));
|
|
nsz |
7308b3 |
if (strcmp(s=getenv("TEST"),"2") != 0)
|
|
nsz |
7308b3 |
error("getenv(\"TEST\"): \"%s\", wanted \"2\"\n", s);
|
|
nsz |
7308b3 |
if (setenv("TEST", "3", 1))
|
|
nsz |
7308b3 |
error("setenv: %s\n", strerror(errno));
|
|
nsz |
7308b3 |
if (strcmp(s=getenv("TEST"),"3") != 0)
|
|
nsz |
7308b3 |
error("getenv(\"TEST\"): \"%s\", wanted \"3\"\n", s);
|
|
nsz |
7308b3 |
if ((r=setenv("","",0)) != -1 || errno != EINVAL)
|
|
nsz |
7308b3 |
error("setenv(\"\",\"\"): %d, errno: %d (%s), wanted -1, %d (EINVAL)\n", r, errno, strerror(errno), EINVAL);
|
|
nsz |
7308b3 |
}
|