]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/setenv.3
proc.5: Note kernel version for /proc/PID/smaps VmFlags "wf" flag
[thirdparty/man-pages.git] / man3 / setenv.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2004, 2007 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
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.
13 .\"
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.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
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)
32 .\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Changed unsetenv() prototype; added EINVAL error
34 .\" Noted nonstandard behavior of setenv() if name contains '='
35 .\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug
36 .\"
37 .TH SETENV 3 2017-09-15 "GNU" "Linux Programmer's Manual"
38 .SH NAME
39 setenv \- change or add an environment variable
40 .SH SYNOPSIS
41 .nf
42 .B #include <stdlib.h>
43 .PP
44 .BI "int setenv(const char *" name ", const char *" value ", int " overwrite );
45 .PP
46 .BI "int unsetenv(const char *" name );
47 .fi
48 .PP
49 .in -4n
50 Feature Test Macro Requirements for glibc (see
51 .BR feature_test_macros (7)):
52 .in
53 .PP
54 .ad l
55 .BR setenv (),
56 .BR unsetenv ():
57 .RS 4
58 _POSIX_C_SOURCE\ >=\ 200112L
59 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
60 .RE
61 .ad b
62 .SH DESCRIPTION
63 The
64 .BR setenv ()
65 function adds the variable
66 .I name
67 to the
68 environment with the value
69 .IR value ,
70 if
71 .I name
72 does not
73 already exist.
74 If
75 .I name
76 does exist in the environment, then
77 its value is changed to
78 .IR value
79 if
80 .I overwrite
81 is nonzero;
82 if
83 .IR overwrite
84 is zero, then the value of
85 .I name
86 is not changed (and
87 .BR setenv ()
88 returns a success status).
89 This function makes copies of the strings pointed to by
90 .I name
91 and
92 .I value
93 (by contrast with
94 .BR putenv (3)).
95 .PP
96 The
97 .BR unsetenv ()
98 function deletes the variable
99 .I name
100 from
101 the environment.
102 If
103 .I name
104 does not exist in the environment,
105 then the function succeeds, and the environment is unchanged.
106 .SH RETURN VALUE
107 .BR setenv ()
108 and
109 .BR unsetenv ()
110 functions return zero on success,
111 or \-1 on error, with
112 .I errno
113 set to indicate the cause of the error.
114 .SH ERRORS
115 .TP
116 .B EINVAL
117 .I name
118 is NULL, points to a string of length 0,
119 or contains an \(aq=\(aq character.
120 .TP
121 .B ENOMEM
122 Insufficient memory to add a new variable to the environment.
123 .SH ATTRIBUTES
124 For an explanation of the terms used in this section, see
125 .BR attributes (7).
126 .ad l
127 .TS
128 allbox;
129 lb lb lb
130 l l l.
131 Interface Attribute Value
132 T{
133 .BR setenv (),
134 .BR unsetenv ()
135 T} Thread safety MT-Unsafe const:env
136 .TE
137 .ad
138 .SH CONFORMING TO
139 POSIX.1-2001, POSIX.1-2008, 4.3BSD.
140 .SH NOTES
141 POSIX.1 does not require
142 .BR setenv ()
143 or
144 .BR unsetenv ()
145 to be reentrant.
146 .PP
147 Prior to glibc 2.2.2,
148 .BR unsetenv ()
149 was prototyped
150 as returning
151 .IR void ;
152 more recent glibc versions follow the
153 POSIX.1-compliant prototype shown in the SYNOPSIS.
154 .SH BUGS
155 POSIX.1 specifies that if
156 .I name
157 contains an \(aq=\(aq character, then
158 .BR setenv ()
159 should fail with the error
160 .BR EINVAL ;
161 however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in
162 .IR name .
163 .SH SEE ALSO
164 .BR clearenv (3),
165 .BR getenv (3),
166 .BR putenv (3),
167 .BR environ (7)