]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setenv.3
ctime.3: wfix
[thirdparty/man-pages.git] / man3 / setenv.3
CommitLineData
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.\"
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.\"
4b8c67d9 37.TH SETENV 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
38.SH NAME
39setenv \- change or add an environment variable
40.SH SYNOPSIS
41.nf
42.B #include <stdlib.h>
68e4db0a 43.PP
fea681da 44.BI "int setenv(const char *" name ", const char *" value ", int " overwrite );
68e4db0a 45.PP
fea681da
MK
46.BI "int unsetenv(const char *" name );
47.fi
68e4db0a 48.PP
cc4615cc
MK
49.in -4n
50Feature Test Macro Requirements for glibc (see
51.BR feature_test_macros (7)):
52.in
68e4db0a 53.PP
cc4615cc
MK
54.ad l
55.BR setenv (),
56.BR unsetenv ():
b671fb6c 57.RS 4
2b1b0424
MK
58_POSIX_C_SOURCE\ >=\ 200112L
59 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
b671fb6c 60.RE
cc4615cc 61.ad b
fea681da 62.SH DESCRIPTION
60a90ecd
MK
63The
64.BR setenv ()
c6fa0841
MK
65function adds the variable
66.I name
67to the
68environment with the value
69.IR value ,
70if
71.I name
72does not
c13182ef 73already exist.
c6fa0841
MK
74If
75.I name
76does exist in the environment, then
77its value is changed to
51700fd7 78.IR value
c6fa0841
MK
79if
80.I overwrite
81is nonzero;
82if
51700fd7 83.IR overwrite
c6fa0841
MK
84is zero, then the value of
85.I name
779e42d0
MK
86is not changed (and
87.BR setenv ()
88returns a success status).
f3268285
MK
89This function makes copies of the strings pointed to by
90.I name
91and
92.I value
93(by contrast with
94.BR putenv (3)).
fea681da 95.PP
60a90ecd
MK
96The
97.BR unsetenv ()
c6fa0841
MK
98function deletes the variable
99.I name
100from
fea681da 101the environment.
f3268285
MK
102If
103.I name
104does not exist in the environment,
105then the function succeeds, and the environment is unchanged.
47297adb 106.SH RETURN VALUE
60a90ecd 107.BR setenv ()
483368b3 108and
60a90ecd 109.BR unsetenv ()
483368b3 110functions return zero on success,
fea681da
MK
111or \-1 on error, with
112.I errno
113set to indicate the cause of the error.
47297adb 114.SH ERRORS
fea681da
MK
115.TP
116.B EINVAL
117.I name
2a4b81ff
MK
118is NULL, points to a string of length 0,
119or contains an \(aq=\(aq character.
120.TP
121.B ENOMEM
122Insufficient memory to add a new variable to the environment.
6d682990
MS
123.SH ATTRIBUTES
124For an explanation of the terms used in this section, see
125.BR attributes (7).
74714ea8 126.ad l
6d682990
MS
127.TS
128allbox;
129lb lb lb
130l l l.
131Interface Attribute Value
132T{
133.BR setenv (),
134.BR unsetenv ()
135T} Thread safety MT-Unsafe const:env
136.TE
74714ea8 137.ad
47297adb 138.SH CONFORMING TO
246d0d44 139POSIX.1-2001, POSIX.1-2008, 4.3BSD.
47297adb 140.SH NOTES
246d0d44 141POSIX.1 does not require
f3268285
MK
142.BR setenv ()
143or
144.BR unsetenv ()
145to be reentrant.
847e0d88 146.PP
60a90ecd
MK
147Prior to glibc 2.2.2,
148.BR unsetenv ()
149was prototyped
c6fa0841
MK
150as returning
151.IR void ;
152more recent glibc versions follow the
246d0d44 153POSIX.1-compliant prototype shown in the SYNOPSIS.
fea681da 154.SH BUGS
246d0d44 155POSIX.1 specifies that if
fea681da 156.I name
f81fb444 157contains an \(aq=\(aq character, then
fea681da
MK
158.BR setenv ()
159should fail with the error
160.BR EINVAL ;
f81fb444 161however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in
fea681da 162.IR name .
47297adb 163.SH SEE ALSO
fea681da
MK
164.BR clearenv (3),
165.BR getenv (3),
166.BR putenv (3),
aa949e2d 167.BR environ (7)