fpathconf() — Determine configurable path name variables
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
Format
#define _POSIX_SOURCE
#include <unistd.h>
long fpathconf(int fildes, int varcode);
General description
Determines the value of a configuration variable (varcode) associated with a particular file descriptor (fildes).
fpathconf() works exactly like pathconf(), except that it takes a file descriptor as an argument rather than taking a path name.
The varcode argument
can be any one of a set of symbols defined in the unistd.h header
file. Each symbol stands for a configuration variable. These are the
possible symbols:
- _PC_LINK_MAX
- Represents LINK_MAX, the maximum number of links the file can have. If pathname is a directory, fpathconf() 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 minimum number of bytes for which space will be available in a terminal input queue. This input space is the maximum number of bytes that a portable application will allow an end user to 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 character if the file name is stored as a string). This limit refers only to the file name itself, that is, the last component of the file's path name. fpathconf() 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 if the path name is stored as a string). fpathconf() returns the maximum length of a relative path name.
- _PC_PIPE_BUF
- Represents PIPE_BUF, the maximum number of bytes that can be written to a pipe as one unit. If more than this number of bytes is written to a pipe, the operation can take more than one physical write operation and can require more than one physical read operation to read the data on the other end of the pipe. If pathname is a FIFO special file, fpathconf() returns the value for the file itself. If pathname is a directory, fpathconf() returns the value for any FIFOs that exist or can be created under the directory. If pathname is any other kind of file, an errno of EINVAL (see description below) will be returned.
- _PC_CHOWN_RESTRICTED
- Represents _POSIX_CHOWN_RESTRICTED defined in the unistd.h header file. This symbol indicates that the use of chown() is restricted; see the callable service chown() for more details. If pathname is a directory, fpathconf() 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. This symbol indicates that an error should be generated if a file name is longer than NAME_MAX. If pathname refers to a directory, the value returned by fpathconf() 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 for the file identified by the file descriptor.
- _PC_ACL_ENTRIES_MAX
- Returns the maximum number of ACL entries in an ACL for the file or directory identified by the file descriptor.
Returned value
If a particular variable has no limit, fpathconf() returns -1 but does not change errno.
If successful, fpathconf() returns the value of the variable requested in varcode.
If unsuccessful, fpathconf()
returns -1 and sets errno to one of the following values:
- Error Code
- Description
- EBADF
- fildes is not a valid open file descriptor.
- 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, fpathconf() 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, fpathconf() 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.
Example
CELEBF29
/* CELEBF29
This example uses fpathconf() with __PC_NAME_MAX to determine the value
of the NAME_MAX configuration variable.
*/
#define _POSIX_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#undef _POSIX_SOURCE
#include <stdio.h>
main() {
long result;
char fn[]="temp.file";
int fd;
if ((fd = creat(fn, S_IRUSR)) < 0)
perror("creat() error");
else {
errno = 0;
puts("examining NAME_MAX limit for current working directory's");
puts("filesystem:");
if ((result = fpathconf(fd, _PC_NAME_MAX)) == -1)
if (errno == 0)
puts("There is no limit to NAME_MAX.");
else perror("fpathconf() error");
else
printf("NAME_MAX is %ld\n", result);
close(fd);
unlink(fn);
}
}
Output
examining NAME_MAX limit for current working directory's
file system:
NAME_MAX is 255