confstr(3)
๐ confstr(3) โ get configuration dependent string variables ๐
okay bestie, welcome to the confstr page from the Library Functions Manual (yes that's the section name, we're being โจofficialโจ today). this one's a libc baddie and she's here to hand you the config strings your system is hiding. let's get into it ๐ซถ
๐ธ NAME ๐ธ
confstr โ get configuration dependent string variables
๐ LIBRARY ๐
Standard C library (libc, -lc)
โจ SYNOPSIS โจ
#include <unistd.h>
size_t confstr(size_t size;
int name, char buf[size], size_t size);
๐ง Feature Test Macro Requirements for glibc (see feature_test_macros(7)): ๐ง
confstr()โ_POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE
yeah bestie there's a feature test macro situation, you knew there would be. love that for glibc.
๐ DESCRIPTION ๐
confstr() gets the value of configuration-dependent string variables. it's literally just that. ask it about a system variable, it tells you the string.
The name argument is the system variable to be queried. The following variables are supported:
_CS_GNU_LIBC_VERSION(GNU C library only; since glibc 2.3.2) โ a string which identifies the GNU C library version on this system (e.g.,"glibc 2.3.4"). she's telling you her own name and version, iconic behavior ๐โโ๏ธ_CS_GNU_LIBPTHREAD_VERSION(GNU C library only; since glibc 2.3.2) โ a string which identifies the POSIX implementation supplied by this C library (e.g.,"NPTL 2.3.4"or"linuxthreads-0.10")._CS_PATHโ a value for thePATHvariable which indicates where all the POSIX.2 standard utilities can be found. the classic, the moment, the one everyone actually wants.
okay now the plot twist that everyone forgets ๐ซ
If buf is not NULL and size is not zero, confstr() copies the value of the string to buf truncated to size - 1 bytes if necessary, with a null byte ('\0') as terminator. This can be detected by comparing the return value of confstr() against size.
If size is zero and buf is NULL, confstr() just returns the value as defined below.
note the and energy up there, bestie. both conditions. the logic is picky and we respect her for it. ๐
๐ฅ RETURN VALUE ๐ฅ
If name is a valid configuration variable, confstr() returns the number of bytes (including the terminating null byte) that would be required to hold the entire value of that variable. This value may be greater than size, which means that the value in buf is truncated.
If name is a valid configuration variable, but that variable does not have a value, then confstr() returns 0.
If name does not correspond to a valid configuration variable, confstr() returns 0, and errno is set to EINVAL.
so like... three different situations and two of them return0?? ๐ checkerrnobestie, that's the vibe check right there.
๐ ERRORS ๐
EINVALโ the value ofnameis invalid.
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
- Interface:
confstr() - Attribute: Thread safety
- Value:
MT-Safe
MT-Safe?? multithreaded-safe, no lock drama, she's main character energy in every thread. periodt. ๐
โญ STANDARDS โญ
POSIX.1-2008.
๐ HISTORY ๐
POSIX.1-2001.
๐ฆ EXAMPLES ๐ฆ
The following code fragment determines the path where to find the POSIX.2 system utilities:
char *pathbuf;
size_t n;
n = confstr(_CS_PATH, NULL, (size_t) 0);
pathbuf = malloc(n);
if (pathbuf == NULL)
abort();
confstr(_CS_PATH, pathbuf, n);
see what she did there?? first call withNULLand(size_t) 0just to ask how much room she needs, thenmalloc(n), then the real call. two-pass girlie. so smart. so clean. we're obsessed. ๐
๐ SEE ALSO ๐
getconf(1), sh(1), exec(3), fpathconf(3), pathconf(3), sysconf(3), system(3)
and that's the whole page bestie, you ate it ๐ this was Linux man-pages 6.20, dated 2026-02-08, so if you're reading this in the far future... hi, hope your glibc is thriving. confstr(3) forever. mwah ๐โจ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Thomas Koenig <ig25@rz.uni-karlsruhe.de>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms