]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
f3268285 | 2 | .\" and Copyright (C) 2004, 2007 Michael kerrisk <mtk.manpages@gmail.com> |
fea681da | 3 | .\" |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
5 | .\" Permission is granted to make and distribute verbatim copies of this |
6 | .\" manual provided the copyright notice and this permission notice are | |
7 | .\" preserved on all copies. | |
8 | .\" | |
9 | .\" Permission is granted to copy and distribute modified versions of this | |
10 | .\" manual under the conditions for verbatim copying, provided that the | |
11 | .\" entire resulting derived work is distributed under the terms of a | |
12 | .\" permission notice identical to this one. | |
c13182ef | 13 | .\" |
fea681da MK |
14 | .\" Since the Linux kernel and libraries are constantly changing, this |
15 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
16 | .\" responsibility for errors or omissions, or for damages resulting from | |
17 | .\" the use of the information contained herein. The author(s) may not | |
18 | .\" have taken the same level of care in the production of this manual, | |
19 | .\" which is licensed free of charge, as they might when working | |
20 | .\" professionally. | |
c13182ef | 21 | .\" |
fea681da MK |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
fea681da MK |
25 | .\" |
26 | .\" References consulted: | |
27 | .\" Linux libc source code | |
28 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
29 | .\" 386BSD man pages | |
30 | .\" Modified Sat Jul 24 18:20:58 1993 by Rik Faith (faith@cs.unc.edu) | |
31 | .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl) | |
c11b1abf | 32 | .\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 33 | .\" Changed unsetenv() prototype; added EINVAL error |
c8f2dd47 | 34 | .\" Noted nonstandard behavior of setenv() if name contains '=' |
279d6eea | 35 | .\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug |
fea681da | 36 | .\" |
2a4b81ff | 37 | .TH SETENV 3 2009-09-20 "GNU" "Linux Programmer's Manual" |
fea681da MK |
38 | .SH NAME |
39 | setenv \- change or add an environment variable | |
40 | .SH SYNOPSIS | |
41 | .nf | |
42 | .B #include <stdlib.h> | |
43 | .sp | |
44 | .BI "int setenv(const char *" name ", const char *" value ", int " overwrite ); | |
45 | .sp | |
46 | .BI "int unsetenv(const char *" name ); | |
47 | .fi | |
cc4615cc MK |
48 | .sp |
49 | .in -4n | |
50 | Feature Test Macro Requirements for glibc (see | |
51 | .BR feature_test_macros (7)): | |
52 | .in | |
53 | .sp | |
54 | .ad l | |
55 | .BR setenv (), | |
56 | .BR unsetenv (): | |
b671fb6c | 57 | .RS 4 |
cc4615cc | 58 | _BSD_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600 |
b671fb6c | 59 | .RE |
cc4615cc | 60 | .ad b |
fea681da | 61 | .SH DESCRIPTION |
60a90ecd MK |
62 | The |
63 | .BR setenv () | |
c6fa0841 MK |
64 | function adds the variable |
65 | .I name | |
66 | to the | |
67 | environment with the value | |
68 | .IR value , | |
69 | if | |
70 | .I name | |
71 | does not | |
c13182ef | 72 | already exist. |
c6fa0841 MK |
73 | If |
74 | .I name | |
75 | does exist in the environment, then | |
76 | its value is changed to | |
51700fd7 | 77 | .IR value |
c6fa0841 MK |
78 | if |
79 | .I overwrite | |
80 | is nonzero; | |
81 | if | |
51700fd7 | 82 | .IR overwrite |
c6fa0841 MK |
83 | is zero, then the value of |
84 | .I name | |
85 | is not | |
fea681da | 86 | changed. |
f3268285 MK |
87 | This function makes copies of the strings pointed to by |
88 | .I name | |
89 | and | |
90 | .I value | |
91 | (by contrast with | |
92 | .BR putenv (3)). | |
fea681da | 93 | .PP |
60a90ecd MK |
94 | The |
95 | .BR unsetenv () | |
c6fa0841 MK |
96 | function deletes the variable |
97 | .I name | |
98 | from | |
fea681da | 99 | the environment. |
f3268285 MK |
100 | If |
101 | .I name | |
102 | does not exist in the environment, | |
103 | then the function succeeds, and the environment is unchanged. | |
47297adb | 104 | .SH RETURN VALUE |
60a90ecd MK |
105 | The |
106 | .BR setenv () | |
2a4b81ff MK |
107 | function returns zero on success, |
108 | or \-1 on error, with | |
109 | .I errno | |
110 | set to indicate the cause of the error. | |
f3268285 | 111 | |
60a90ecd MK |
112 | The |
113 | .BR unsetenv () | |
114 | function returns zero on success, | |
fea681da MK |
115 | or \-1 on error, with |
116 | .I errno | |
117 | set to indicate the cause of the error. | |
47297adb | 118 | .SH ERRORS |
fea681da MK |
119 | .TP |
120 | .B EINVAL | |
121 | .I name | |
2a4b81ff MK |
122 | is NULL, points to a string of length 0, |
123 | or contains an \(aq=\(aq character. | |
124 | .TP | |
125 | .B ENOMEM | |
126 | Insufficient memory to add a new variable to the environment. | |
47297adb | 127 | .SH CONFORMING TO |
68e1685c | 128 | 4.3BSD, POSIX.1-2001. |
47297adb | 129 | .SH NOTES |
f3268285 MK |
130 | POSIX.1-2001 does not require |
131 | .BR setenv () | |
132 | or | |
133 | .BR unsetenv () | |
134 | to be reentrant. | |
135 | ||
60a90ecd MK |
136 | Prior to glibc 2.2.2, |
137 | .BR unsetenv () | |
138 | was prototyped | |
c6fa0841 MK |
139 | as returning |
140 | .IR void ; | |
141 | more recent glibc versions follow the | |
68e1685c | 142 | POSIX.1-2001-compliant prototype shown in the SYNOPSIS. |
fea681da | 143 | .SH BUGS |
68e1685c | 144 | POSIX.1-2001 specifies that if |
fea681da | 145 | .I name |
f81fb444 | 146 | contains an \(aq=\(aq character, then |
fea681da MK |
147 | .BR setenv () |
148 | should fail with the error | |
149 | .BR EINVAL ; | |
f81fb444 | 150 | however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in |
fea681da | 151 | .IR name . |
47297adb | 152 | .SH SEE ALSO |
fea681da MK |
153 | .BR clearenv (3), |
154 | .BR getenv (3), | |
155 | .BR putenv (3), | |
aa949e2d | 156 | .BR environ (7) |