]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setenv.3
Removed trailing white space at end of lines
[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.\"
2a4b81ff 37.TH SETENV 3 2009-09-20 "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
85is not
fea681da 86changed.
f3268285
MK
87This function makes copies of the strings pointed to by
88.I name
89and
90.I value
91(by contrast with
92.BR putenv (3)).
fea681da 93.PP
60a90ecd
MK
94The
95.BR unsetenv ()
c6fa0841
MK
96function deletes the variable
97.I name
98from
fea681da 99the environment.
f3268285
MK
100If
101.I name
102does not exist in the environment,
103then the function succeeds, and the environment is unchanged.
47297adb 104.SH RETURN VALUE
60a90ecd
MK
105The
106.BR setenv ()
2a4b81ff
MK
107function returns zero on success,
108or \-1 on error, with
109.I errno
110set to indicate the cause of the error.
f3268285 111
60a90ecd
MK
112The
113.BR unsetenv ()
114function returns zero on success,
fea681da
MK
115or \-1 on error, with
116.I errno
117set to indicate the cause of the error.
47297adb 118.SH ERRORS
fea681da
MK
119.TP
120.B EINVAL
121.I name
2a4b81ff
MK
122is NULL, points to a string of length 0,
123or contains an \(aq=\(aq character.
124.TP
125.B ENOMEM
126Insufficient memory to add a new variable to the environment.
47297adb 127.SH CONFORMING TO
68e1685c 1284.3BSD, POSIX.1-2001.
47297adb 129.SH NOTES
f3268285
MK
130POSIX.1-2001 does not require
131.BR setenv ()
132or
133.BR unsetenv ()
134to be reentrant.
135
60a90ecd
MK
136Prior to glibc 2.2.2,
137.BR unsetenv ()
138was prototyped
c6fa0841
MK
139as returning
140.IR void ;
141more recent glibc versions follow the
68e1685c 142POSIX.1-2001-compliant prototype shown in the SYNOPSIS.
fea681da 143.SH BUGS
68e1685c 144POSIX.1-2001 specifies that if
fea681da 145.I name
f81fb444 146contains an \(aq=\(aq character, then
fea681da
MK
147.BR setenv ()
148should fail with the error
149.BR EINVAL ;
f81fb444 150however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in
fea681da 151.IR name .
47297adb 152.SH SEE ALSO
fea681da
MK
153.BR clearenv (3),
154.BR getenv (3),
155.BR putenv (3),
aa949e2d 156.BR environ (7)