confstr

Determines the current value of a specified system variable defined by a string value.

Format

#include  <unistd.h>

size_t confstr  (int name, char *buf, size_t
                len);

Arguments

name
The system variable setting. Valid values for the name argument are the _CS_X names defined in the <unistd.h> header file.
buf
Pointer to the buffer where the confstr function copies the name value.
len
The size of the buffer storing the name value.

Description

This function allows an application to determine the current setting of certain system parameters, limits, or options that are defined by a string value. The function is mainly used by applications to find the system default value for the PATH environment variable.

If the following conditions are true, then the confstr function copies that value into a len-byte buffer pointed to by buf:

If the returned string is longer than len bytes, including the terminating null, then the confstr function truncates the string to len -1 bytes and adds a terminating null to the result. The application can detect that the string was truncated by comparing the value returned by the confstr function with the value of the len argument.

The <limits.h> header file contains system-defined limits. The <unistd.h> header file contains system-defined environmental variables.

Example

    To find out how big a buffer is needed to store the string value of name, enter:

     confstr(_CS_PATH, NULL, (size_t) 0)
    

    The confstr function returns the size of the buffer necessary.

Return Values
Indicates an error. When the specified name value:

  • Is invalid, errno is set to EINVAL.

  • Does not have a system-defined value, errno is not set.
 
The size of the buffer needed to hold the value.

  • When the value of the name argument is system- defined, confstr returns the size of the buffer needed to hold the entire value. If this return value is greater than the len value, the string returned as the buf value is truncated.

  • When the value of the len argument is set to 0 or the buf value is NULL, confstr returns the size of the buffer needed to hold the entire system-defined value. The string value is not copied.
 


Previous Page | Next Page | Table of Contents | Index