forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc.c
More file actions
49 lines (40 loc) · 1.74 KB
/
src.c
File metadata and controls
49 lines (40 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright 2011 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
printf("List:\n");
for (char** str = environ; *str; str++) {
printf("%s\n", *str);
}
printf("\n");
printf("getenv(PATH): %s\n", getenv("PATH"));
printf("getenv(NONEXISTENT): %s\n", getenv("NONEXISTENT"));
printf("setenv/0(PATH) ret: %d\n", setenv("PATH", "test", 0));
printf("getenv(PATH) after setenv/0: %s\n", getenv("PATH"));
printf("setenv/1(PATH) ret: %d\n", setenv("PATH", "test2", 1));
printf("getenv(PATH) after setenv/1: %s\n", getenv("PATH"));
printf("setenv(SET_VALUE) ret: %d\n", setenv("SET_VALUE", "test3", 0));
printf("setenv(SET_VALUE2) ret: %d\n", setenv("SET_VALUE2", "test4", 1));
printf("getenv(SET_VALUE): %s\n", getenv("SET_VALUE"));
printf("getenv(SET_VALUE2): %s\n", getenv("SET_VALUE2"));
char buffer[] = "PUT_VALUE=test5";
printf("putenv(PUT_VALUE) ret: %d\n", putenv(buffer));
printf("getenv(PUT_VALUE): %s\n", getenv("PUT_VALUE"));
buffer[10] = 'Q';
printf("getenv(PUT_VALUE) after alteration: %s\n", getenv("PUT_VALUE"));
printf("unsetenv(PUT_VALUE) ret: %d\n", unsetenv("PUT_VALUE"));
printf("getenv(PUT_VALUE) after unsetenv: %s\n", getenv("PUT_VALUE"));
printf("setenv(0) ret: %d\n", setenv(0, "foo", 1));
printf("setenv('') ret: %d\n", setenv("", "foo", 1));
printf("setenv(X=Y) ret: %d\n", setenv("X=Y", "foo", 1));
printf("unsetenv('') ret: %d\n", unsetenv(""));
printf("unsetenv(X=Y) ret: %d\n", unsetenv("X=Y"));
return 0;
}