]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setenv.3
All pages: Remove the 5th argument to .TH
[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.\"
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
19setenv \- change or add an environment variable
09672b8d
AC
20.SH LIBRARY
21Standard 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
32Feature 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
43The
44.BR setenv ()
c6fa0841
MK
45function adds the variable
46.I name
47to the
48environment with the value
49.IR value ,
50if
51.I name
52does not
c13182ef 53already exist.
c6fa0841
MK
54If
55.I name
56does exist in the environment, then
57its value is changed to
1ae6b2c7 58.I value
c6fa0841
MK
59if
60.I overwrite
61is nonzero;
62if
1ae6b2c7 63.I overwrite
c6fa0841
MK
64is zero, then the value of
65.I name
779e42d0
MK
66is not changed (and
67.BR setenv ()
68returns a success status).
f3268285
MK
69This function makes copies of the strings pointed to by
70.I name
71and
72.I value
73(by contrast with
74.BR putenv (3)).
fea681da 75.PP
60a90ecd
MK
76The
77.BR unsetenv ()
c6fa0841
MK
78function deletes the variable
79.I name
80from
fea681da 81the environment.
f3268285
MK
82If
83.I name
84does not exist in the environment,
85then the function succeeds, and the environment is unchanged.
47297adb 86.SH RETURN VALUE
60a90ecd 87.BR setenv ()
483368b3 88and
60a90ecd 89.BR unsetenv ()
483368b3 90functions return zero on success,
fea681da
MK
91or \-1 on error, with
92.I errno
855d489a 93set to indicate the error.
47297adb 94.SH ERRORS
fea681da
MK
95.TP
96.B EINVAL
97.I name
2a4b81ff
MK
98is NULL, points to a string of length 0,
99or contains an \(aq=\(aq character.
100.TP
101.B ENOMEM
102Insufficient memory to add a new variable to the environment.
6d682990
MS
103.SH ATTRIBUTES
104For 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
109allbox;
c466875e 110lbx lb lb
6d682990
MS
111l l l.
112Interface Attribute Value
113T{
114.BR setenv (),
115.BR unsetenv ()
116T} Thread safety MT-Unsafe const:env
117.TE
c466875e 118.hy
74714ea8 119.ad
c466875e 120.sp 1
3113c7f3 121.SH STANDARDS
246d0d44 122POSIX.1-2001, POSIX.1-2008, 4.3BSD.
47297adb 123.SH NOTES
246d0d44 124POSIX.1 does not require
f3268285
MK
125.BR setenv ()
126or
127.BR unsetenv ()
128to be reentrant.
847e0d88 129.PP
60a90ecd
MK
130Prior to glibc 2.2.2,
131.BR unsetenv ()
132was prototyped
c6fa0841
MK
133as returning
134.IR void ;
135more recent glibc versions follow the
246d0d44 136POSIX.1-compliant prototype shown in the SYNOPSIS.
fea681da 137.SH BUGS
246d0d44 138POSIX.1 specifies that if
fea681da 139.I name
f81fb444 140contains an \(aq=\(aq character, then
fea681da
MK
141.BR setenv ()
142should fail with the error
143.BR EINVAL ;
f81fb444 144however, 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)