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