]>
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 MK |
3 | .\" |
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. | |
23 | .\" | |
24 | .\" References consulted: | |
25 | .\" Linux libc source code | |
26 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
27 | .\" 386BSD man pages | |
28 | .\" Modified Sat Jul 24 18:20:58 1993 by Rik Faith (faith@cs.unc.edu) | |
29 | .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl) | |
c11b1abf | 30 | .\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 31 | .\" Changed unsetenv() prototype; added EINVAL error |
c8f2dd47 | 32 | .\" Noted nonstandard behavior of setenv() if name contains '=' |
279d6eea | 33 | .\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug |
fea681da | 34 | .\" |
2a4b81ff | 35 | .TH SETENV 3 2009-09-20 "GNU" "Linux Programmer's Manual" |
fea681da MK |
36 | .SH NAME |
37 | setenv \- change or add an environment variable | |
38 | .SH SYNOPSIS | |
39 | .nf | |
40 | .B #include <stdlib.h> | |
41 | .sp | |
42 | .BI "int setenv(const char *" name ", const char *" value ", int " overwrite ); | |
43 | .sp | |
44 | .BI "int unsetenv(const char *" name ); | |
45 | .fi | |
cc4615cc MK |
46 | .sp |
47 | .in -4n | |
48 | Feature Test Macro Requirements for glibc (see | |
49 | .BR feature_test_macros (7)): | |
50 | .in | |
51 | .sp | |
52 | .ad l | |
53 | .BR setenv (), | |
54 | .BR unsetenv (): | |
b671fb6c | 55 | .RS 4 |
cc4615cc | 56 | _BSD_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600 |
b671fb6c | 57 | .RE |
cc4615cc | 58 | .ad b |
fea681da | 59 | .SH DESCRIPTION |
60a90ecd MK |
60 | The |
61 | .BR setenv () | |
62 | function adds the variable \fIname\fP to the | |
fea681da | 63 | environment with the value \fIvalue\fP, if \fIname\fP does not |
c13182ef MK |
64 | already exist. |
65 | If \fIname\fP does exist in the environment, then | |
c7094399 | 66 | its value is changed to \fIvalue\fP if \fIoverwrite\fP is nonzero; |
fea681da MK |
67 | if \fIoverwrite\fP is zero, then the value of \fIname\fP is not |
68 | changed. | |
f3268285 MK |
69 | This function makes copies of the strings pointed to by |
70 | .I name | |
71 | and | |
72 | .I value | |
73 | (by contrast with | |
74 | .BR putenv (3)). | |
fea681da | 75 | .PP |
60a90ecd MK |
76 | The |
77 | .BR unsetenv () | |
78 | function deletes the variable \fIname\fP from | |
fea681da | 79 | the environment. |
f3268285 MK |
80 | If |
81 | .I name | |
82 | does not exist in the environment, | |
83 | then the function succeeds, and the environment is unchanged. | |
47297adb | 84 | .SH RETURN VALUE |
60a90ecd MK |
85 | The |
86 | .BR setenv () | |
2a4b81ff MK |
87 | function returns zero on success, |
88 | or \-1 on error, with | |
89 | .I errno | |
90 | set to indicate the cause of the error. | |
f3268285 | 91 | |
60a90ecd MK |
92 | The |
93 | .BR unsetenv () | |
94 | function returns zero on success, | |
fea681da MK |
95 | or \-1 on error, with |
96 | .I errno | |
97 | set to indicate the cause of the error. | |
47297adb | 98 | .SH ERRORS |
fea681da MK |
99 | .TP |
100 | .B EINVAL | |
101 | .I name | |
2a4b81ff MK |
102 | is NULL, points to a string of length 0, |
103 | or contains an \(aq=\(aq character. | |
104 | .TP | |
105 | .B ENOMEM | |
106 | Insufficient memory to add a new variable to the environment. | |
47297adb | 107 | .SH CONFORMING TO |
68e1685c | 108 | 4.3BSD, POSIX.1-2001. |
47297adb | 109 | .SH NOTES |
f3268285 MK |
110 | POSIX.1-2001 does not require |
111 | .BR setenv () | |
112 | or | |
113 | .BR unsetenv () | |
114 | to be reentrant. | |
115 | ||
60a90ecd MK |
116 | Prior to glibc 2.2.2, |
117 | .BR unsetenv () | |
118 | was prototyped | |
fea681da | 119 | as returning \fIvoid\fP; more recent glibc versions follow the |
68e1685c | 120 | POSIX.1-2001-compliant prototype shown in the SYNOPSIS. |
fea681da | 121 | .SH BUGS |
68e1685c | 122 | POSIX.1-2001 specifies that if |
fea681da | 123 | .I name |
f81fb444 | 124 | contains an \(aq=\(aq character, then |
fea681da MK |
125 | .BR setenv () |
126 | should fail with the error | |
127 | .BR EINVAL ; | |
f81fb444 | 128 | however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in |
fea681da | 129 | .IR name . |
47297adb | 130 | .SH SEE ALSO |
fea681da MK |
131 | .BR clearenv (3), |
132 | .BR getenv (3), | |
133 | .BR putenv (3), | |
aa949e2d | 134 | .BR environ (7) |