xref: /freebsd/lib/libc/gen/confstr.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
1.\" Copyright (c) 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd December 3, 2006
29.Dt CONFSTR 3
30.Os
31.Sh NAME
32.Nm confstr
33.Nd get string-valued configurable variables
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In unistd.h
38.Ft size_t
39.Fn confstr "int name" "char *buf" "size_t len"
40.Sh DESCRIPTION
41This interface is specified by
42.St -p1003.1-2001 .
43A more flexible (but non-portable) interface is provided by
44.Xr sysctl 3 .
45.Pp
46The
47.Fn confstr
48function provides a method for applications to get configuration
49defined string values.
50Shell programmers needing access to these parameters should use the
51.Xr getconf 1
52utility.
53.Pp
54The
55.Fa name
56argument specifies the system variable to be queried.
57Symbolic constants for each name value are found in the include file
58.In unistd.h .
59The
60.Fa len
61argument specifies the size of the buffer referenced by the
62argument
63.Fa buf .
64If
65.Fa len
66is non-zero,
67.Fa buf
68is a non-null pointer, and
69.Fa name
70has a value, up to
71.Fa len
72\- 1 bytes of the value are copied into the buffer
73.Fa buf .
74The copied value is always null terminated.
75.Pp
76The available values are as follows:
77.Bl -tag -width 6n
78.It Li _CS_PATH
79Return a value for the
80.Ev PATH
81environment variable that finds all the standard utilities.
82.El
83.Sh RETURN VALUES
84If the call to
85.Fn confstr
86is not successful, 0 is returned and
87.Va errno
88is set appropriately.
89Otherwise, if the variable does not have a configuration defined value,
900 is returned and
91.Va errno
92is not modified.
93Otherwise, the buffer size needed to hold the entire configuration-defined
94value is returned.
95If this size is greater than the argument
96.Fa len ,
97the string in
98.Fa buf
99was truncated.
100.Sh ERRORS
101The
102.Fn confstr
103function may fail and set
104.Va errno
105for any of the errors specified for the library functions
106.Xr malloc 3
107and
108.Xr sysctl 3 .
109.Pp
110In addition, the following errors may be reported:
111.Bl -tag -width Er
112.It Bq Er EINVAL
113The value of the
114.Fa name
115argument is invalid.
116.El
117.Sh SEE ALSO
118.Xr getconf 1 ,
119.Xr pathconf 2 ,
120.Xr sysconf 3 ,
121.Xr sysctl 3
122.Sh HISTORY
123The
124.Fn confstr
125function first appeared in
126.Bx 4.4 .
127