2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" and Copyright (C) 2004, 2007 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\" References consulted:
8 .\" Linux libc source code
9 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
11 .\" Modified Sat Jul 24 18:20:58 1993 by Rik Faith (faith@cs.unc.edu)
12 .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl)
13 .\" Modified 9 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
14 .\" Changed unsetenv() prototype; added EINVAL error
15 .\" Noted nonstandard behavior of setenv() if name contains '='
16 .\" 2005-08-12, mtk, glibc 2.3.4 fixed the "name contains '='" bug
18 .TH setenv 3 (date) "Linux man-pages (unreleased)"
20 setenv \- change or add an environment variable
23 .RI ( libc ", " \-lc )
26 .B #include <stdlib.h>
28 .BI "int setenv(const char *" name ", const char *" value ", int " overwrite );
29 .BI "int unsetenv(const char *" name );
33 Feature Test Macro Requirements for glibc (see
34 .BR feature_test_macros (7)):
40 _POSIX_C_SOURCE >= 200112L
41 || /* glibc <= 2.19: */ _BSD_SOURCE
46 function adds the variable
49 environment with the value
57 does exist in the environment, then
58 its value is changed to
65 is zero, then the value of
69 returns a success status).
70 This function makes copies of the strings pointed to by
79 function deletes the variable
85 does not exist in the environment,
86 then the function succeeds, and the environment is unchanged.
91 functions return zero on success,
94 set to indicate the error.
99 is NULL, points to a string of length 0,
100 or contains an \[aq]=\[aq] character.
103 Insufficient memory to add a new variable to the environment.
105 For an explanation of the terms used in this section, see
111 Interface Attribute Value
117 T} Thread safety MT-Unsafe const:env
122 POSIX.1-2001, 4.3BSD.
124 Prior to glibc 2.2.2,
129 more recent glibc versions follow the
130 POSIX.1-compliant prototype shown in the SYNOPSIS.
132 POSIX.1 does not require
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 glibc 2.3.4 allowed an \[aq]=\[aq] sign in