Standards
Standards / Extensions |
C or C++ |
Dependencies |
POSIX.1a
XPG4
XPG4.2
Single UNIX Specification, Version 3
|
both |
|
Format
#define _POSIX_SOURCE
#include <unistd.h>
long pathconf(const char *pathname, int varcode);
General description
Lets an
application determine the value of a configuration variable, varcode,
associated with a particular file or directory, pathname.
The
varcode argument
may be any one of the following symbols, defined in the unistd.h header
file, each standing for a configuration variable:
- _PC_LINK_MAX
- Represents LINK_MAX, the maximum number of links the file can
have. If pathname is a directory, pathconf()
returns the maximum number of links that can be established to the
directory itself.
- _PC_MAX_CANON
- Represents MAX_CANON, the maximum number of bytes in a terminal
canonical input line. pathname must refer
to a character special file for a terminal.
- _PC_MAX_INPUT
- Represents MAX_INPUT, the maximum number of bytes for which space
is available in a terminal input queue. That is, it refers to the
maximum number of bytes that a portable application can have the user
enter before the application actually reads the input. pathname must
refer to a character special file for a terminal.
- _PC_NAME_MAX
- Represents NAME_MAX, the maximum number of characters in a file
name (not including any terminating NULL at the end if the file name
is stored as a string). This symbol refers only to the file name itself,
that is, the last component of the file's path name. pathconf() returns
the maximum length of file names.
- _PC_PATH_MAX
- Represents PATH_MAX, the maximum number of characters in a complete
path name (not including any terminating NULL at the end if the path
name is stored as a string). pathconf() returns the maximum length
of a relative path name.
- _PC_PIPE_BUF
- Represents PIPE_BUF, the maximum number of bytes that can be written
“atomically” to a pipe. If more than this number of bytes is written
to a pipe, the operation may take more than one physical write operation
and physical read operation to read the data on the other end of the
pipe. If pathname is a FIFO special file,
pathconf() returns the value for the file itself. If pathname is
a directory, pathconf() returns the value for any FIFOs that exist
or that can be created under the directory. If pathname is
any other kind of file, an errno of EINVAL will be returned, indicating
an invalid path name was specified.
- _PC_CHOWN_RESTRICTED
- Represents _POSIX_CHOWN_RESTRICTED defined in the unistd.h header
file, and restricts use of chown() to a process with appropriate privileges.
It also changes the group ID of a file to the effective group ID
of the process or to one of its supplementary group IDs. If pathname is
a directory, pathconf() returns the value for any kind of file under
the directory, but not for subdirectories of the directory.
- _PC_NO_TRUNC
- Represents _POSIX_NO_TRUNC defined in the unistd.h header file,
and generates an error if a file name is longer than NAME_MAX. If pathname refers
to a directory, the value returned by pathconf() applies to all files
under that directory.
- _PC_VDISABLE
- Represents _POSIX_VDISABLE defined in the unistd.h header file.
This symbol indicates that terminal special characters can be disabled
using this character value, if it is defined; see the callable service
tcsetattr() for details. pathname must
refer to a character special file for a terminal.
- _PC_ACL
- Returns 1 if an access control mechanism is supported by the security
product.
- _PC_ACL_ENTRIES_MAX
- Returns the maximum number of ACL entries in an ACL for a file
or directory that supports ACLs.
Returned value
If successful, pathconf()
return the value of the variable requested in varcode.
If
unsuccessful, pathconf() returns -1. If a particular variable has
no limit, such as PATH_MAX, pathconf() returns -1 but does not change
errno.
If pathconf() cannot determine an appropriate value,
it sets errno to one of the following values:
- Error Code
- Description
- EACCES
- The process does not have search permission on some component
of the pathname.
- EINVAL
- varcode is not a valid variable code,
or the given variable cannot be associated with the specified file.
- If varcode refers to MAX_CANON, MAX_INPUT,
or _POSIX_VDISABLE, and pathname does not
refer to a character special file, pathconf() returns -1 and sets
errno to EINVAL.
- If varcode refers to NAME_MAX, PATH_MAX,
or POSIX_NO_TRUNC, and pathname does not
refer to a directory, pathconf() returns the requested information.
- If varcode refers to PC_PIPE_BUF and pathname refers
to a pipe or a FIFO, the value returned applies to the referenced
object itself. If pathname refers to a directory,
the value returned applies to any FIFOs that exist or can be created
within the directory. If pathname refers
to any other type of file, the function sets errno to EINVAL.
- ELOOP
- A loop exists in symbolic links. This error is issued if more
than POSIX_SYMLOOPS symbolic links are detected in the resolution
of pathname.
- ENAMETOOLONG
- pathname is longer than PATH_MAX characters,
or some component of pathname is longer
than NAME_MAX while _POSIX_NO_TRUNC is in effect.
For symbolic
links, the length of the path name string substituted for a symbolic
link exceeds PATH_MAX.
- ENOENT
- There is no file named pathname, or
the pathname argument is an empty string.
- ENOTDIR
- Some component of the pathname is not
a directory.
Example
CELEBP01 ⁄* CELEBP01
This example determines the maximum number of characters in a file name.
*⁄
#define _POSIX_SOURCE
#include <errno.h>
#include <unistd.h>
#undef _POSIX_SOURCE
#include <stdio.h>
main() {
long result;
errno = 0;
puts("examining NAME_MAX limit for root filesystem");
if ((result = pathconf("⁄", _PC_NAME_MAX)) == -1)
if (errno == 0)
puts("There is no limit to NAME_MAX.");
else perror("pathconf() error");
else
printf("NAME_MAX is %ld\n", result);
}
Output: examining NAME_MAX limit for root file system
NAME_MAX is 255