File: src.c

package info (click to toggle)
emscripten 2.0.12~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 108,440 kB
  • sloc: ansic: 510,324; cpp: 384,763; javascript: 84,341; python: 51,362; sh: 50,019; pascal: 4,159; makefile: 3,409; asm: 2,150; lisp: 1,869; ruby: 488; cs: 142
file content (49 lines) | stat: -rw-r--r-- 1,782 bytes parent folder | download | duplicates (2)
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;
}