1putenv(3C) Standard C Library Functions putenv(3C)
2
3
4
6 putenv - change or add value to environment
7
9 #include <stdlib.h>
10
11 int putenv(char *string);
12
13
15 The putenv() function makes the value of the environment variable name
16 equal to value by altering an existing variable or creating a new one.
17 In either case, the string pointed to by string becomes part of the
18 environment, so altering the string will change the environment.
19
20
21 The string argument points to a string of the form name=value. The
22 space used by string is no longer used once a new string-defining name
23 is passed to putenv().
24
25
26 The putenv() function uses malloc(3C) to enlarge the environment.
27
28
29 After putenv() is called, environment variables are not in alphabetical
30 order.
31
33 Upon successful completion, putenv() returns 0. Otherwise, it returns a
34 non-zero value and sets errno to indicate the error.
35
37 The putenv() function may fail if:
38
39 ENOMEM Insufficient memory was available.
40
41
43 The putenv() function can be safely called from multithreaded programs.
44 Caution must be exercised when using this function and getenv(3C) in
45 multithreaded programs. These functions examine and modify the environ‐
46 ment list, which is shared by all threads in a program. The system
47 prevents the list from being accessed simultaneously by two different
48 threads. It does not, however, prevent two threads from successively
49 accessing the environment list using putenv() or getenv().
50
52 See attributes(5) for descriptions of the following attributes:
53
54
55
56
57 ┌─────────────────────────────┬─────────────────────────────┐
58 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
59 ├─────────────────────────────┼─────────────────────────────┤
60 │Interface Stability │Standard │
61 ├─────────────────────────────┼─────────────────────────────┤
62 │MT-Level │Safe │
63 └─────────────────────────────┴─────────────────────────────┘
64
66 exec(2), getenv(3C), malloc(3C), attributes(5), environ(5), stan‐
67 dards(5)
68
70 The string argument should not be an automatic variable. It should be
71 declared static if it is declared within a function because it cannot
72 be automatically declared. A potential error is to call putenv() with a
73 pointer to an automatic variable as the argument and to then exit the
74 calling function while string is still part of the environment.
75
76
77
78SunOS 5.11 7 Aug 2004 putenv(3C)