ptg10805159
42 UNIX Standardization and Implementations Chapter 2
2.5.4 sysconf, pathconf,and fpathconf Functions
We’ve listed various minimum values that an implementation must support, but how
do we find out the limits that a particular system actually supports? As we mentioned
earlier,some of these limits might be available at compile time; others must be
determined at runtime. We’ve also mentioned that some limits don’t change in a given
system, whereas others can change because they areassociated with a file or directory.
The runtime limits areobtained by calling one of the following three functions.
#include <unistd.h>
long sysconf(intname);
long pathconf(const char *pathname,intname);
long fpathconf(intfd,int name);
All three return: corresponding value if OK,−1 on error (see later)
The difference between the last two functions is that one takes a pathname as its
argument and the other takes a file descriptor argument.
Figure2.11lists thenamearguments thatsysconfuses to identify system limits.
Constants beginning with_SC_areused as arguments tosysconfto identify the
runtime limit. Figure2.12 lists thenamearguments that areused bypathconfand
fpathconfto identify system limits. Constants beginning with_PC_areused as
arguments topathconfandfpathconfto identify the runtime limit.
We need to look in moredetail at the different return values from these three
functions.
- All three functions return−1and seterrnotoEINVALif thenameisn’t one of
the appropriate constants. The thirdcolumn in Figures 2.11and 2.12 lists the
limit constants we’ll deal with throughout the rest of this book. - Somenamescan return either the value of the variable (a return value≥0) or an
indication that the value is indeterminate. An indeterminate value is indicated
by returning−1and not changing the value oferrno. - The value returned for_SC_CLK_TCKis the number of clock ticks per second,
for use with the return values from thetimesfunction (Section 8.17).
Some restrictions apply to thepathconfpathnameargument and thefpathconf
fdargument. If any of these restrictions isn’t met, the results areundefined.
- The referenced file for _PC_MAX_CANON and _PC_MAX_INPUT must be a
terminal file. - Thereferenced file for_PC_LINK_MAXand_PC_TIMESTAMP_RESOLUTIONcan
be either a file or a directory.Ifthe referenced file is a directory,the return value
applies to the directory itself, not to the filename entries within the directory. - Thereferenced file for_PC_FILESIZEBITSand_PC_NAME_MAXmust be a
directory.The return value applies to filenames within the directory.