201 lines
4.7 KiB
HTML
201 lines
4.7 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of PUTENV</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>PUTENV</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
putenv - change or add an environment variable
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>></B>
|
|
|
|
<B>int putenv(char *</B><I>string</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>putenv</B>():
|
|
|
|
_XOPEN_SOURCE
|
|
<BR> || /* Glibc since 2.19: */ _DEFAULT_SOURCE
|
|
<BR> || /* Glibc versions <= 2.19: */ _SVID_SOURCE
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>putenv</B>()
|
|
|
|
function adds or changes the value of environment
|
|
variables.
|
|
The argument <I>string</I> is of the form <I>name</I>=<I>value</I>.
|
|
If <I>name</I> does not already exist in the environment, then
|
|
<I>string</I> is added to the environment.
|
|
If <I>name</I> does exist,
|
|
then the value of <I>name</I> in the environment is changed to
|
|
<I>value</I>.
|
|
The string pointed to by <I>string</I> becomes part of the environment,
|
|
so altering the string changes the environment.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The
|
|
<B>putenv</B>()
|
|
|
|
function returns zero on success,
|
|
or nonzero if an error occurs.
|
|
In the event of an error,
|
|
<I>errno</I>
|
|
|
|
is set to indicate the cause.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Insufficient space to allocate new environment.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>putenv</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe const:env<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The
|
|
<B>putenv</B>()
|
|
|
|
function is not required to be reentrant, and the
|
|
one in glibc 2.0 is not, but the glibc 2.1 version is.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<P>
|
|
|
|
Since version 2.1.2, the glibc implementation conforms to SUSv2:
|
|
the pointer <I>string</I> given to
|
|
<B>putenv</B>()
|
|
|
|
is used.
|
|
In particular, this string becomes part of the environment;
|
|
changing it later will change the environment.
|
|
(Thus, it is an error to call
|
|
<B>putenv</B>()
|
|
|
|
with an automatic variable
|
|
as the argument, then return from the calling function while <I>string</I>
|
|
is still part of the environment.)
|
|
However, glibc versions 2.0 to 2.1.1 differ: a copy of the string is used.
|
|
On the one hand this causes a memory leak, and on the other hand
|
|
it violates SUSv2.
|
|
<P>
|
|
|
|
The 4.4BSD version, like glibc 2.0, uses a copy.
|
|
<P>
|
|
|
|
SUSv2 removes the <I>const</I> from the prototype, and so does glibc 2.1.3.
|
|
<P>
|
|
|
|
The GNU C library implementation provides a nonstandard extension.
|
|
If
|
|
<I>string</I>
|
|
|
|
does not include an equal sign:
|
|
<P>
|
|
|
|
|
|
|
|
putenv("NAME");
|
|
|
|
|
|
<P>
|
|
|
|
then the named variable is removed from the caller's environment.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+clearenv">clearenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getenv">getenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setenv">setenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+unsetenv">unsetenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+environ">environ</A></B>(7)
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="5"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="6"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="7"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="8"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="9"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="10"><A HREF="#lbAJ">SEE ALSO</A><DD>
|
|
<DT id="11"><A HREF="#lbAK">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:53 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|