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