1setenv(3)                  Library Functions Manual                  setenv(3)
2
3
4

NAME

6       setenv - change or add an environment variable
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdlib.h>
13
14       int setenv(const char *name, const char *value, int overwrite);
15       int unsetenv(const char *name);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       setenv(), unsetenv():
20           _POSIX_C_SOURCE >= 200112L
21               || /* glibc <= 2.19: */ _BSD_SOURCE
22

DESCRIPTION

24       The  setenv()  function  adds the variable name to the environment with
25       the value value, if name does not already exist.  If name does exist in
26       the  environment,  then  its  value is changed to value if overwrite is
27       nonzero; if overwrite is zero, then the value of name  is  not  changed
28       (and setenv() returns a success status).  This function makes copies of
29       the strings pointed to by name and value (by contrast with putenv(3)).
30
31       The unsetenv() function deletes the variable name from the environment.
32       If  name does not exist in the environment, then the function succeeds,
33       and the environment is unchanged.
34

RETURN VALUE

36       setenv() and unsetenv() functions return zero on success, or -1 on  er‐
37       ror, with errno set to indicate the error.
38

ERRORS

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

ATTRIBUTES

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

STANDARDS

56       POSIX.1-2008.
57

HISTORY

59       POSIX.1-2001, 4.3BSD.
60
61       Prior to glibc 2.2.2, unsetenv() was prototyped as returning void; more
62       recent glibc versions follow the POSIX.1-compliant prototype  shown  in
63       the SYNOPSIS.
64

CAVEATS

66       POSIX.1 does not require setenv() or unsetenv() to be reentrant.
67

BUGS

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

SEE ALSO

74       clearenv(3), getenv(3), putenv(3), environ(7)
75
76
77
78Linux man-pages 6.04              2023-03-30                         setenv(3)
Impressum