pathconf()--Get Configurable Path Name Variables


  Syntax
 #include <unistd.h>

 long pathconf(const char *path, int name);  
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes.

The pathconf() function lets an application determine the value of a configuration variable (name) associated with a particular file or directory (path).

If the named file is a symbolic link, pathconf() resolves the symbolic link.


Parameters

path
(Input) A pointer to the null-terminated path name of the file for which the value of the configuration variable is requested.

This parameter is assumed to be represented in the CCSID (coded character set identifier) currently in effect for the process. If the CCSID of the job is 65535, this parameter is assumed to be represented in the default CCSID of the job.

See QlgPathconf()--Get Configurable Path Name Variables for a description and an example of supplying the path in any CCSID.


name
(Input) The name of the configuration variable value requested.

The value of name can be any one of the following set of symbols defined in the <unistd.h> header file, each standing for a configuration variable:

_PC_LINK_MAX

Represents LINK_MAX, which indicates the maximum number of links the file can have. If path is a directory, pathconf() returns the maximum number of links that can be established to the directory itself.

_PC_MAX_CANON

Represents MAX_CANON, which indicates the maximum number of bytes in a terminal canonical input line.

_PC_MAX_INPUT

Represents MAX_INPUT, which indicates the minimum number of bytes for which space is available in a terminal input queue. This available space is the maximum number of bytes that a portable application can have the user enter before the application actually reads the input.

_PC_NAME_MAX

Represents NAME_MAX, which indicates the maximum number of bytes 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 path name of the file. pathconf() returns the maximum length of file names, even when the path does not refer to a directory.

This value is the number of bytes allowed in the file name if it were encoded in the CCSID of the job. If the CCSID is mixed, this number is an estimate and may be larger than the actual allowable maximum.

_PC_PATH_MAX

Represents PATH_MAX, which indicates the maximum number of bytes 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 relative to path, even when path does not refer to a directory.

This value is the number of bytes allowed in the path name if it were encoded in the CCSID of the job. If the CCSID is mixed, this number is an estimate and may be larger than the actual allowable maximum.

_PC_PIPE_BUF

Represents PIPE_BUF, which indicates the maximum number of bytes that can be written "atomically" to a pipe. If more than this number of bytes are 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 path is a FIFO special file, pathconf() returns the value for the file itself. If path is a directory, pathconf() returns the value for any FIFOs that exist or that can be created under the directory. If path is any other kind of file, an error of [EINVAL] is returned.

_PC_CHOWN_RESTRICTED

Represents _POSIX_CHOWN_RESTRICTED, as defined in the <unistd.h> header file. It restricts use of chown() to a job with appropriate privileges, and allows the group ID of a file to be changed only to the effective group ID of the job or to one of its supplementary group IDs. If path 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, as defined in the <unistd.h> header file. It generates an error if a file name is longer than NAME_MAX. If path refers to a directory, the value returned by pathconf() applies to all files under that directory.

_PC_VDISABLE

Represents _POSIX_VDISABLE, as 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.

_PC_THREAD_SAFE

This symbol is used to determine if the object represented by path resides in a threadsafe file system. pathconf() returns the value 1 if the file system is threadsafe and 0 if the file system is not threadsafe. fpathconf() will never fail with error code [ENOTSAFE] when called with _PC_THREAD_SAFE.


Authorities

Note: Adopted authority is not used.

Authorization required for pathconf()

Object Referred to Authority Required errno
Each directory in the path name preceding the object *X EACCES
Object None None

Return Value

value
pathconf() was successful. The value of the variable requested in name is returned.
-1
One of the following has occurred:


Error Conditions

If fpathconf() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

Error condition Additional information
[EACCES]

If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems.

[EAGAIN]
[EBADFID]
[EBADNAME]
[EBUSY]
[ECONVERT]
[EDAMAGE]
[EFAULT]
[EFILECVT]
[EINTR]
[EINVAL]

For example, name is not a valid configuration variable name, or the given variable cannot be associated with the specified file.

[EIO]
[EISDIR]
[ELOOP]
[ENAMETOOLONG]
[ENOENT]
[ENOMEM]
[ENOSPC]
[ENOTAVAIL]
[ENOTDIR]
[ENOTSAFE]
[ENOTSUP]
[EPERM]
[EROOBJ]
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[EUNKNOWN]

If interaction with a file server is required to access the object, errno could indicate one of the following errors:

Error condition Additional information
[EADDRNOTAVAIL]
[ECONNABORTED]
[ECONNREFUSED]
[ECONNRESET]
[EHOSTDOWN]
[EHOSTUNREACH]
[ENETDOWN]
[ENETRESET]
[ENETUNREACH]
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[ETIMEDOUT]
[EUNATCH]


Error Messages

The following messages may be sent from this function:

Message ID Error Message Text
CPE3418 E Possible APAR condition or hardware failure.
CPFA0D4 E File system error occurred. Error number &1.
CPF3CF2 E Error(s) occurred during running of &1 API.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.

Usage Notes

  1. When this function is called with any configuration variable name except _PC_THREAD_SAFE, the following usage note applies:


Related Information


Example

The following example determines the maximum number of bytes in a file name.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <stdio.h>
#include <unistd.h>
#include <errno.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 filesystem
NAME_MAX is 255


API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]