1SETENV(3)                  Linux Programmer's Manual                 SETENV(3)
2
3
4

NAME

6       setenv - change or add an environment variable
7

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

34       The setenv() function returns zero on success, or  -1  on  error,  with
35       errno set to indicate the cause of the error.
36
37       The  unsetenv()  function returns zero on success, or -1 on error, with
38       errno set to indicate the cause of the error.
39

ERRORS

41       EINVAL name is NULL, points to a string of length 0, or contains an '='
42              character.
43
44       ENOMEM Insufficient memory to add a new variable to the environment.
45

ATTRIBUTES

47       For   an   explanation   of   the  terms  used  in  this  section,  see
48       attributes(7).
49
50       ┌───────────┬───────────────┬─────────────────────┐
51Interface  Attribute     Value               
52       ├───────────┼───────────────┼─────────────────────┤
53setenv(),  │ Thread safety │ MT-Unsafe const:env │
54unsetenv() │               │                     │
55       └───────────┴───────────────┴─────────────────────┘

CONFORMING TO

57       POSIX.1-2001, POSIX.1-2008, 4.3BSD.
58

NOTES

60       POSIX.1 does not require setenv() or unsetenv() to be reentrant.
61
62       Prior to glibc 2.2.2, unsetenv() was prototyped as returning void; more
63       recent glibc versions follow the POSIX.1-compliant prototype  shown  in
64       the SYNOPSIS.
65

BUGS

67       POSIX.1 specifies that if name contains an '=' character, then setenv()
68       should fail with the error EINVAL; however, versions  of  glibc  before
69       2.3.4 allowed an '=' sign in name.
70

SEE ALSO

72       clearenv(3), getenv(3), putenv(3), environ(7)
73

COLOPHON

75       This  page  is  part of release 4.16 of the Linux man-pages project.  A
76       description of the project, information about reporting bugs,  and  the
77       latest     version     of     this    page,    can    be    found    at
78       https://www.kernel.org/doc/man-pages/.
79
80
81
82GNU                               2017-09-15                         SETENV(3)
Impressum