Name

confstr - get configuration dependent string variables

Library

libc.lib

Synopsis

  #include <unistd.h>
  size_t confstr (int name, char *buf, size_t len);

Return values

If the call to confstr is not successful, 0 is returned and errno is set appropriately. Otherwise, if the variable does not have a configuration defined value, 0 is returned and errno is not modified. Otherwise, the buffer size needed to hold the entire configuration-defined value is returned. If this size is greater than the argument len, the string in buf was truncated.

Detailed description

The confstr function provides a method for applications to get configuration defined string values.

The name argument specifies the system variable to be queried. Symbolic constants for each name value are found in the include file

  #include <unistd.h.>The len argument specifies the size of the buffer referenced by the argument buf. If len is non-zero, buf is a non-null pointer, and name has a value, up to len - 1 bytes of the value are copied into the buffer buf. The copied value is always null terminated.

The available values are as follows:

_CS_PATH
  Return a value for the PATH environment variable that finds all the standard utilities.


Examples

#include<unistd.h>
#include<stdio.h>
#include <stdlib.h>
 
int main()
{
 int n = 0;
 char *buf = NULL;
 int len = 0;
   
 n = confstr(_CS_PATH, NULL, 0);
    
 printf("{Expected: 31} %d\n", n);
       
 if( n == 0 )
    return -1;
                    
 buf = (char *)malloc(n);
  
 if ( buf == NULL )
 {
    printf("malloc failed!!");
    return -1;
 }
             
 len = confstr(_CS_PATH, buf, n);
                
 printf("PATH in buffer: \n%s", buf);
 printf("\nlength: %d", len);
 free(buf);
 
 return 0;
}

         

Output

PATH in buffer:
/usr/bin:/bin:/usr/sbin:/sbin:
length: 31

         

Errors

[EINVAL]
  The value of the name argument is invalid.

See also

pathconf, sysconf

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top