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

NAME

6       putenv - change or add an environment variable
7

SYNOPSIS

9       #include <stdlib.h>
10
11       int putenv(char *string);
12
13   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15       putenv():
16           _XOPEN_SOURCE
17               || /* Glibc since 2.19: */ _DEFAULT_SOURCE
18               || /* Glibc <= 2.19: */ _SVID_SOURCE
19

DESCRIPTION

21       The  putenv()  function  adds or changes the value of environment vari‐
22       ables.  The argument string is of the form name=value.   If  name  does
23       not already exist in the environment, then string is added to the envi‐
24       ronment.  If name does exist, then the value of name in the environment
25       is  changed  to value.  The string pointed to by string becomes part of
26       the environment, so altering the string changes the environment.
27

RETURN VALUE

29       The putenv() function returns zero on success.  On failure, it  returns
30       a nonzero value, and errno is set to indicate the error.
31

ERRORS

33       ENOMEM Insufficient space to allocate new environment.
34

ATTRIBUTES

36       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
37       tributes(7).
38
39       ┌────────────────────────────────┬───────────────┬─────────────────────┐
40Interface                       Attribute     Value               
41       ├────────────────────────────────┼───────────────┼─────────────────────┤
42putenv()                        │ Thread safety │ MT-Unsafe const:env │
43       └────────────────────────────────┴───────────────┴─────────────────────┘
44

CONFORMING TO

46       POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
47

NOTES

49       The putenv() function is not required to be reentrant, and the  one  in
50       glibc 2.0 is not, but the glibc 2.1 version is.
51
52       Since  version  2.1.2,  the glibc implementation conforms to SUSv2: the
53       pointer string given to putenv() is used.  In particular,  this  string
54       becomes  part of the environment; changing it later will change the en‐
55       vironment.  (Thus, it is an error to call putenv()  with  an  automatic
56       variable  as  the argument, then return from the calling function while
57       string is still part of the environment.)  However, glibc versions  2.0
58       to  2.1.1  differ:  a copy of the string is used.  On the one hand this
59       causes a memory leak, and on the other hand it violates SUSv2.
60
61       The 4.4BSD version, like glibc 2.0, uses a copy.
62
63       SUSv2 removes the const from the prototype, and so does glibc 2.1.3.
64
65       The GNU C library implementation provides a nonstandard extension.   If
66       string does not include an equal sign:
67
68           putenv("NAME");
69
70       then the named variable is removed from the caller's environment.
71

SEE ALSO

73       clearenv(3), getenv(3), setenv(3), unsetenv(3), environ(7)
74

COLOPHON

76       This  page  is  part of release 5.13 of the Linux man-pages project.  A
77       description of the project, information about reporting bugs,  and  the
78       latest     version     of     this    page,    can    be    found    at
79       https://www.kernel.org/doc/man-pages/.
80
81
82
83GNU                               2021-03-22                         PUTENV(3)
Impressum