1PUTENV(3P) POSIX Programmer's Manual PUTENV(3P)
2
3
4
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
12 putenv - change or add a value to an environment
13
15 #include <stdlib.h>
16
17 int putenv(char *string);
18
19
21 The putenv() function shall use the string argument to set environment
22 variable values. The string argument should point to a string of the
23 form " name= value ". The putenv() function shall make the value of
24 the environment variable name equal to value by altering an existing
25 variable or creating a new one. In either case, the string pointed to
26 by string shall become part of the environment, so altering the string
27 shall change the environment. The space used by string is no longer
28 used once a new string which defines name is passed to putenv().
29
30 The putenv() function need not be reentrant. A function that is not
31 required to be reentrant is not required to be thread-safe.
32
34 Upon successful completion, putenv() shall return 0; otherwise, it
35 shall return a non-zero value and set errno to indicate the error.
36
38 The putenv() function may fail if:
39
40 ENOMEM Insufficient memory was available.
41
42
43 The following sections are informative.
44
46 Changing the Value of an Environment Variable
47 The following example changes the value of the HOME environment vari‐
48 able to the value /usr/home.
49
50
51 #include <stdlib.h>
52 ...
53 static char *var = "HOME=/usr/home";
54 int ret;
55
56
57 ret = putenv(var);
58
60 The putenv() function manipulates the environment pointed to by envi‐
61 ron, and can be used in conjunction with getenv().
62
63 See exec(), for restrictions on changing the environment in multi-
64 threaded applications.
65
66 This routine may use malloc() to enlarge the environment.
67
68 A potential error is to call putenv() with an automatic variable as the
69 argument, then return from the calling function while string is still
70 part of the environment.
71
72 The setenv() function is preferred over this function.
73
75 The standard developers noted that putenv() is the only function avail‐
76 able to add to the environment without permitting memory leaks.
77
79 None.
80
82 exec(), getenv(), malloc(), setenv(), the Base Definitions volume of
83 IEEE Std 1003.1-2001, <stdlib.h>
84
86 Portions of this text are reprinted and reproduced in electronic form
87 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
88 -- Portable Operating System Interface (POSIX), The Open Group Base
89 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
90 Electrical and Electronics Engineers, Inc and The Open Group. In the
91 event of any discrepancy between this version and the original IEEE and
92 The Open Group Standard, the original IEEE and The Open Group Standard
93 is the referee document. The original Standard can be obtained online
94 at http://www.opengroup.org/unix/online.html .
95
96
97
98IEEE/The Open Group 2003 PUTENV(3P)