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

DESCRIPTION

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

RETURN VALUE

22       The putenv() function returns zero on success, or non-zero if an  error
23       occurs.
24

ERRORS

26       ENOMEM Insufficient space to allocate new environment.
27

NOTES

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

CONFORMING TO

54       SVr4, POSIX.1-2001, 4.3BSD
55

SEE ALSO

57       clearenv(3), getenv(3), setenv(3), unsetenv(3), environ(7)
58
59
60
61GNU                               1993-04-08                         PUTENV(3)
Impressum