Node:String Parameters, Previous:Utility Minimums, Up:System Configuration
POSIX.2 defines a way to get string-valued parameters from the operating
system with the function confstr
:
size_t confstr (int parameter, char *buf, size_t len) | Function |
This function reads the value of a string-valued system parameter,
storing the string into len bytes of memory space starting at
buf. The parameter argument should be one of the
_CS_ symbols listed below.
The normal return value from If the string you asked for is too long for the buffer (that is, longer
than The following
|
Currently there is just one parameter you can read with confstr
:
_CS_PATH
_CS_LFS_CFLAGS
_LARGEFILE_SOURCE
feature select macro; see Feature Test Macros.
_CS_LFS_LDFLAGS
_LARGEFILE_SOURCE
feature select macro; see Feature Test Macros.
_CS_LFS_LIBS
_LARGEFILE_SOURCE
feature select macro; see Feature Test Macros.
_CS_LFS_LINTFLAGS
_LARGEFILE_SOURCE
feature select macro; see Feature Test Macros.
_CS_LFS64_CFLAGS
_LARGEFILE64_SOURCE
feature select macro; see Feature Test Macros.
_CS_LFS64_LDFLAGS
_LARGEFILE64_SOURCE
feature select macro; see Feature Test Macros.
_CS_LFS64_LIBS
_LARGEFILE64_SOURCE
feature select macro; see Feature Test Macros.
_CS_LFS64_LINTFLAGS
_LARGEFILE64_SOURCE
feature select macro; see Feature Test Macros.
The way to use confstr
without any arbitrary limit on string size
is to call it twice: first call it to get the length, allocate the
buffer accordingly, and then call confstr
again to fill the
buffer, like this:
char * get_default_path (void) { size_t len = confstr (_CS_PATH, NULL, 0); char *buffer = (char *) xmalloc (len); if (confstr (_CS_PATH, buf, len + 1) == 0) { free (buffer); return NULL; } return buffer; }