| 1 |
'\" t |
| 2 |
.\" Copyright 1993, Thomas Koenig <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.\" FIXME Many more values for 'name' are supported, some of which |
| 8 |
.\" are documented under 'info libc confstr'. |
| 9 |
.\" See <bits/confname.h> for the rest. |
| 10 |
.\" These should all be added to this page. |
| 11 |
.\" See also the POSIX.1-2001 specification of confstr() |
| 12 |
.\" |
| 13 |
.TH confstr 3 2026-02-08 "Linux man-pages 6.18" |
| 14 |
.SH NAME |
| 15 |
confstr \- get configuration dependent string variables |
| 16 |
.SH LIBRARY |
| 17 |
Standard C library |
| 18 |
.RI ( libc ,\~ \-lc ) |
| 19 |
.SH SYNOPSIS |
| 20 |
.nf |
| 21 |
.B #include <unistd.h> |
| 22 |
.P |
| 23 |
.BR "size_t confstr(" "size_t size;" |
| 24 |
.BI " int " "name" ", char " buf [ size "], size_t " size ); |
| 25 |
.fi |
| 26 |
.P |
| 27 |
.RS -4 |
| 28 |
Feature Test Macro Requirements for glibc (see |
| 29 |
.BR feature_test_macros (7)): |
| 30 |
.RE |
| 31 |
.P |
| 32 |
.BR confstr (): |
| 33 |
.nf |
| 34 |
_POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE |
| 35 |
.fi |
| 36 |
.SH DESCRIPTION |
| 37 |
.BR confstr () |
| 38 |
gets the value of configuration-dependent string variables. |
| 39 |
.P |
| 40 |
The |
| 41 |
.I name |
| 42 |
argument is the system variable to be queried. |
| 43 |
The following variables are supported: |
| 44 |
.TP |
| 45 |
.BR _CS_GNU_LIBC_VERSION " (GNU C library only; since glibc 2.3.2)" |
| 46 |
A string which identifies the GNU C library version on this system |
| 47 |
(e.g., "glibc 2.3.4"). |
| 48 |
.TP |
| 49 |
.BR _CS_GNU_LIBPTHREAD_VERSION " (GNU C library only; since glibc 2.3.2)" |
| 50 |
A string which identifies the POSIX implementation supplied by this |
| 51 |
C library (e.g., "NPTL 2.3.4" or "linuxthreads\-0.10"). |
| 52 |
.TP |
| 53 |
.B _CS_PATH |
| 54 |
A value for the |
| 55 |
.B PATH |
| 56 |
variable which indicates where all the POSIX.2 standard utilities can |
| 57 |
be found. |
| 58 |
.P |
| 59 |
If |
| 60 |
.I buf |
| 61 |
is not NULL and |
| 62 |
.I size |
| 63 |
is not zero, |
| 64 |
.BR confstr () |
| 65 |
copies the value of the string to |
| 66 |
.I buf |
| 67 |
truncated to |
| 68 |
.I size \- 1 |
| 69 |
bytes if necessary, with a null byte (\[aq]\[rs]0\[aq]) as terminator. |
| 70 |
This can be detected by comparing the return value of |
| 71 |
.BR confstr () |
| 72 |
against |
| 73 |
.IR size . |
| 74 |
.P |
| 75 |
If |
| 76 |
.I size |
| 77 |
is zero and |
| 78 |
.I buf |
| 79 |
is NULL, |
| 80 |
.BR confstr () |
| 81 |
just returns the value as defined below. |
| 82 |
.SH RETURN VALUE |
| 83 |
If |
| 84 |
.I name |
| 85 |
is a valid configuration variable, |
| 86 |
.BR confstr () |
| 87 |
returns the number of bytes (including the terminating null byte) |
| 88 |
that would be required to hold the entire value of that variable. |
| 89 |
This value may be greater than |
| 90 |
.IR size , |
| 91 |
which means that the value in |
| 92 |
.I buf |
| 93 |
is truncated. |
| 94 |
.P |
| 95 |
If |
| 96 |
.I name |
| 97 |
is a valid configuration variable, |
| 98 |
but that variable does not have a value, then |
| 99 |
.BR confstr () |
| 100 |
returns 0. |
| 101 |
If |
| 102 |
.I name |
| 103 |
does not correspond to a valid configuration variable, |
| 104 |
.BR confstr () |
| 105 |
returns 0, and |
| 106 |
.I errno |
| 107 |
is set to |
| 108 |
.BR EINVAL . |
| 109 |
.SH ERRORS |
| 110 |
.TP |
| 111 |
.B EINVAL |
| 112 |
The value of |
| 113 |
.I name |
| 114 |
is invalid. |
| 115 |
.SH ATTRIBUTES |
| 116 |
For an explanation of the terms used in this section, see |
| 117 |
.BR attributes (7). |
| 118 |
.TS |
| 119 |
allbox; |
| 120 |
lbx lb lb |
| 121 |
l l l. |
| 122 |
Interface Attribute Value |
| 123 |
T{ |
| 124 |
.na |
| 125 |
.nh |
| 126 |
.BR confstr () |
| 127 |
T} Thread safety MT-Safe |
| 128 |
.TE |
| 129 |
.SH STANDARDS |
| 130 |
POSIX.1-2008. |
| 131 |
.SH HISTORY |
| 132 |
POSIX.1-2001. |
| 133 |
.SH EXAMPLES |
| 134 |
The following code fragment determines the path where to find |
| 135 |
the POSIX.2 system utilities: |
| 136 |
.P |
| 137 |
.in +4n |
| 138 |
.EX |
| 139 |
char *pathbuf; |
| 140 |
size_t n; |
| 141 |
\& |
| 142 |
n = confstr(_CS_PATH, NULL, (size_t) 0); |
| 143 |
pathbuf = malloc(n); |
| 144 |
if (pathbuf == NULL) |
| 145 |
abort(); |
| 146 |
confstr(_CS_PATH, pathbuf, n); |
| 147 |
.EE |
| 148 |
.in |
| 149 |
.SH SEE ALSO |
| 150 |
.BR getconf (1), |
| 151 |
.BR sh (1), |
| 152 |
.BR exec (3), |
| 153 |
.BR fpathconf (3), |
| 154 |
.BR pathconf (3), |
| 155 |
.BR sysconf (3), |
| 156 |
.BR system (3) |