]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
31cc8387 | 2 | .\" and Copyright (C) 2004, 2007 Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 3 | .\" |
5fbde956 | 4 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
5 | .\" |
6 | .\" References consulted: | |
7 | .\" Linux libc source code | |
8 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
9 | .\" 386BSD man pages | |
10 | .\" Modified Sat Jul 24 18:20:58 1993 by Rik Faith (faith@cs.unc.edu) | |
11 | .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl) | |
c11b1abf | 12 | .\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 13 | .\" Changed unsetenv() prototype; added EINVAL error |
c8f2dd47 | 14 | .\" Noted nonstandard behavior of setenv() if name contains '=' |
279d6eea | 15 | .\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug |
fea681da | 16 | .\" |
45186a5d | 17 | .TH SETENV 3 2021-03-22 "Linux man-pages (unreleased)" |
fea681da MK |
18 | .SH NAME |
19 | setenv \- change or add an environment variable | |
09672b8d AC |
20 | .SH LIBRARY |
21 | Standard C library | |
8fc3b2cf | 22 | .RI ( libc ", " \-lc ) |
fea681da MK |
23 | .SH SYNOPSIS |
24 | .nf | |
25 | .B #include <stdlib.h> | |
68e4db0a | 26 | .PP |
fea681da | 27 | .BI "int setenv(const char *" name ", const char *" value ", int " overwrite ); |
fea681da MK |
28 | .BI "int unsetenv(const char *" name ); |
29 | .fi | |
68e4db0a | 30 | .PP |
d39ad78f | 31 | .RS -4 |
cc4615cc MK |
32 | Feature Test Macro Requirements for glibc (see |
33 | .BR feature_test_macros (7)): | |
d39ad78f | 34 | .RE |
68e4db0a | 35 | .PP |
cc4615cc MK |
36 | .BR setenv (), |
37 | .BR unsetenv (): | |
9d2adbae | 38 | .nf |
5c10d2c5 | 39 | _POSIX_C_SOURCE >= 200112L |
9d2adbae MK |
40 | || /* Glibc <= 2.19: */ _BSD_SOURCE |
41 | .fi | |
fea681da | 42 | .SH DESCRIPTION |
60a90ecd MK |
43 | The |
44 | .BR setenv () | |
c6fa0841 MK |
45 | function adds the variable |
46 | .I name | |
47 | to the | |
48 | environment with the value | |
49 | .IR value , | |
50 | if | |
51 | .I name | |
52 | does not | |
c13182ef | 53 | already exist. |
c6fa0841 MK |
54 | If |
55 | .I name | |
56 | does exist in the environment, then | |
57 | its value is changed to | |
1ae6b2c7 | 58 | .I value |
c6fa0841 MK |
59 | if |
60 | .I overwrite | |
61 | is nonzero; | |
62 | if | |
1ae6b2c7 | 63 | .I overwrite |
c6fa0841 MK |
64 | is zero, then the value of |
65 | .I name | |
779e42d0 MK |
66 | is not changed (and |
67 | .BR setenv () | |
68 | returns a success status). | |
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 () | |
c6fa0841 MK |
78 | function deletes the variable |
79 | .I name | |
80 | from | |
fea681da | 81 | the environment. |
f3268285 MK |
82 | If |
83 | .I name | |
84 | does not exist in the environment, | |
85 | then the function succeeds, and the environment is unchanged. | |
47297adb | 86 | .SH RETURN VALUE |
60a90ecd | 87 | .BR setenv () |
483368b3 | 88 | and |
60a90ecd | 89 | .BR unsetenv () |
483368b3 | 90 | functions return zero on success, |
fea681da MK |
91 | or \-1 on error, with |
92 | .I errno | |
855d489a | 93 | set to indicate the error. |
47297adb | 94 | .SH ERRORS |
fea681da MK |
95 | .TP |
96 | .B EINVAL | |
97 | .I name | |
2a4b81ff MK |
98 | is NULL, points to a string of length 0, |
99 | or contains an \(aq=\(aq character. | |
100 | .TP | |
101 | .B ENOMEM | |
102 | Insufficient memory to add a new variable to the environment. | |
6d682990 MS |
103 | .SH ATTRIBUTES |
104 | For an explanation of the terms used in this section, see | |
105 | .BR attributes (7). | |
74714ea8 | 106 | .ad l |
c466875e | 107 | .nh |
6d682990 MS |
108 | .TS |
109 | allbox; | |
c466875e | 110 | lbx lb lb |
6d682990 MS |
111 | l l l. |
112 | Interface Attribute Value | |
113 | T{ | |
114 | .BR setenv (), | |
115 | .BR unsetenv () | |
116 | T} Thread safety MT-Unsafe const:env | |
117 | .TE | |
c466875e | 118 | .hy |
74714ea8 | 119 | .ad |
c466875e | 120 | .sp 1 |
3113c7f3 | 121 | .SH STANDARDS |
246d0d44 | 122 | POSIX.1-2001, POSIX.1-2008, 4.3BSD. |
47297adb | 123 | .SH NOTES |
246d0d44 | 124 | POSIX.1 does not require |
f3268285 MK |
125 | .BR setenv () |
126 | or | |
127 | .BR unsetenv () | |
128 | to be reentrant. | |
847e0d88 | 129 | .PP |
60a90ecd MK |
130 | Prior to glibc 2.2.2, |
131 | .BR unsetenv () | |
132 | was prototyped | |
c6fa0841 MK |
133 | as returning |
134 | .IR void ; | |
135 | more recent glibc versions follow the | |
246d0d44 | 136 | POSIX.1-compliant prototype shown in the SYNOPSIS. |
fea681da | 137 | .SH BUGS |
246d0d44 | 138 | POSIX.1 specifies that if |
fea681da | 139 | .I name |
f81fb444 | 140 | contains an \(aq=\(aq character, then |
fea681da MK |
141 | .BR setenv () |
142 | should fail with the error | |
143 | .BR EINVAL ; | |
f81fb444 | 144 | however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in |
fea681da | 145 | .IR name . |
47297adb | 146 | .SH SEE ALSO |
fea681da MK |
147 | .BR clearenv (3), |
148 | .BR getenv (3), | |
149 | .BR putenv (3), | |
aa949e2d | 150 | .BR environ (7) |