OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / putenv.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\"     Single UNIX Specification, Version 2
30 .\" Modified Thu Apr  8 15:00:12 1993, David Metcalfe
31 .\" Modified Sat Jul 24 18:44:45 1993, Rik Faith (faith@cs.unc.edu)
32 .\" Modified Fri Feb 14 21:47:50 1997 by Andries Brouwer (aeb@cwi.nl)
33 .\" Modified Mon Oct 11 11:11:11 1999 by Andries Brouwer (aeb@cwi.nl)
34 .\" Modified Wed Nov 10 00:02:26 1999 by Andries Brouwer (aeb@cwi.nl)
35 .\" Modified Sun May 20 22:17:20 2001 by Andries Brouwer (aeb@cwi.nl)
36 .TH PUTENV 3  2014-08-19 "GNU" "Linux Programmer's Manual"
37 .SH NAME
38 putenv \- change or add an environment variable
39 .SH SYNOPSIS
40 .nf
41 .B #include <stdlib.h>
42 .sp
43 .BI "int putenv(char *" string );
44 .\" Not: const char *
45 .fi
46 .sp
47 .in -4n
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
50 .in
51 .sp
52 .BR putenv ():
53 _SVID_SOURCE || _XOPEN_SOURCE
54 .SH DESCRIPTION
55 The
56 .BR putenv ()
57 function adds or changes the value of environment
58 variables.
59 The argument \fIstring\fP is of the form \fIname\fP=\fIvalue\fP.
60 If \fIname\fP does not already exist in the environment, then
61 \fIstring\fP is added to the environment.
62 If \fIname\fP does exist,
63 then the value of \fIname\fP in the environment is changed to
64 \fIvalue\fP.
65 The string pointed to by \fIstring\fP becomes part of the environment,
66 so altering the string changes the environment.
67 .SH RETURN VALUE
68 The
69 .BR putenv ()
70 function returns zero on success,
71 or nonzero if an error occurs.
72 In the event of an error,
73 .I errno
74 is set to indicate the cause.
75 .SH ERRORS
76 .TP
77 .B ENOMEM
78 Insufficient space to allocate new environment.
79 .SH CONFORMING TO
80 SVr4, POSIX.1-2001, 4.3BSD.
81 .SH NOTES
82 The
83 .BR putenv ()
84 function is not required to be reentrant, and the
85 one in glibc 2.0 is not, but the glibc 2.1 version is.
86 .\" .LP
87 .\" Description for libc4, libc5, glibc:
88 .\" If the argument \fIstring\fP is of the form \fIname\fP,
89 .\" and does not contain an \(aq=\(aq character, then the variable \fIname\fP
90 .\" is removed from the environment.
91 .\" If
92 .\" .BR putenv ()
93 .\" has to allocate a new array \fIenviron\fP,
94 .\" and the previous array was also allocated by
95 .\" .BR putenv (),
96 .\" then it will be freed.
97 .\" In no case will the old storage associated
98 .\" to the environment variable itself be freed.
99 .LP
100 Since version 2.1.2, the glibc implementation conforms to SUSv2:
101 the pointer \fIstring\fP given to
102 .BR putenv ()
103 is used.
104 In particular, this string becomes part of the environment;
105 changing it later will change the environment.
106 (Thus, it is an error is to call
107 .BR putenv ()
108 with an automatic variable
109 as the argument, then return from the calling function while \fIstring\fP
110 is still part of the environment.)
111 However, glibc versions 2.0 to 2.1.1 differ: a copy of the string is used.
112 On the one hand this causes a memory leak, and on the other hand
113 it violates SUSv2.
114 .LP
115 The 4.4BSD version, like glibc 2.0, uses a copy.
116 .LP
117 SUSv2 removes the \fIconst\fP from the prototype, and so does glibc 2.1.3.
118 .SH SEE ALSO
119 .BR clearenv (3),
120 .BR getenv (3),
121 .BR setenv (3),
122 .BR unsetenv (3),
123 .BR environ (7)
124 .SH COLOPHON
125 This page is part of release 3.79 of the Linux
126 .I man-pages
127 project.
128 A description of the project,
129 information about reporting bugs,
130 and the latest version of this page,
131 can be found at
132 \%http://www.kernel.org/doc/man\-pages/.