1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2004, 2007 Michael kerrisk <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" References consulted:
25 .\" Linux libc source code
26 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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)
30 .\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Changed unsetenv() prototype; added EINVAL error
32 .\" Noted non-standard behavior of setenv() if name contains '='
33 .\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug
35 .TH SETENV 3 2009-09-20 "GNU" "Linux Programmer's Manual"
37 setenv \- change or add an environment variable
40 .B #include <stdlib.h>
42 .BI "int setenv(const char *" name ", const char *" value ", int " overwrite );
44 .BI "int unsetenv(const char *" name );
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
55 _BSD_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
60 function adds the variable \fIname\fP to the
61 environment with the value \fIvalue\fP, if \fIname\fP does not
63 If \fIname\fP does exist in the environment, then
64 its value is changed to \fIvalue\fP if \fIoverwrite\fP is non-zero;
65 if \fIoverwrite\fP is zero, then the value of \fIname\fP is not
67 This function makes copies of the strings pointed to by
76 function deletes the variable \fIname\fP from
80 does not exist in the environment,
81 then the function succeeds, and the environment is unchanged.
85 function returns zero on success,
88 set to indicate the cause of the error.
92 function returns zero on success,
95 set to indicate the cause of the error.
100 is NULL, points to a string of length 0,
101 or contains an \(aq=\(aq character.
104 Insufficient memory to add a new variable to the environment.
106 4.3BSD, POSIX.1-2001.
108 POSIX.1-2001 does not require
114 Prior to glibc 2.2.2,
117 as returning \fIvoid\fP; more recent glibc versions follow the
118 POSIX.1-2001-compliant prototype shown in the SYNOPSIS.
120 POSIX.1-2001 specifies that if
122 contains an \(aq=\(aq character, then
124 should fail with the error
126 however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in