1CONFSTR(3P) POSIX Programmer's Manual CONFSTR(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 confstr - get configurable variables
13
15 #include <unistd.h>
16
17 size_t confstr(int name, char *buf, size_t len);
18
19
21 The confstr() function shall return configuration-defined string val‐
22 ues. Its use and purpose are similar to sysconf(), but it is used where
23 string values rather than numeric values are returned.
24
25 The name argument represents the system variable to be queried. The
26 implementation shall support the following name values, defined in
27 <unistd.h>. It may support others:
28
29 _CS_PATH
30 _CS_POSIX_V6_ILP32_OFF32_CFLAGS
31 _CS_POSIX_V6_ILP32_OFF32_LDFLAGS
32 _CS_POSIX_V6_ILP32_OFF32_LIBS
33 _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
34 _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
35 _CS_POSIX_V6_ILP32_OFFBIG_LIBS
36 _CS_POSIX_V6_LP64_OFF64_CFLAGS
37 _CS_POSIX_V6_LP64_OFF64_LDFLAGS
38 _CS_POSIX_V6_LP64_OFF64_LIBS
39 _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
40 _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
41 _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
42 _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS
43
44 _CS_XBS5_ILP32_OFF32_CFLAGS (LEGACY)
45 _CS_XBS5_ILP32_OFF32_LDFLAGS (LEGACY)
46 _CS_XBS5_ILP32_OFF32_LIBS (LEGACY)
47 _CS_XBS5_ILP32_OFF32_LINTFLAGS (LEGACY)
48 _CS_XBS5_ILP32_OFFBIG_CFLAGS (LEGACY)
49 _CS_XBS5_ILP32_OFFBIG_LDFLAGS (LEGACY)
50 _CS_XBS5_ILP32_OFFBIG_LIBS (LEGACY)
51 _CS_XBS5_ILP32_OFFBIG_LINTFLAGS (LEGACY)
52 _CS_XBS5_LP64_OFF64_CFLAGS (LEGACY)
53 _CS_XBS5_LP64_OFF64_LDFLAGS (LEGACY)
54 _CS_XBS5_LP64_OFF64_LIBS (LEGACY)
55 _CS_XBS5_LP64_OFF64_LINTFLAGS (LEGACY)
56 _CS_XBS5_LPBIG_OFFBIG_CFLAGS (LEGACY)
57 _CS_XBS5_LPBIG_OFFBIG_LDFLAGS (LEGACY)
58 _CS_XBS5_LPBIG_OFFBIG_LIBS (LEGACY)
59 _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS (LEGACY)
60
61
62 If len is not 0, and if name has a configuration-defined value, conf‐
63 str() shall copy that value into the len-byte buffer pointed to by buf.
64 If the string to be returned is longer than len bytes, including the
65 terminating null, then confstr() shall truncate the string to len-1
66 bytes and null-terminate the result. The application can detect that
67 the string was truncated by comparing the value returned by confstr()
68 with len.
69
70 If len is 0 and buf is a null pointer, then confstr() shall still
71 return the integer value as defined below, but shall not return a
72 string. If len is 0 but buf is not a null pointer, the result is
73 unspecified.
74
75 If the implementation supports the POSIX shell option, the string
76 stored in buf after a call to:
77
78
79 confstr(_CS_PATH, buf, sizeof(buf))
80
81 can be used as a value of the PATH environment variable that accesses
82 all of the standard utilities of IEEE Std 1003.1-2001, if the return
83 value is less than or equal to sizeof( buf).
84
86 If name has a configuration-defined value, confstr() shall return the
87 size of buffer that would be needed to hold the entire configuration-
88 defined value including the terminating null. If this return value is
89 greater than len, the string returned in buf is truncated.
90
91 If name is invalid, confstr() shall return 0 and set errno to indicate
92 the error.
93
94 If name does not have a configuration-defined value, confstr() shall
95 return 0 and leave errno unchanged.
96
98 The confstr() function shall fail if:
99
100 EINVAL The value of the name argument is invalid.
101
102
103 The following sections are informative.
104
106 None.
107
109 An application can distinguish between an invalid name parameter value
110 and one that corresponds to a configurable variable that has no config‐
111 uration-defined value by checking if errno is modified. This mirrors
112 the behavior of sysconf().
113
114 The original need for this function was to provide a way of finding the
115 configuration-defined default value for the environment variable PATH.
116 Since PATH can be modified by the user to include directories that
117 could contain utilities replacing the standard utilities in the Shell
118 and Utilities volume of IEEE Std 1003.1-2001, applications need a way
119 to determine the system-supplied PATH environment variable value that
120 contains the correct search path for the standard utilities.
121
122 An application could use:
123
124
125 confstr(name, (char *)NULL, (size_t)0)
126
127 to find out how big a buffer is needed for the string value; use mal‐
128 loc() to allocate a buffer to hold the string; and call confstr() again
129 to get the string. Alternately, it could allocate a fixed, static buf‐
130 fer that is big enough to hold most answers (perhaps 512 or 1024
131 bytes), but then use malloc() to allocate a larger buffer if it finds
132 that this is too small.
133
135 Application developers can normally determine any configuration vari‐
136 able by means of reading from the stream opened by a call to:
137
138
139 popen("command -p getconf variable", "r");
140
141 The confstr() function with a name argument of _CS_PATH returns a
142 string that can be used as a PATH environment variable setting that
143 will reference the standard shell and utilities as described in the
144 Shell and Utilities volume of IEEE Std 1003.1-2001.
145
146 The confstr() function copies the returned string into a buffer sup‐
147 plied by the application instead of returning a pointer to a string.
148 This allows a cleaner function in some implementations (such as those
149 with lightweight threads) and resolves questions about when the appli‐
150 cation must copy the string returned.
151
153 None.
154
156 pathconf(), sysconf(), the Base Definitions volume of
157 IEEE Std 1003.1-2001, <unistd.h>, the Shell and Utilities volume of
158 IEEE Std 1003.1-2001, c99
159
161 Portions of this text are reprinted and reproduced in electronic form
162 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
163 -- Portable Operating System Interface (POSIX), The Open Group Base
164 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
165 Electrical and Electronics Engineers, Inc and The Open Group. In the
166 event of any discrepancy between this version and the original IEEE and
167 The Open Group Standard, the original IEEE and The Open Group Standard
168 is the referee document. The original Standard can be obtained online
169 at http://www.opengroup.org/unix/online.html .
170
171
172
173IEEE/The Open Group 2003 CONFSTR(3P)