⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 putenv.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 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-2003 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, 2003 Edition<br>Copyright &copy; 2001-2003 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> argumentshould point to a string of the form " <i>name</i>= <i>value</i> ". The <i>putenv</i>() function shall make the value of theenvironment variable <i>name</i> equal to <i>value</i> by altering an existing variable or creating a new one. In either case, thestring pointed to by <i>string</i> shall become part of the environment, so altering the string shall change the environment. Thespace used by <i>string</i> is no longer used once a new string which defines <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 bethread-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> toindicate 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 <ahref="../functions/getenv.html"><i>getenv</i>()</a>.</p><p>See <a href="exec.html"><i><a href="../functions/exec.html">exec</a></i>()</a> , for restrictions on changing the environment inmulti-threaded applications.</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 functionwhile <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 permittingmemory 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> , <ahref="malloc.html"><i>malloc</i>()</a> , <a href="setenv.html"><i>setenv</i>()</a> , the Base Definitions volume ofIEEE&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 FUTUREDIRECTION in previous issues.</p><p>A note indicating that this function need not be reentrant is added to the DESCRIPTION.</p></blockquote><h4><a name="tag_03_583_13"></a>Issue 6</h4><blockquote><p>IEEE&nbsp;Std 1003.1-2001/Cor&nbsp;1-2002, item XSH/TC1/D6/48 is applied, clarifying wording in the DESCRIPTION and adding a newparagraph into APPLICATION USAGE referring readers to <i><a href="../functions/exec.html">exec</a></i>.</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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -