1SETENV(3) Linux Programmer's Manual SETENV(3)
2
3
4
6 setenv - change or add an environment variable
7
9 #include <stdlib.h>
10
11 int setenv(const char *name, const char *value, int overwrite);
12 int unsetenv(const char *name);
13
14 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16 setenv(), unsetenv():
17 _POSIX_C_SOURCE >= 200112L
18 || /* Glibc <= 2.19: */ _BSD_SOURCE
19
21 The setenv() function adds the variable name to the environment with
22 the value value, if name does not already exist. If name does exist in
23 the environment, then its value is changed to value if overwrite is
24 nonzero; if overwrite is zero, then the value of name is not changed
25 (and setenv() returns a success status). This function makes copies of
26 the strings pointed to by name and value (by contrast with putenv(3)).
27
28 The unsetenv() function deletes the variable name from the environment.
29 If name does not exist in the environment, then the function succeeds,
30 and the environment is unchanged.
31
33 setenv() and unsetenv() functions return zero on success, or -1 on er‐
34 ror, with errno set to indicate the error.
35
37 EINVAL name is NULL, points to a string of length 0, or contains an '='
38 character.
39
40 ENOMEM Insufficient memory to add a new variable to the environment.
41
43 For an explanation of the terms used in this section, see at‐
44 tributes(7).
45
46 ┌────────────────────────────────┬───────────────┬─────────────────────┐
47 │Interface │ Attribute │ Value │
48 ├────────────────────────────────┼───────────────┼─────────────────────┤
49 │setenv(), unsetenv() │ Thread safety │ MT-Unsafe const:env │
50 └────────────────────────────────┴───────────────┴─────────────────────┘
51
53 POSIX.1-2001, POSIX.1-2008, 4.3BSD.
54
56 POSIX.1 does not require setenv() or unsetenv() to be reentrant.
57
58 Prior to glibc 2.2.2, unsetenv() was prototyped as returning void; more
59 recent glibc versions follow the POSIX.1-compliant prototype shown in
60 the SYNOPSIS.
61
63 POSIX.1 specifies that if name contains an '=' character, then setenv()
64 should fail with the error EINVAL; however, versions of glibc before
65 2.3.4 allowed an '=' sign in name.
66
68 clearenv(3), getenv(3), putenv(3), environ(7)
69
71 This page is part of release 5.13 of the Linux man-pages project. A
72 description of the project, information about reporting bugs, and the
73 latest version of this page, can be found at
74 https://www.kernel.org/doc/man-pages/.
75
76
77
78GNU 2021-03-22 SETENV(3)