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(): _SVID_SOURCE || _XOPEN_SOURCE
16

DESCRIPTION

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

RETURN VALUE

26       The putenv() function returns zero on success, or non-zero if an  error
27       occurs.
28

ERRORS

30       ENOMEM Insufficient space to allocate new environment.
31

CONFORMING TO

33       SVr4, POSIX.1-2001, 4.3BSD.
34

NOTES

36       The  putenv()  function is not required to be reentrant, and the one in
37       libc4, libc5 and glibc 2.0 is not, but the glibc 2.1 version is.
38
39       Description for libc4, libc5, glibc: If the argument string is  of  the
40       form  name,  and  does  not contain an '=' character, then the variable
41       name is removed from the environment.  If putenv() has  to  allocate  a
42       new  array  environ,  and  the  previous  array  was  also allocated by
43       putenv(), then it will be freed.  In no case will the old storage asso‐
44       ciated to the environment variable itself be freed.
45
46       The  libc4  and  libc5  and  glibc 2.1.2 versions conform to SUSv2: the
47       pointer string given to putenv() is used.  In particular,  this  string
48       becomes  part  of  the  environment;  changing it later will change the
49       environment.  (Thus, it is an error is to call putenv() with  an  auto‐
50       matic  variable  as the argument, then return from the calling function
51       while string  is  still  part  of  the  environment.)   However,  glibc
52       2.0-2.1.1  differs: a copy of the string is used.  On the one hand this
53       causes a memory leak, and on the other hand it  violates  SUSv2.   This
54       has been fixed in glibc 2.1.2.
55
56       The 4.4BSD version, like glibc 2.0, uses a copy.
57
58       SUSv2 removes the const from the prototype, and so does glibc 2.1.3.
59

SEE ALSO

61       clearenv(3), getenv(3), setenv(3), unsetenv(3), environ(7)
62

COLOPHON

64       This  page  is  part of release 3.22 of the Linux man-pages project.  A
65       description of the project, and information about reporting  bugs,  can
66       be found at http://www.kernel.org/doc/man-pages/.
67
68
69
70GNU                               2007-07-26                         PUTENV(3)
Impressum