1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2004, 2007 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
10 .\" Modified Sat Jul 24 18:20:58 1993 by Rik Faith (faith@cs.unc.edu)
11 .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl)
12 .\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
13 .\" Changed unsetenv() prototype; added EINVAL error
14 .\" Noted nonstandard behavior of setenv() if name contains '='
15 .\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug
17 .TH SETENV 3 2021-03-22 "Linux man-pages (unreleased)"
19 setenv \- change or add an environment variable
22 .RI ( libc ", " \-lc )
25 .B #include <stdlib.h>
27 .BI "int setenv(const char *" name ", const char *" value ", int " overwrite );
28 .BI "int unsetenv(const char *" name );
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
39 _POSIX_C_SOURCE >= 200112L
40 || /* Glibc <= 2.19: */ _BSD_SOURCE
45 function adds the variable
48 environment with the value
56 does exist in the environment, then
57 its value is changed to
64 is zero, then the value of
68 returns a success status).
69 This function makes copies of the strings pointed to by
78 function deletes the variable
84 does not exist in the environment,
85 then the function succeeds, and the environment is unchanged.
90 functions return zero on success,
93 set to indicate the error.
98 is NULL, points to a string of length 0,
99 or contains an \(aq=\(aq character.
102 Insufficient memory to add a new variable to the environment.
104 For an explanation of the terms used in this section, see
112 Interface Attribute Value
116 T} Thread safety MT-Unsafe const:env
122 POSIX.1-2001, POSIX.1-2008, 4.3BSD.
124 POSIX.1 does not require
130 Prior to glibc 2.2.2,
135 more recent glibc versions follow the
136 POSIX.1-compliant prototype shown in the SYNOPSIS.
138 POSIX.1 specifies that if
140 contains an \(aq=\(aq character, then
142 should fail with the error
144 however, versions of glibc before 2.3.4 allowed an \(aq=\(aq sign in