]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setenv.3
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex...
[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
MK
3.\"
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
c13182ef 12.\"
fea681da
MK
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
23.\"
24.\" References consulted:
25.\" Linux libc source code
26.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27.\" 386BSD man pages
28.\" Modified Sat Jul 24 18:20:58 1993 by Rik Faith (faith@cs.unc.edu)
29.\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl)
c11b1abf 30.\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 31.\" Changed unsetenv() prototype; added EINVAL error
c8f2dd47 32.\" Noted nonstandard behavior of setenv() if name contains '='
279d6eea 33.\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug
fea681da 34.\"
2a4b81ff 35.TH SETENV 3 2009-09-20 "GNU" "Linux Programmer's Manual"
fea681da
MK
36.SH NAME
37setenv \- change or add an environment variable
38.SH SYNOPSIS
39.nf
40.B #include <stdlib.h>
41.sp
42.BI "int setenv(const char *" name ", const char *" value ", int " overwrite );
43.sp
44.BI "int unsetenv(const char *" name );
45.fi
cc4615cc
MK
46.sp
47.in -4n
48Feature Test Macro Requirements for glibc (see
49.BR feature_test_macros (7)):
50.in
51.sp
52.ad l
53.BR setenv (),
54.BR unsetenv ():
b671fb6c 55.RS 4
cc4615cc 56_BSD_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
b671fb6c 57.RE
cc4615cc 58.ad b
fea681da 59.SH DESCRIPTION
60a90ecd
MK
60The
61.BR setenv ()
62function adds the variable \fIname\fP to the
fea681da 63environment with the value \fIvalue\fP, if \fIname\fP does not
c13182ef
MK
64already exist.
65If \fIname\fP does exist in the environment, then
c7094399 66its value is changed to \fIvalue\fP if \fIoverwrite\fP is nonzero;
fea681da
MK
67if \fIoverwrite\fP is zero, then the value of \fIname\fP is not
68changed.
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 ()
78function deletes the variable \fIname\fP from
fea681da 79the environment.
f3268285
MK
80If
81.I name
82does not exist in the environment,
83then the function succeeds, and the environment is unchanged.
47297adb 84.SH RETURN VALUE
60a90ecd
MK
85The
86.BR setenv ()
2a4b81ff
MK
87function returns zero on success,
88or \-1 on error, with
89.I errno
90set to indicate the cause of the error.
f3268285 91
60a90ecd
MK
92The
93.BR unsetenv ()
94function returns zero on success,
fea681da
MK
95or \-1 on error, with
96.I errno
97set to indicate the cause of the error.
47297adb 98.SH ERRORS
fea681da
MK
99.TP
100.B EINVAL
101.I name
2a4b81ff
MK
102is NULL, points to a string of length 0,
103or contains an \(aq=\(aq character.
104.TP
105.B ENOMEM
106Insufficient memory to add a new variable to the environment.
47297adb 107.SH CONFORMING TO
68e1685c 1084.3BSD, POSIX.1-2001.
47297adb 109.SH NOTES
f3268285
MK
110POSIX.1-2001 does not require
111.BR setenv ()
112or
113.BR unsetenv ()
114to be reentrant.
115
60a90ecd
MK
116Prior to glibc 2.2.2,
117.BR unsetenv ()
118was prototyped
fea681da 119as returning \fIvoid\fP; more recent glibc versions follow the
68e1685c 120POSIX.1-2001-compliant prototype shown in the SYNOPSIS.
fea681da 121.SH BUGS
68e1685c 122POSIX.1-2001 specifies that if
fea681da 123.I name
f81fb444 124contains an \(aq=\(aq character, then
fea681da
MK
125.BR setenv ()
126should fail with the error
127.BR EINVAL ;
f81fb444 128however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in
fea681da 129.IR name .
47297adb 130.SH SEE ALSO
fea681da
MK
131.BR clearenv (3),
132.BR getenv (3),
133.BR putenv (3),
aa949e2d 134.BR environ (7)