📄 library_27.html
字号:
See section <A HREF="library_27.html#SEC466" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_27.html#SEC466">Using <CODE>pathconf</CODE></A>.
<P>
<H2><A NAME="SEC465" HREF="library_toc.html#SEC465" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC465">Minimum Values for File System Limits</A></H2>
<P>
Here are the names for the POSIX minimum upper bounds for some of the
above parameters. The significance of these values is that you can
safely push to these limits without checking whether the particular
system you are using can go that far.
<P>
<DL COMPACT>
<DT><CODE>_POSIX_LINK_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX for the maximum value of a
file's link count. The value of this constant is <CODE>8</CODE>; thus, you
can always make up to eight names for a file without running into a
system limit.
<P>
<DT><CODE>_POSIX_MAX_CANON</CODE>
<DD>The most restrictive limit permitted by POSIX for the maximum number of
bytes in a canonical input line from a terminal device. The value of
this constant is <CODE>255</CODE>.
<P>
<DT><CODE>_POSIX_MAX_INPUT</CODE>
<DD>The most restrictive limit permitted by POSIX for the maximum number of
bytes in a terminal device input queue (or typeahead buffer).
See section <A HREF="library_16.html#SEC276" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC276">Input Modes</A>. The value of this constant is <CODE>255</CODE>.
<P>
<DT><CODE>_POSIX_NAME_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX for the maximum number of
bytes in a file name component. The value of this constant is
<CODE>14</CODE>.
<P>
<DT><CODE>_POSIX_PATH_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX for the maximum number of
bytes in a file name. The value of this constant is <CODE>255</CODE>.
<P>
<DT><CODE>_POSIX_PIPE_BUF</CODE>
<DD>The most restrictive limit permitted by POSIX for the maximum number of
bytes that can be written atomically to a pipe. The value of this
constant is <CODE>512</CODE>.
</DL>
<P>
<H2><A NAME="SEC466" HREF="library_toc.html#SEC466" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC466">Using <CODE>pathconf</CODE></A></H2>
<P>
When your machine allows different files to have different values for a
file system parameter, you can use the functions in this section to find
out the value that applies to any particular file.
<P>
These functions and the associated constants for the <VAR>parameter</VAR>
argument are declared in the header file <TT>`unistd.h'</TT>.
<P>
<A NAME="IDX1905"></A>
<U>Function:</U> long int <B>pathconf</B> <I>(const char *<VAR>filename</VAR>, int <VAR>parameter</VAR>)</I><P>
This function is used to inquire about the limits that apply to
the file named <VAR>filename</VAR>.
<P>
The <VAR>parameter</VAR> argument should be one of the <SAMP>`_PC_'</SAMP> constants
listed below.
<P>
The normal return value from <CODE>pathconf</CODE> is the value you requested.
A value of <CODE>-1</CODE> is returned both if the implementation does not
impose a limit, and in case of an error. In the former case,
<CODE>errno</CODE> is not set, while in the latter case, <CODE>errno</CODE> is set
to indicate the cause of the problem. So the only way to use this
function robustly is to store <CODE>0</CODE> into <CODE>errno</CODE> just before
calling it.
<P>
Besides the usual file name syntax errors (see section <A HREF="library_10.html#SEC115" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_10.html#SEC115">File Name Errors</A>),
the following error condition is defined for this function:
<P>
<DL COMPACT>
<DT><CODE>EINVAL</CODE>
<DD>The value of <VAR>parameter</VAR> is invalid, or the implementation doesn't
support the <VAR>parameter</VAR> for the specific file.
</DL>
<P>
<A NAME="IDX1906"></A>
<U>Function:</U> long int <B>fpathconf</B> <I>(int <VAR>filedes</VAR>, int <VAR>parameter</VAR>)</I><P>
This is just like <CODE>pathconf</CODE> except that an open file descriptor
is used to specify the file for which information is requested, instead
of a file name.
<P>
The following <CODE>errno</CODE> error conditions are defined for this function:
<P>
<DL COMPACT>
<DT><CODE>EBADF</CODE>
<DD>The <VAR>filedes</VAR> argument is not a valid file descriptor.
<P>
<DT><CODE>EINVAL</CODE>
<DD>The value of <VAR>parameter</VAR> is invalid, or the implementation doesn't
support the <VAR>parameter</VAR> for the specific file.
</DL>
<P>
Here are the symbolic constants that you can use as the <VAR>parameter</VAR>
argument to <CODE>pathconf</CODE> and <CODE>fpathconf</CODE>. The values are all
integer constants.
<P>
<DL COMPACT>
<DT><CODE>_PC_LINK_MAX</CODE>
<DD>Inquire about the parameter corresponding to <CODE>LINK_MAX</CODE>.
<P>
<DT><CODE>_PC_MAX_CANON</CODE>
<DD>Inquire about the parameter corresponding to <CODE>MAX_CANON</CODE>.
<P>
<DT><CODE>_PC_MAX_INPUT</CODE>
<DD>Inquire about the parameter corresponding to <CODE>MAX_INPUT</CODE>.
<P>
<DT><CODE>_PC_NAME_MAX</CODE>
<DD>Inquire about the parameter corresponding to <CODE>NAME_MAX</CODE>.
<P>
<DT><CODE>_PC_PATH_MAX</CODE>
<DD>Inquire about the parameter corresponding to <CODE>PATH_MAX</CODE>.
<P>
<DT><CODE>_PC_PIPE_BUF</CODE>
<DD>Inquire about the parameter corresponding to <CODE>PIPE_BUF</CODE>.
<P>
<DT><CODE>_PC_CHOWN_RESTRICTED</CODE>
<DD>Inquire about the parameter corresponding to <CODE>_POSIX_CHOWN_RESTRICTED</CODE>.
<P>
<DT><CODE>_PC_NO_TRUNC</CODE>
<DD>Inquire about the parameter corresponding to <CODE>_POSIX_NO_TRUNC</CODE>.
<P>
<DT><CODE>_PC_VDISABLE</CODE>
<DD>Inquire about the parameter corresponding to <CODE>_POSIX_VDISABLE</CODE>.
</DL>
<P>
<H2><A NAME="SEC467" HREF="library_toc.html#SEC467" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC467">Utility Program Capacity Limits</A></H2>
<P>
The POSIX.2 standard specifies certain system limits that you can access
through <CODE>sysconf</CODE> that apply to utility behavior rather than the
behavior of the library or the operating system.
<P>
The GNU C library defines macros for these limits, and <CODE>sysconf</CODE>
returns values for them if you ask; but these values convey no
meaningful information. They are simply the smallest values that
POSIX.2 permits.
<P>
<A NAME="IDX1907"></A>
<U>Macro:</U> int <B>BC_BASE_MAX</B><P>
The largest value of <CODE>obase</CODE> that the <CODE>bc</CODE> utility is
guaranteed to support.
<P>
<A NAME="IDX1908"></A>
<U>Macro:</U> int <B>BC_SCALE_MAX</B><P>
The largest value of <CODE>scale</CODE> that the <CODE>bc</CODE> utility is
guaranteed to support.
<P>
<A NAME="IDX1909"></A>
<U>Macro:</U> int <B>BC_DIM_MAX</B><P>
The largest number of elements in one array that the <CODE>bc</CODE> utility
is guaranteed to support.
<P>
<A NAME="IDX1910"></A>
<U>Macro:</U> int <B>BC_STRING_MAX</B><P>
The largest number of characters in one string constant that the
<CODE>bc</CODE> utility is guaranteed to support.
<P>
<A NAME="IDX1911"></A>
<U>Macro:</U> int <B>BC_DIM_MAX</B><P>
The largest number of elements in one array that the <CODE>bc</CODE> utility
is guaranteed to support.
<P>
<A NAME="IDX1912"></A>
<U>Macro:</U> int <B>COLL_WEIGHTS_MAX</B><P>
The largest number of weights that can necessarily be used in defining
the collating sequence for a locale.
<P>
<A NAME="IDX1913"></A>
<U>Macro:</U> int <B>EXPR_NEST_MAX</B><P>
The maximum number of expressions that can be nested within parenthesis
by the <CODE>expr</CODE> utility.
<P>
<A NAME="IDX1914"></A>
<U>Macro:</U> int <B>LINE_MAX</B><P>
The largest text line that the text-oriented POSIX.2 utilities can
support. (If you are using the GNU versions of these utilities, then
there is no actual limit except that imposed by the available virtual
memory, but there is no way that the library can tell you this.)
<P>
<H2><A NAME="SEC468" HREF="library_toc.html#SEC468" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC468">Minimum Values for Utility Limits</A></H2>
<P>
<DL COMPACT>
<DT><CODE>_POSIX2_BC_BASE_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX.2 for the maximum value of
<CODE>obase</CODE> in the <CODE>bc</CODE> utility. Its value is <CODE>99</CODE>.
<P>
<DT><CODE>_POSIX2_BC_DIM_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX.2 for the maximum size of
an array in the <CODE>bc</CODE> utility. Its value is <CODE>2048</CODE>.
<P>
<DT><CODE>_POSIX2_BC_SCALE_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX.2 for the maximum value of
<CODE>scale</CODE> in the <CODE>bc</CODE> utility. Its value is <CODE>99</CODE>.
<P>
<DT><CODE>_POSIX2_BC_STRING_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX.2 for the maximum size of
a string constant in the <CODE>bc</CODE> utility. Its value is <CODE>1000</CODE>.
<P>
<DT><CODE>_POSIX2_COLL_WEIGHTS_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX.2 for the maximum number
of weights that can necessarily be used in defining the collating
sequence for a locale. Its value is <CODE>2</CODE>.
<P>
<DT><CODE>_POSIX2_EXPR_NEST_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX.2 for the maximum number
of expressions nested within parenthesis when using the <CODE>expr</CODE> utility.
Its value is <CODE>32</CODE>.
<P>
<DT><CODE>_POSIX2_LINE_MAX</CODE>
<DD>The most restrictive limit permitted by POSIX.2 for the maximum size of
a text line that the text utilities can handle. Its value is
<CODE>2048</CODE>.
</DL>
<P>
<H2><A NAME="SEC469" HREF="library_toc.html#SEC469" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC469">String-Valued Parameters</A></H2>
<P>
POSIX.2 defines a way to get string-valued parameters from the operating
system with the function <CODE>confstr</CODE>:
<P>
<A NAME="IDX1915"></A>
<U>Function:</U> size_t <B>confstr</B> <I>(int <VAR>parameter</VAR>, char *<VAR>buf</VAR>, size_t <VAR>len</VAR>)</I><P>
This function reads the value of a string-valued system parameter,
storing the string into <VAR>len</VAR> bytes of memory space starting at
<VAR>buf</VAR>. The <VAR>parameter</VAR> argument should be one of the
<SAMP>`_CS_'</SAMP> symbols listed below.
<P>
The normal return value from <CODE>confstr</CODE> is the length of the string
value that you asked for. If you supply a null pointer for <VAR>buf</VAR>,
then <CODE>confstr</CODE> does not try to store the string; it just returns
its length. A value of <CODE>0</CODE> indicates an error.
<P>
If the string you asked for is too long for the buffer (that is, longer
than <CODE><VAR>len</VAR> - 1</CODE>), then <CODE>confstr</CODE> stores just that much
(leaving room for the terminating null character). You can tell that
this has happened because <CODE>confstr</CODE> returns a value greater than or
equal to <VAR>len</VAR>.
<P>
The following <CODE>errno</CODE> error conditions are defined for this function:
<P>
<DL COMPACT>
<DT><CODE>EINVAL</CODE>
<DD>The value of the <VAR>parameter</VAR> is invalid.
</DL>
<P>
Currently there is just one parameter you can read with <CODE>confstr</CODE>:
<P>
<DL COMPACT>
<DT><CODE>_CS_PATH</CODE>
<DD>This parameter's value is the recommended default path for searching for
executable files. This is the path that a user has by default just
after logging in.
</DL>
<P>
The way to use <CODE>confstr</CODE> without any arbitrary limit on string size
is to call it twice: first call it to get the length, allocate the
buffer accordingly, and then call <CODE>confstr</CODE> again to fill the
buffer, like this:
<P>
<PRE>
char *
get_default_path (void)
{
size_t len = confstr (_CS_PATH, NULL, 0);
char *buffer = (char *) xmalloc (len);
if (confstr (_CS_PATH, buf, len + 1) == 0)
{
free (buffer);
return NULL;
}
return buffer;
}
</PRE>
<P>Go to the <A HREF="library_26.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_26.html">previous</A>, <A HREF="library_28.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_28.html">next</A> section.<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -