]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" References consulted: | |
26 | .\" Linux libc source code | |
27 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
28 | .\" 386BSD man pages | |
29 | .\" Single UNIX Specification, Version 2 | |
30 | .\" Modified Thu Apr 8 15:00:12 1993, David Metcalfe | |
31 | .\" Modified Sat Jul 24 18:44:45 1993, Rik Faith (faith@cs.unc.edu) | |
32 | .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl) | |
33 | .\" Modified Mon Oct 11 11:11:11 1999 by Andries Brouwer (aeb@cwi.nl) | |
34 | .\" Modified Wed Nov 10 00:02:26 1999 by Andries Brouwer (aeb@cwi.nl) | |
35 | .\" Modified Sun May 20 22:17:20 2001 by Andries Brouwer (aeb@cwi.nl) | |
97986708 | 36 | .TH PUTENV 3 2016-03-15 "GNU" "Linux Programmer's Manual" |
fea681da MK |
37 | .SH NAME |
38 | putenv \- change or add an environment variable | |
39 | .SH SYNOPSIS | |
40 | .nf | |
41 | .B #include <stdlib.h> | |
68e4db0a | 42 | .PP |
fea681da MK |
43 | .BI "int putenv(char *" string ); |
44 | .\" Not: const char * | |
45 | .fi | |
68e4db0a | 46 | .PP |
cc4615cc MK |
47 | .in -4n |
48 | Feature Test Macro Requirements for glibc (see | |
49 | .BR feature_test_macros (7)): | |
50 | .in | |
68e4db0a | 51 | .PP |
cc4615cc | 52 | .BR putenv (): |
2b1b0424 MK |
53 | _XOPEN_SOURCE |
54 | || /* Glibc since 2.19: */ _DEFAULT_SOURCE | |
55 | || /* Glibc versions <= 2.19: */ _SVID_SOURCE | |
fea681da | 56 | .SH DESCRIPTION |
60a90ecd MK |
57 | The |
58 | .BR putenv () | |
59 | function adds or changes the value of environment | |
c13182ef MK |
60 | variables. |
61 | The argument \fIstring\fP is of the form \fIname\fP=\fIvalue\fP. | |
62 | If \fIname\fP does not already exist in the environment, then | |
63 | \fIstring\fP is added to the environment. | |
64 | If \fIname\fP does exist, | |
65 | then the value of \fIname\fP in the environment is changed to | |
fea681da MK |
66 | \fIvalue\fP. |
67 | The string pointed to by \fIstring\fP becomes part of the environment, | |
68 | so altering the string changes the environment. | |
47297adb | 69 | .SH RETURN VALUE |
60a90ecd MK |
70 | The |
71 | .BR putenv () | |
72 | function returns zero on success, | |
c7094399 | 73 | or nonzero if an error occurs. |
fbe1845c MK |
74 | In the event of an error, |
75 | .I errno | |
76 | is set to indicate the cause. | |
fea681da MK |
77 | .SH ERRORS |
78 | .TP | |
79 | .B ENOMEM | |
80 | Insufficient space to allocate new environment. | |
e3b91e1e MS |
81 | .SH ATTRIBUTES |
82 | For an explanation of the terms used in this section, see | |
83 | .BR attributes (7). | |
84 | .TS | |
85 | allbox; | |
86 | lb lb lb | |
87 | l l l. | |
88 | Interface Attribute Value | |
89 | T{ | |
90 | .BR putenv () | |
91 | T} Thread safety MT-Unsafe const:env | |
92 | .TE | |
47297adb | 93 | .SH CONFORMING TO |
4490b764 | 94 | POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD. |
fea681da | 95 | .SH NOTES |
60a90ecd MK |
96 | The |
97 | .BR putenv () | |
98 | function is not required to be reentrant, and the | |
09d8ec93 | 99 | one in glibc 2.0 is not, but the glibc 2.1 version is. |
99c4073b MK |
100 | .\" .LP |
101 | .\" Description for libc4, libc5, glibc: | |
102 | .\" If the argument \fIstring\fP is of the form \fIname\fP, | |
103 | .\" and does not contain an \(aq=\(aq character, then the variable \fIname\fP | |
104 | .\" is removed from the environment. | |
105 | .\" If | |
106 | .\" .BR putenv () | |
107 | .\" has to allocate a new array \fIenviron\fP, | |
108 | .\" and the previous array was also allocated by | |
109 | .\" .BR putenv (), | |
110 | .\" then it will be freed. | |
111 | .\" In no case will the old storage associated | |
112 | .\" to the environment variable itself be freed. | |
dd3568a1 | 113 | .PP |
165b9638 | 114 | Since version 2.1.2, the glibc implementation conforms to SUSv2: |
60a90ecd MK |
115 | the pointer \fIstring\fP given to |
116 | .BR putenv () | |
117 | is used. | |
fea681da MK |
118 | In particular, this string becomes part of the environment; |
119 | changing it later will change the environment. | |
65c3312c | 120 | (Thus, it is an error to call |
60a90ecd MK |
121 | .BR putenv () |
122 | with an automatic variable | |
fea681da MK |
123 | as the argument, then return from the calling function while \fIstring\fP |
124 | is still part of the environment.) | |
165b9638 | 125 | However, glibc versions 2.0 to 2.1.1 differ: a copy of the string is used. |
fea681da | 126 | On the one hand this causes a memory leak, and on the other hand |
c13182ef | 127 | it violates SUSv2. |
dd3568a1 | 128 | .PP |
b14d4aa5 | 129 | The 4.4BSD version, like glibc 2.0, uses a copy. |
dd3568a1 | 130 | .PP |
2b0fa182 | 131 | SUSv2 removes the \fIconst\fP from the prototype, and so does glibc 2.1.3. |
73700225 MK |
132 | .PP |
133 | The GNU C library implementation provides a nonstandard extension. | |
134 | If | |
135 | .I string | |
136 | does not include an equal sign: | |
137 | .PP | |
138 | .in +4n | |
139 | .EX | |
140 | putenv("NAME"); | |
141 | .EE | |
142 | .in | |
143 | .PP | |
144 | then the named variable is removed from the caller's environment. | |
47297adb | 145 | .SH SEE ALSO |
fea681da MK |
146 | .BR clearenv (3), |
147 | .BR getenv (3), | |
148 | .BR setenv (3), | |
149 | .BR unsetenv (3), | |
aa949e2d | 150 | .BR environ (7) |