📄 confstr.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>confstr</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_002_005"> </a>NAME</h4><blockquote>confstr - get configurable variables</blockquote><h4><a name = "tag_000_002_006"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="unistd.h.html">unistd.h</a>>size_t confstr(int <i>name</i>, char *<i>buf</i>, size_t <i>len</i>);</code></pre></blockquote><h4><a name = "tag_000_002_007"> </a>DESCRIPTION</h4><blockquote>The<i>confstr()</i>function provides a method for applicationsto get configuration-defined string values.Its use and purpose are similar to<i><a href="sysconf.html">sysconf()</a></i>,but it is used where string values rather than numeric values are returned.<p>The<i>name</i>argument represents the system variable to bequeried.The implementation supports the following name values,defined in<i><a href="unistd.h.html"><unistd.h></a></i>.It may support others:<p><pre>_CS_PATH_CS_XBS5_ILP32_OFF32_CFLAGS_CS_XBS5_ILP32_OFF32_LDFLAGS_CS_XBS5_ILP32_OFF32_LIBS_CS_XBS5_ILP32_OFF32_LINTFLAGS_CS_XBS5_ILP32_OFFBIG_CFLAGS_CS_XBS5_ILP32_OFFBIG_LDFLAGS_CS_XBS5_ILP32_OFFBIG_LIBS_CS_XBS5_ILP32_OFFBIG_LINTFLAGS_CS_XBS5_LP64_OFF64_CFLAGS_CS_XBS5_LP64_OFF64_LDFLAGS_CS_XBS5_LP64_OFF64_LIBS_CS_XBS5_LP64_OFF64_LINTFLAGS_CS_XBS5_LPBIG_OFFBIG_CFLAGS_CS_XBS5_LPBIG_OFFBIG_LDFLAGS_CS_XBS5_LPBIG_OFFBIG_LIBS_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS</pre><p>If<i>len</i>is not 0, and if<i>name</i>has a configuration-defined value,<i>confstr()</i>copies that value into the<i>len</i>-bytebuffer pointed to by<i>buf</i>.If the string to be returned is longer than<i>len</i>bytes, including the terminating null, then<i>confstr()</i>truncates the string to<i>len</i>-1bytes and null-terminates the result.The application can detect that the string was truncated bycomparing the value returned by<i>confstr()</i>with<i>len</i>.<p>If<i>len</i>is 0 and<i>buf</i>is a null pointer, then<i>confstr()</i>still returns the integer value as defined below, but does notreturn a string.If<i>len</i>is 0 but<i>buf</i>is not a null pointer, the result is unspecified.</blockquote><h4><a name = "tag_000_002_008"> </a>RETURN VALUE</h4><blockquote>If<i>name</i>has a configuration-defined value,<i>confstr()</i>returnsthe size of buffer that would be needed to hold the entireconfiguration-defined value including the terminating null.If this return value is greater than<i>len</i>,the string returned in<i>buf</i>is truncated.<p>If<i>name</i>is invalid,<i>confstr()</i>returns 0 and sets<i>errno</i>to indicate the error.<p>If<i>name</i>does not have a configuration-defined value,<i>confstr()</i>returns 0 and leaves<i>errno</i>unchanged.<br></blockquote><h4><a name = "tag_000_002_009"> </a>ERRORS</h4><blockquote>The<i>confstr()</i>function will fail if:<dl compact><dt>[EINVAL]<dd>The value of the<i>name</i>argument is invalid.</dl></blockquote><h4><a name = "tag_000_002_010"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_002_011"> </a>APPLICATION USAGE</h4><blockquote>An application can distinguish between an invalid<i>name</i>parametervalue and one that corresponds to a configurable variable that hasno configuration-defined value by checking if<i>errno</i>is modified.This mirrors the behaviour of<i><a href="sysconf.html">sysconf()</a></i>.<p>The original need for this function was to provide a way offinding the configuration-defined default value for theenvironment variable<i>PATH</i>.Since<i>PATH</i>can be modified by theuser to include directories that could contain utilitiesreplacing <b>XCU</b> specification standard utilities, applications need a wayto determine the system-supplied<i>PATH</i>environment variablevalue that contains the correct search path for thestandard utilities.<p>An application could use:<pre><code>confstr(name, (char *)NULL, (size_t)0)</code></pre><p>to find out how big a buffer is needed for the string value; use<i><a href="malloc.html">malloc()</a></i>to allocate a buffer to hold the string; and call<i>confstr()</i>again to get the string.Alternately, it could allocate a fixed, static buffer that is big enough tohold most answers (perhaps 512 or 1024 bytes), but then use<i><a href="malloc.html">malloc()</a></i>to allocate a larger buffer if it finds that this is too small.</blockquote><h4><a name = "tag_000_002_012"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_002_013"> </a>SEE ALSO</h4><blockquote><i><a href="pathconf.html">pathconf()</a></i>,<i><a href="sysconf.html">sysconf()</a></i>,<i><a href="unistd.h.html"><unistd.h></a></i>,the <b>XCU</b> specification of <i><a href="../xcu/getconf.html">getconf</a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from the ISO POSIX-2 standard.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -