Get configuration-defined string values
#include <unistd.h> size_t confstr( int name, char * buf, size_t len );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The confstr() function lets applications get or (as a QNX Neutrino extension) set configuration-defined string values. This is similar to the sysconf() function, but you use it to get string values, rather than numeric values. By default, the function queries and returns values in the system.
The name argument represents the system variable to query. The values are defined in <confname.h>; at least the following name values are valid:
![]() |
A hostname can consist only of letters, numbers, and hyphens, and must not start or end with a hyphen. For more information, see RFC 952. |
The configuration-defined value is returned in the buffer pointed to by buf, and will be ≤ len bytes long, including the terminating NULL. If the value, including the terminating NULL, is greater than len bytes long, it's truncated to len - 1 bytes and terminated with a NULL character.
To find out the length of a configuration-defined value, call confstr() with buf set to NULL and len set to 0.
As a QNX Neutrino extension, you can set a configuration value, as follows:
If you're getting the value:
If you're setting a value and an error occurs, confstr() returns 0 and sets errno. Any other value indicates success.
Print information similar to that returned by the uname() function:
#include <unistd.h> #include <stdio.h> #include <limits.h> #define BUFF_SIZE (256 + 1) int main( void ) { char buff[BUFF_SIZE]; if( confstr( _CS_SYSNAME, buff, BUFF_SIZE ) > 0 ) { printf( "System name: %s\n", buff ); } if( confstr( _CS_HOSTNAME, buff, BUFF_SIZE ) > 0 ) { printf( "Host name: %s\n", buff ); } if( confstr( _CS_RELEASE, buff, BUFF_SIZE ) > 0 ) { printf( "Release: %s\n", buff ); } if( confstr( _CS_VERSION, buff, BUFF_SIZE ) > 0 ) { printf( "Version: %s\n", buff ); } if( confstr( _CS_MACHINE, buff, BUFF_SIZE ) > 0 ) { printf( "Machine: %s\n", buff ); } if( confstr( _CS_SET | _CS_HOSTNAME, "myhostname", 0 ) != 0 ) { printf( "Hostname set to: %s\n", "myhostname" ); } return 0; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
confstr, getconf, setconf in the Utilities Reference
“Configuration strings” in the Configuring Your Environment chapter of the Neutrino User's Guide