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

📄 setenv.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>setenv</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="setenv"></a> <a name="tag_03_647"></a><!-- setenv --> <!--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_647_01"></a>NAME</h4><blockquote>setenv - add or change environment variable</blockquote><h4><a name="tag_03_647_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('CX')">CX</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 setenv(const char *</tt><i>envname</i><tt>, const char *</tt><i>envval</i><tt>, int</tt> <i>overwrite</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_647_03"></a>DESCRIPTION</h4><blockquote><p>The <i>setenv</i>() function shall update or add a variable in the environment of the calling process. The <i>envname</i>argument points to a string containing the name of an environment variable to be added or altered. The environment variable shallbe set to the value to which <i>envval</i> points. The function shall fail if <i>envname</i> points to a string which contains an<tt>'='</tt> character. If the environment variable named by <i>envname</i> already exists and the value of <i>overwrite</i> isnon-zero, the function shall return success and the environment shall be updated. If the environment variable named by<i>envname</i> already exists and the value of <i>overwrite</i> is zero, the function shall return success and the environmentshall remain unchanged.</p><p>If the application modifies <i>environ</i> or the pointers to which it points, the behavior of <i>setenv</i>() is undefined. The<i>setenv</i>() function shall update the list of pointers to which <i>environ</i> points.</p><p>The strings described by <i>envname</i> and <i>envval</i> are copied by this function.</p><p>The <i>setenv</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_647_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, zero shall be returned. Otherwise, -1 shall be returned, <i>errno</i> set to indicate the error, andthe environment shall be unchanged.</p></blockquote><h4><a name="tag_03_647_05"></a>ERRORS</h4><blockquote><p>The <i>setenv</i>() function shall fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The <i>name</i> argument is a null pointer, points to an empty string, or points to a string containing an <tt>'='</tt>character.</dd><dt>[ENOMEM]</dt><dd>Insufficient memory was available to add a variable or its value to the environment.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_647_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_647_07"></a>APPLICATION USAGE</h4><blockquote><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></blockquote><h4><a name="tag_03_647_08"></a>RATIONALE</h4><blockquote><p>Unanticipated results may occur if <i>setenv</i>() changes the external variable <i>environ</i>. In particular, if the optional<i>envp</i> argument to <i>main</i>() is present, it is not changed, and thus may point to an obsolete copy of the environment (asmay any other copy of <i>environ</i>). However, other than the aforementioned restriction, the developers ofIEEE&nbsp;Std&nbsp;1003.1-2001 intended that the traditional method of walking through the environment by way of the <i>environ</i>pointer must be supported.</p><p>It was decided that <i>setenv</i>() should be required by this revision because it addresses a piece of missing functionality,and does not impose a significant burden on the implementor.</p><p>There was considerable debate as to whether the System V <a href="../functions/putenv.html"><i>putenv</i>()</a> function or theBSD <i>setenv</i>() function should be required as a mandatory function. The <i>setenv</i>() function was chosen because itpermitted the implementation of the <a href="../functions/unsetenv.html"><i>unsetenv</i>()</a> function to delete environmentalvariables, without specifying an additional interface. The <a href="../functions/putenv.html"><i>putenv</i>()</a> function isavailable as an XSI extension.</p><p>The standard developers considered requiring that <i>setenv</i>() indicate an error when a call to it would result in exceeding{ARG_MAX}. The requirement was rejected since the condition might be temporary, with the application eventually reducing theenvironment size. The ultimate success or failure depends on the size at the time of a call to <i><a href="../functions/exec.html">exec</a></i>, which returns an indication of this error condition.</p></blockquote><h4><a name="tag_03_647_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_647_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="unsetenv.html"><i>unsetenv</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>, <a href="../basedefs/sys/types.h.html"><i>&lt;sys/types.h&gt;</i></a>, <ahref="../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a></p></blockquote><h4><a name="tag_03_647_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 6. Derived from the IEEE&nbsp;P1003.1a draft standard.</p><p>IEEE&nbsp;Std 1003.1-2001/Cor&nbsp;1-2002, item XSH/TC1/D6/55 is applied, adding references to <i><a href="../functions/exec.html">exec</a></i> in the APPLICATION USAGE and SEE ALSO sections.</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 + -