249 lines
4.8 KiB
HTML
249 lines
4.8 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SETENV</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SETENV</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<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>
|
|
|
|
setenv - 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 setenv(const char *</B><I>name</I><B>, const char *</B><I>value</I><B>, int </B><I>overwrite</I><B>);</B>
|
|
|
|
<B>int unsetenv(const char *</B><I>name</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>setenv</B>(),
|
|
|
|
<B>unsetenv</B>():
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
_POSIX_C_SOURCE >= 200112L
|
|
<BR> || /* Glibc versions <= 2.19: */ _BSD_SOURCE
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>setenv</B>()
|
|
|
|
function adds the variable
|
|
<I>name</I>
|
|
|
|
to the
|
|
environment with the value
|
|
<I>value</I>,
|
|
|
|
if
|
|
<I>name</I>
|
|
|
|
does not
|
|
already exist.
|
|
If
|
|
<I>name</I>
|
|
|
|
does exist in the environment, then
|
|
its value is changed to
|
|
<I>value</I>
|
|
|
|
if
|
|
<I>overwrite</I>
|
|
|
|
is nonzero;
|
|
if
|
|
<I>overwrite</I>
|
|
|
|
is zero, then the value of
|
|
<I>name</I>
|
|
|
|
is not changed (and
|
|
<B>setenv</B>()
|
|
|
|
returns a success status).
|
|
This function makes copies of the strings pointed to by
|
|
<I>name</I>
|
|
|
|
and
|
|
<I>value</I>
|
|
|
|
(by contrast with
|
|
<B><A HREF="/cgi-bin/man/man2html?3+putenv">putenv</A></B>(3)).
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>unsetenv</B>()
|
|
|
|
function deletes the variable
|
|
<I>name</I>
|
|
|
|
from
|
|
the environment.
|
|
If
|
|
<I>name</I>
|
|
|
|
does not exist in the environment,
|
|
then the function succeeds, and the environment is unchanged.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The
|
|
<B>setenv</B>()
|
|
|
|
function returns zero on success,
|
|
or -1 on error, with
|
|
<I>errno</I>
|
|
|
|
set to indicate the cause of the error.
|
|
<P>
|
|
|
|
The
|
|
<B>unsetenv</B>()
|
|
|
|
function returns zero on success,
|
|
or -1 on error, with
|
|
<I>errno</I>
|
|
|
|
set to indicate the cause of the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="2"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>name</I>
|
|
|
|
is NULL, points to a string of length 0,
|
|
or contains an '=' character.
|
|
<DT id="3"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Insufficient memory to add a new variable to the 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>setenv</B>(),
|
|
|
|
<B>unsetenv</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, 4.3BSD.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
POSIX.1 does not require
|
|
<B>setenv</B>()
|
|
|
|
or
|
|
<B>unsetenv</B>()
|
|
|
|
to be reentrant.
|
|
<P>
|
|
|
|
Prior to glibc 2.2.2,
|
|
<B>unsetenv</B>()
|
|
|
|
was prototyped
|
|
as returning
|
|
<I>void</I>;
|
|
|
|
more recent glibc versions follow the
|
|
POSIX.1-compliant prototype shown in the SYNOPSIS.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
POSIX.1 specifies that if
|
|
<I>name</I>
|
|
|
|
contains an '=' character, then
|
|
<B>setenv</B>()
|
|
|
|
should fail with the error
|
|
<B>EINVAL</B>;
|
|
|
|
however, versions of glibc before 2.3.4 allowed an '=' sign in
|
|
<I>name</I>.
|
|
|
|
<A NAME="lbAK"> </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+putenv">putenv</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+environ">environ</A></B>(7)
|
|
|
|
<A NAME="lbAL"> </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="4"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="9"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAJ">BUGS</A><DD>
|
|
<DT id="13"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="14"><A HREF="#lbAL">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:56 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|