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

249 lines
10 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>confstr</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="confstr"></a> <a name="tag_03_83"></a><!-- confstr -->
<!--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_83_01"></a>NAME</h4>
<blockquote>confstr - get configurable variables</blockquote>
<h4><a name="tag_03_83_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br>
<br>
size_t confstr(int</tt> <i>name</i><tt>, char *</tt><i>buf</i><tt>, size_t</tt> <i>len</i><tt>);<br>
</tt></code></p>
</blockquote>
<h4><a name="tag_03_83_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>confstr</i>() function shall return configuration-defined string values. Its use and purpose are similar to <a href=
"../functions/sysconf.html"><i>sysconf</i>()</a>, but it is used where string values rather than numeric values are returned.</p>
<p>The <i>name</i> argument represents the system variable to be queried. The implementation shall support the following name
values, defined in <a href="../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a>. It may support others:</p>
<p><br>
_CS_PATH<br>
_CS_POSIX_V6_ILP32_OFF32_CFLAGS<br>
_CS_POSIX_V6_ILP32_OFF32_LDFLAGS<br>
_CS_POSIX_V6_ILP32_OFF32_LIBS<br>
_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS<br>
_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS<br>
_CS_POSIX_V6_ILP32_OFFBIG_LIBS<br>
_CS_POSIX_V6_LP64_OFF64_CFLAGS<br>
_CS_POSIX_V6_LP64_OFF64_LDFLAGS<br>
_CS_POSIX_V6_LP64_OFF64_LIBS<br>
_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS<br>
_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS<br>
_CS_POSIX_V6_LPBIG_OFFBIG_LIBS<br>
_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS<br>
<sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"><br>
_CS_XBS5_ILP32_OFF32_CFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_ILP32_OFF32_LDFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_ILP32_OFF32_LIBS (<b>LEGACY</b>)<br>
_CS_XBS5_ILP32_OFF32_LINTFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_ILP32_OFFBIG_CFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_ILP32_OFFBIG_LDFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_ILP32_OFFBIG_LIBS (<b>LEGACY</b>)<br>
_CS_XBS5_ILP32_OFFBIG_LINTFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_LP64_OFF64_CFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_LP64_OFF64_LDFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_LP64_OFF64_LIBS (<b>LEGACY</b>)<br>
_CS_XBS5_LP64_OFF64_LINTFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_LPBIG_OFFBIG_CFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_LPBIG_OFFBIG_LDFLAGS (<b>LEGACY</b>)<br>
_CS_XBS5_LPBIG_OFFBIG_LIBS (<b>LEGACY</b>)<br>
_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS (<b>LEGACY</b>)<br>
<img src="../images/opt-end.gif" alt="[Option End]" border="0"><br>
</p>
<p>If <i>len</i> is not 0, and if <i>name</i> has a configuration-defined value, <i>confstr</i>() shall copy that value into the
<i>len</i>-byte buffer 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>() shall truncate the string to <i>len</i>-1 bytes and null-terminate the result. The
application can detect that the string was truncated by comparing the value returned by <i>confstr</i>() with <i>len</i>.</p>
<p>If <i>len</i> is 0 and <i>buf</i> is a null pointer, then <i>confstr</i>() shall still return the integer value as defined
below, but shall not return a string. If <i>len</i> is 0 but <i>buf</i> is not a null pointer, the result is unspecified.</p>
<p>If the implementation supports the POSIX shell option, the string stored in <i>buf</i> after a call to:</p>
<pre>
<tt>confstr(_CS_PATH, buf, sizeof(buf))
</tt>
</pre>
<p>can be used as a value of the <i>PATH</i> environment variable that accesses all of the standard utilities of
IEEE&nbsp;Std&nbsp;1003.1-2001, if the return value is less than or equal to <i>sizeof</i>( <i>buf</i>).</p>
</blockquote>
<h4><a name="tag_03_83_04"></a>RETURN VALUE</h4>
<blockquote>
<p>If <i>name</i> has a configuration-defined value, <i>confstr</i>() shall return the size of buffer that would be needed to hold
the entire configuration-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>
<p>If <i>name</i> is invalid, <i>confstr</i>() shall return 0 and set <i>errno</i> to indicate the error.</p>
<p>If <i>name</i> does not have a configuration-defined value, <i>confstr</i>() shall return 0 and leave <i>errno</i>
unchanged.</p>
</blockquote>
<h4><a name="tag_03_83_05"></a>ERRORS</h4>
<blockquote>
<p>The <i>confstr</i>() function shall fail if:</p>
<dl compact>
<dt>[EINVAL]</dt>
<dd>The value of the <i>name</i> argument is invalid.</dd>
</dl>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_83_06"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_83_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>An application can distinguish between an invalid <i>name</i> parameter value and one that corresponds to a configurable
variable that has no configuration-defined value by checking if <i>errno</i> is modified. This mirrors the behavior of <a href=
"../functions/sysconf.html"><i>sysconf</i>()</a>.</p>
<p>The original need for this function was to provide a way of finding the configuration-defined default value for the environment
variable <i>PATH .</i> Since <i>PATH</i> can be modified by the user to include directories that could contain utilities replacing
the standard utilities in the Shell and Utilities volume of IEEE&nbsp;Std&nbsp;1003.1-2001, applications need a way to determine
the system-supplied <i>PATH</i> environment variable value that contains the correct search path for the standard utilities.</p>
<p>An application could use:</p>
<pre>
<tt>confstr(name, (char *)NULL, (size_t)0)
</tt>
</pre>
<p>to find out how big a buffer is needed for the string value; use <a href="../functions/malloc.html"><i>malloc</i>()</a> 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 to hold most answers (perhaps 512 or 1024 bytes), but then use <a href=
"../functions/malloc.html"><i>malloc</i>()</a> to allocate a larger buffer if it finds that this is too small.</p>
</blockquote>
<h4><a name="tag_03_83_08"></a>RATIONALE</h4>
<blockquote>
<p>Application developers can normally determine any configuration variable by means of reading from the stream opened by a call
to:</p>
<pre>
<tt>popen("command -p getconf variable", "r");
</tt>
</pre>
<p>The <i>confstr</i>() function with a <i>name</i> argument of _CS_PATH returns a string that can be used as a <i>PATH</i>
environment variable setting that will reference the standard shell and utilities as described in the Shell and Utilities volume of
IEEE&nbsp;Std&nbsp;1003.1-2001.</p>
<p>The <i>confstr</i>() function copies the returned string into a buffer supplied by the application instead of returning a
pointer to a string. This allows a cleaner function in some implementations (such as those with lightweight threads) and resolves
questions about when the application must copy the string returned.</p>
</blockquote>
<h4><a name="tag_03_83_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_83_10"></a>SEE ALSO</h4>
<blockquote>
<p><a href="pathconf.html"><i>pathconf</i>()</a> , <a href="sysconf.html"><i>sysconf</i>()</a> , the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/unistd.h.html"><i>&lt;unistd.h&gt;</i></a>, the Shell and Utilities volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../utilities/c99.html"><i>c99</i></a></p>
</blockquote>
<h4><a name="tag_03_83_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4. Derived from the ISO&nbsp;POSIX-2 standard.</p>
</blockquote>
<h4><a name="tag_03_83_12"></a>Issue 5</h4>
<blockquote>
<p>A table indicating the permissible values of <i>name</i> is added to the DESCRIPTION. All those marked EX are new in this
issue.</p>
</blockquote>
<h4><a name="tag_03_83_13"></a>Issue 6</h4>
<blockquote>
<p>The Open Group Corrigendum U033/7 is applied. The return value for the case returning the size of the buffer now explicitly
states that this includes the terminating null.</p>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The DESCRIPTION is updated with new arguments which can be used to determine configuration strings for C compiler flags,
linker/loader flags, and libraries for each different supported programming environment. This is a change to support data size
neutrality.</p>
</li>
</ul>
<p>The following changes were made to align with the IEEE&nbsp;P1003.1a draft standard:</p>
<ul>
<li>
<p>The DESCRIPTION is updated to include text describing how _CS_PATH can be used to obtain a <i>PATH</i> to access the standard
utilities.</p>
</li>
</ul>
<p>The macros associated with the <i>c89</i> programming models are marked LEGACY and new equivalent macros associated with <a
href="../utilities/c99.html"><i>c99</i></a> are introduced.</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>