Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/putenv.html
2024-02-19 00:21:47 -05:00

156 lines
5.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>putenv</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="putenv"></a> <a name="tag_03_583"></a><!-- putenv -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_583_01"></a>NAME</h4>
<blockquote>putenv - change or add a value to an environment</blockquote>
<h4><a name="tag_03_583_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> #include &lt;<a href="../basedefs/stdlib.h.html">stdlib.h</a>&gt;<br>
<br>
int putenv(char *</tt><i>string</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_03_583_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>putenv</i>() function shall use the <i>string</i> argument to set environment variable values. The <i>string</i> argument
should point to a string of the form " <i>name</i>= <i>value</i>. The <i>putenv</i>() function shall make the value of the
environment variable <i>name</i> equal to <i>value</i> by altering an existing variable or creating a new one. In either case, the
string pointed to by <i>string</i> shall become part of the environment, so altering the string shall change the environment. The
space used by <i>string</i> is no longer used once a new string-defining <i>name</i> is passed to <i>putenv</i>().</p>
<p>The <i>putenv</i>() function need not be reentrant. A function that is not required to be reentrant is not required to be
thread-safe.</p>
</blockquote>
<h4><a name="tag_03_583_04"></a>RETURN VALUE</h4>
<blockquote>
<p>Upon successful completion, <i>putenv</i>() shall return 0; otherwise, it shall return a non-zero value and set <i>errno</i> to
indicate the error.</p>
</blockquote>
<h4><a name="tag_03_583_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>putenv</i>() function may fail if:</p>
<dl compact>
<dt>[ENOMEM]</dt>
<dd>Insufficient memory was available.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_583_06"></a>EXAMPLES</h4>
<blockquote>
<h5><a name="tag_03_583_06_01"></a>Changing the Value of an Environment Variable</h5>
<p>The following example changes the value of the <i>HOME</i> environment variable to the value <b>/usr/home</b>.</p>
<pre>
<tt>#include &lt;stdlib.h&gt;
...
static char *var = "HOME=/usr/home";
int ret;
<br>
ret = putenv(var);
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_583_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>The <i>putenv</i>() function manipulates the environment pointed to by <i>environ</i>, and can be used in conjunction with <a
href="../functions/getenv.html"><i>getenv</i>()</a>.</p>
<p>This routine may use <a href="../functions/malloc.html"><i>malloc</i>()</a> to enlarge the environment.</p>
<p>A potential error is to call <i>putenv</i>() with an automatic variable as the argument, then return from the calling function
while <i>string</i> is still part of the environment.</p>
<p>The <a href="../functions/setenv.html"><i>setenv</i>()</a> function is preferred over this function.</p>
</blockquote>
<h4><a name="tag_03_583_08"></a>RATIONALE</h4>
<blockquote>
<p>The standard developers noted that <i>putenv</i>() is the only function available to add to the environment without permitting
memory leaks.</p>
</blockquote>
<h4><a name="tag_03_583_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_583_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="exec.html"><i><a href="../functions/exec.html">exec</a></i>()</a> , <a href="getenv.html"><i>getenv</i>()</a> , <a
href="malloc.html"><i>malloc</i>()</a> , <a href="setenv.html"><i>setenv</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/stdlib.h.html"><i>&lt;stdlib.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_583_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
</blockquote>
<h4><a name="tag_03_583_12"></a>Issue 5</h4>
<blockquote>
<p>The type of the argument to this function is changed from <b>const char *</b> to <b>char *</b>. This was indicated as a FUTURE
DIRECTION in previous issues.</p>
<p>A note indicating that this function need not be reentrant is added to the DESCRIPTION.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>