1PUTENV(3P)                 POSIX Programmer's Manual                PUTENV(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       putenv — change or add a value to an environment
13

SYNOPSIS

15       #include <stdlib.h>
16
17       int putenv(char *string);
18

DESCRIPTION

20       The putenv() function shall use the string argument to set  environment
21       variable  values.  The  string argument should point to a string of the
22       form "name=value".  The putenv() function shall make the value  of  the
23       environment  variable name equal to value by altering an existing vari‐
24       able or creating a new one. In either case, the string  pointed  to  by
25       string  shall  become  part  of the environment, so altering the string
26       shall change the environment.
27
28       The putenv() function need not be thread-safe.
29

RETURN VALUE

31       Upon successful completion, putenv()  shall  return  0;  otherwise,  it
32       shall return a non-zero value and set errno to indicate the error.
33

ERRORS

35       The putenv() function may fail if:
36
37       ENOMEM Insufficient memory was available.
38
39       The following sections are informative.
40

EXAMPLES

42   Changing the Value of an Environment Variable
43       The  following  example changes the value of the HOME environment vari‐
44       able to the value /usr/home.
45
46
47           #include <stdlib.h>
48           ...
49           static char *var = "HOME=/usr/home";
50           int ret;
51
52           ret = putenv(var);
53

APPLICATION USAGE

55       The putenv() function manipulates the environment pointed to  by  envi‐
56       ron, and can be used in conjunction with getenv().
57
58       See  exec()  for  restrictions  on  changing  the environment in multi-
59       threaded applications.
60
61       This routine may use malloc() to enlarge the environment.
62
63       A potential error is to call putenv() with an automatic variable as the
64       argument,  then  return from the calling function while string is still
65       part of the environment.
66
67       Although the space used by string is no longer used once a  new  string
68       which defines name is passed to putenv(), if any thread in the applica‐
69       tion has used getenv() to retrieve  a  pointer  to  this  variable,  it
70       should  not  be  freed  by  calling free().  If the changed environment
71       variable is one known by the system (such  as  the  locale  environment
72       variables) the application should never free the buffer used by earlier
73       calls to putenv() for the same variable.
74
75       The setenv() function is preferred over this function.  One  reason  is
76       that  putenv() is optional and therefore less portable. Another is that
77       using putenv() can slow down environment searches, as explained in  the
78       RATIONALE section for getenv().
79

RATIONALE

81       Refer to the RATIONALE section in setenv().
82

FUTURE DIRECTIONS

84       None.
85

SEE ALSO

87       exec, free(), getenv(), malloc(), setenv()
88
89       The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
90
92       Portions  of  this text are reprinted and reproduced in electronic form
93       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
94       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
95       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
96       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
97       event of any discrepancy between this version and the original IEEE and
98       The  Open Group Standard, the original IEEE and The Open Group Standard
99       is the referee document. The original Standard can be  obtained  online
100       at http://www.opengroup.org/unix/online.html .
101
102       Any  typographical  or  formatting  errors that appear in this page are
103       most likely to have been introduced during the conversion of the source
104       files  to  man page format. To report such errors, see https://www.ker
105       nel.org/doc/man-pages/reporting_bugs.html .
106
107
108
109IEEE/The Open Group                  2017                           PUTENV(3P)
Impressum