]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setenv.3
dlinfo.3: ATTRIBUTES: Note function that is thread-safe
[thirdparty/man-pages.git] / man3 / setenv.3
CommitLineData
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.\"
fe0fefbf 37.TH SETENV 3 2015-03-02 "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>
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
50Feature 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
62The
63.BR setenv ()
c6fa0841
MK
64function adds the variable
65.I name
66to the
67environment with the value
68.IR value ,
69if
70.I name
71does not
c13182ef 72already exist.
c6fa0841
MK
73If
74.I name
75does exist in the environment, then
76its value is changed to
51700fd7 77.IR value
c6fa0841
MK
78if
79.I overwrite
80is nonzero;
81if
51700fd7 82.IR overwrite
c6fa0841
MK
83is zero, then the value of
84.I name
779e42d0
MK
85is not changed (and
86.BR setenv ()
87returns a success status).
f3268285
MK
88This function makes copies of the strings pointed to by
89.I name
90and
91.I value
92(by contrast with
93.BR putenv (3)).
fea681da 94.PP
60a90ecd
MK
95The
96.BR unsetenv ()
c6fa0841
MK
97function deletes the variable
98.I name
99from
fea681da 100the environment.
f3268285
MK
101If
102.I name
103does not exist in the environment,
104then the function succeeds, and the environment is unchanged.
47297adb 105.SH RETURN VALUE
60a90ecd
MK
106The
107.BR setenv ()
2a4b81ff
MK
108function returns zero on success,
109or \-1 on error, with
110.I errno
111set to indicate the cause of the error.
f3268285 112
60a90ecd
MK
113The
114.BR unsetenv ()
115function returns zero on success,
fea681da
MK
116or \-1 on error, with
117.I errno
118set to indicate the cause of the error.
47297adb 119.SH ERRORS
fea681da
MK
120.TP
121.B EINVAL
122.I name
2a4b81ff
MK
123is NULL, points to a string of length 0,
124or contains an \(aq=\(aq character.
125.TP
126.B ENOMEM
127Insufficient memory to add a new variable to the environment.
6d682990
MS
128.SH ATTRIBUTES
129For an explanation of the terms used in this section, see
130.BR attributes (7).
131.TS
132allbox;
133lb lb lb
134l l l.
135Interface Attribute Value
136T{
137.BR setenv (),
138.BR unsetenv ()
139T} Thread safety MT-Unsafe const:env
140.TE
47297adb 141.SH CONFORMING TO
246d0d44 142POSIX.1-2001, POSIX.1-2008, 4.3BSD.
47297adb 143.SH NOTES
246d0d44 144POSIX.1 does not require
f3268285
MK
145.BR setenv ()
146or
147.BR unsetenv ()
148to be reentrant.
149
60a90ecd
MK
150Prior to glibc 2.2.2,
151.BR unsetenv ()
152was prototyped
c6fa0841
MK
153as returning
154.IR void ;
155more recent glibc versions follow the
246d0d44 156POSIX.1-compliant prototype shown in the SYNOPSIS.
fea681da 157.SH BUGS
246d0d44 158POSIX.1 specifies that if
fea681da 159.I name
f81fb444 160contains an \(aq=\(aq character, then
fea681da
MK
161.BR setenv ()
162should fail with the error
163.BR EINVAL ;
f81fb444 164however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in
fea681da 165.IR name .
47297adb 166.SH SEE ALSO
fea681da
MK
167.BR clearenv (3),
168.BR getenv (3),
169.BR putenv (3),
aa949e2d 170.BR environ (7)