repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / tests / system / libroot / posix / clearenv.cpp
blobc7c29e0a151b1b0e585a6e65f55d5b0cc29f77a6
1 /*
2 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <stdio.h>
8 #include <stdlib.h>
11 int gTestNr;
14 void
15 set_env()
17 gTestNr++;
18 printf("Test %d...\n", gTestNr);
20 if (setenv("TEST_VARIABLE", "42", true) != 0)
21 fprintf(stderr, "Test %d: setting variable failed!\n", gTestNr);
25 void
26 test_env()
28 if (getenv("TEST_VARIABLE") != NULL)
29 fprintf(stderr, "Test %d: not cleared!\n", gTestNr);
30 if (setenv("OTHER_VARIABLE", "test", true) != 0)
31 fprintf(stderr, "Test %d: setting other failed!\n", gTestNr);
35 int
36 main(int argc, char** argv)
38 set_env();
39 environ = NULL;
40 test_env();
42 set_env();
43 environ[0] = NULL;
44 test_env();
46 static char* emptyEnv[1] = {NULL};
47 set_env();
48 environ = emptyEnv;
49 test_env();
51 set_env();
52 environ = (char**)calloc(1, sizeof(*environ));
53 test_env();
55 // clearenv() is not part of the POSIX specs
56 #if 1
57 set_env();
58 clearenv();
59 test_env();
60 #endif
62 return 0;