]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setenv.3
Automated unformatting of parentheses using unformat_parens.sh
[thirdparty/man-pages.git] / man3 / setenv.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
3.\" Permission is granted to make and distribute verbatim copies of this
4.\" manual provided the copyright notice and this permission notice are
5.\" preserved on all copies.
6.\"
7.\" Permission is granted to copy and distribute modified versions of this
8.\" manual under the conditions for verbatim copying, provided that the
9.\" entire resulting derived work is distributed under the terms of a
10.\" permission notice identical to this one.
11.\"
12.\" Since the Linux kernel and libraries are constantly changing, this
13.\" manual page may be incorrect or out-of-date. The author(s) assume no
14.\" responsibility for errors or omissions, or for damages resulting from
15.\" the use of the information contained herein. The author(s) may not
16.\" have taken the same level of care in the production of this manual,
17.\" which is licensed free of charge, as they might when working
18.\" professionally.
19.\"
20.\" Formatted or processed versions of this manual, if unaccompanied by
21.\" the source, must acknowledge the copyright and authors of this work.
22.\"
23.\" References consulted:
24.\" Linux libc source code
25.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26.\" 386BSD man pages
27.\" Modified Sat Jul 24 18:20:58 1993 by Rik Faith (faith@cs.unc.edu)
28.\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl)
305a0578 29.\" Modified 9 Jun 2004, Michael Kerrisk <mtk-manpages@gmx.net>
fea681da
MK
30.\" Changed unsetenv() prototype; added EINVAL error
31.\" Noted non-standard behaviour of setenv() if name contains '='
279d6eea 32.\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug
fea681da
MK
33.\"
34.TH SETENV 3 2004-05-09 "BSD" "Linux Programmer's Manual"
35.SH NAME
36setenv \- change or add an environment variable
37.SH SYNOPSIS
38.nf
39.B #include <stdlib.h>
40.sp
41.BI "int setenv(const char *" name ", const char *" value ", int " overwrite );
42.sp
43.BI "int unsetenv(const char *" name );
44.fi
45.SH DESCRIPTION
63aa9df0 46The \fBsetenv\fP() function adds the variable \fIname\fP to the
fea681da
MK
47environment with the value \fIvalue\fP, if \fIname\fP does not
48already exist. If \fIname\fP does exist in the environment, then
49its value is changed to \fIvalue\fP if \fIoverwrite\fP is non-zero;
50if \fIoverwrite\fP is zero, then the value of \fIname\fP is not
51changed.
52.PP
63aa9df0 53The \fBunsetenv\fP() function deletes the variable \fIname\fP from
fea681da
MK
54the environment.
55.SH "RETURN VALUE"
63aa9df0 56The \fBsetenv\fP() function returns zero on success, or \-1 if there
fea681da 57was insufficient space in the environment.
63aa9df0 58The \fBunsetenv\fP() function returns zero on success,
fea681da
MK
59or \-1 on error, with
60.I errno
61set to indicate the cause of the error.
62.SH "ERRORS"
63.TP
64.B EINVAL
65.I name
66contained an '=' character.
67.SH "CONFORMING TO"
b14d4aa5 684.3BSD
fea681da 69.SH "NOTES"
63aa9df0 70Prior to glibc 2.2.2, \fBunsetenv\fP() was prototyped
fea681da
MK
71as returning \fIvoid\fP; more recent glibc versions follow the
72SUSv3-compliant prototype shown in the SYNOPSIS.
73.SH BUGS
74SUSv3 specifies that if
75.I name
76contains an '=' character, then
77.BR setenv ()
78should fail with the error
79.BR EINVAL ;
279d6eea 80however, versions of glibc before 2.3.4 allowed an '=' sign in
fea681da 81.IR name .
fea681da
MK
82.SH "SEE ALSO"
83.BR clearenv (3),
84.BR getenv (3),
85.BR putenv (3),
86.BR environ (5)