1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
'\" et
.TH CONFSTR "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
confstr
\(em get configurable variables
.SH SYNOPSIS
.LP
.nf
#include <unistd.h>
.P
size_t confstr(int \fIname\fP, char *\fIbuf\fP, size_t \fIlen\fP);
.fi
.SH DESCRIPTION
The
\fIconfstr\fR()
function shall return configuration-defined string values. Its use and
purpose are similar to
\fIsysconf\fR(),
but it is used where string values rather than numeric values are
returned.
.P
The
.IR name
argument represents the system variable to be queried. The
implementation shall support the following name values, defined in
.IR <unistd.h> .
It may support others:
.P
.nf
_CS_PATH
_CS_POSIX_V7_ILP32_OFF32_CFLAGS
_CS_POSIX_V7_ILP32_OFF32_LDFLAGS
_CS_POSIX_V7_ILP32_OFF32_LIBS
_CS_POSIX_V7_ILP32_OFFBIG_CFLAGS
_CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS
_CS_POSIX_V7_ILP32_OFFBIG_LIBS
_CS_POSIX_V7_LP64_OFF64_CFLAGS
_CS_POSIX_V7_LP64_OFF64_LDFLAGS
_CS_POSIX_V7_LP64_OFF64_LIBS
_CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS
_CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS
_CS_POSIX_V7_LPBIG_OFFBIG_LIBS
_CS_POSIX_V7_THREADS_CFLAGS
_CS_POSIX_V7_THREADS_LDFLAGS
_CS_POSIX_V7_WIDTH_RESTRICTED_ENVS
_CS_V7_ENV
_CS_POSIX_V6_ILP32_OFF32_CFLAGS
_CS_POSIX_V6_ILP32_OFF32_LDFLAGS
_CS_POSIX_V6_ILP32_OFF32_LIBS
_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
_CS_POSIX_V6_ILP32_OFFBIG_LIBS
_CS_POSIX_V6_LP64_OFF64_CFLAGS
_CS_POSIX_V6_LP64_OFF64_LDFLAGS
_CS_POSIX_V6_LP64_OFF64_LIBS
_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
_CS_POSIX_V6_LPBIG_OFFBIG_LIBS
_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS
_CS_V6_ENV
.fi
.P
If
.IR len
is not 0, and if
.IR name
has a configuration-defined value,
\fIconfstr\fR()
shall copy that value into the
.IR len -byte
buffer pointed to by
.IR buf .
If the string to be returned is longer than
.IR len
bytes, including the terminating null, then
\fIconfstr\fR()
shall truncate the string to
.IR len \-1
bytes and null-terminate the result. The application can detect that
the string was truncated by comparing the value returned by
\fIconfstr\fR()
with
.IR len .
.P
If
.IR len
is 0 and
.IR buf
is a null pointer, then
\fIconfstr\fR()
shall still return the integer value as defined below, but shall not
return a string. If
.IR len
is 0 but
.IR buf
is not a null pointer, the result is unspecified.
.P
After a call to:
.sp
.RS 4
.nf
confstr(_CS_V7_ENV, buf, sizeof(buf))
.fi
.P
.RE
.P
the string stored in
.IR buf
shall contain a
<space>-separated
list of the variable=value environment variable pairs an
implementation requires as part of specifying a conforming
environment, as described in the implementations' conformance
documentation.
.P
If the implementation supports the POSIX shell option, the string
stored in
.IR buf
after a call to:
.sp
.RS 4
.nf
confstr(_CS_PATH, buf, sizeof(buf))
.fi
.P
.RE
.P
can be used as a value of the
.IR PATH
environment variable that accesses all of the standard utilities of
POSIX.1\(hy2008, that are provided in a manner accessible via the
.IR exec
family of functions, if the return value is less than or equal to
.IR sizeof (\c
.IR buf ).
.SH "RETURN VALUE"
If
.IR name
has a configuration-defined value,
\fIconfstr\fR()
shall return the size of buffer that would be needed to hold the entire
configuration-defined value including the terminating null. If this
return value is greater than
.IR len ,
the string returned in
.IR buf
is truncated.
.P
If
.IR name
is invalid,
\fIconfstr\fR()
shall return 0 and set
.IR errno
to indicate the error.
.P
If
.IR name
does not have a configuration-defined value,
\fIconfstr\fR()
shall return 0 and leave
.IR errno
unchanged.
.SH ERRORS
The
\fIconfstr\fR()
function shall fail if:
.TP
.BR EINVAL
The value of the
.IR name
argument is invalid.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
None.
.SH "APPLICATION USAGE"
An application can distinguish between an invalid
.IR name
parameter value and one that corresponds to a configurable variable
that has no configuration-defined value by checking if
.IR errno
is modified. This mirrors the behavior of
\fIsysconf\fR().
.P
The original need for this function was to provide a way of finding the
configuration-defined default value for the environment variable
.IR PATH .
Since
.IR PATH
can be modified by the user to include directories that could contain
utilities replacing the standard utilities in the Shell and Utilities volume of POSIX.1\(hy2017, applications
need a way to determine the system-supplied
.IR PATH
environment variable value that contains the correct search path for
the standard utilities.
.P
An application could use:
.sp
.RS 4
.nf
confstr(name, (char *)NULL, (size_t)0)
.fi
.P
.RE
.P
to find out how big a buffer is needed for the string value; use
\fImalloc\fR()
to allocate a buffer to hold the string; and call
\fIconfstr\fR()
again to get the string. Alternately, it could allocate a fixed, static
buffer that is big enough to hold most answers (perhaps 512 or 1\|024
bytes), but then use
\fImalloc\fR()
to allocate a larger buffer if it finds that this is too small.
.SH RATIONALE
Application developers can normally determine any configuration
variable by means of reading from the stream opened by a call to:
.sp
.RS 4
.nf
popen("command -p getconf variable", "r");
.fi
.P
.RE
.P
The
\fIconfstr\fR()
function with a
.IR name
argument of _CS_PATH returns a string that can be used as a
.IR PATH
environment variable setting that will reference the standard shell and
utilities as described in the Shell and Utilities volume of POSIX.1\(hy2017.
.P
The
\fIconfstr\fR()
function copies the returned string into a buffer supplied by the
application instead of returning a pointer to a string. This allows a
cleaner function in some implementations (such as those with
lightweight threads) and resolves questions about when the application
must copy the string returned.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIexec\fR\^",
.IR "\fIfpathconf\fR\^(\|)",
.IR "\fIsysconf\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<unistd.h>\fP"
.P
The Shell and Utilities volume of POSIX.1\(hy2017,
.IR "\fIc99\fR\^"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|