---
name: "confstr"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/confstr"
---

# confstr(3)

get string-valued configurable variables

## NAME

**confstr** – get string-valued configurable variables

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<unistd.h\>**

*size\_t*\

**confstr**(*int name*, *char \*buf*, *size\_t len*);

## DESCRIPTION

This interface is specified by POSIX. A more flexible (but non-portable) interface is provided by [sysctl(3)](/sysctl/3.md).

The **confstr**() function provides a method for applications to get configuration defined string values. Shell programmers needing access to these parameters should use the [getconf(1)](/getconf/1.md) utility.

The *name* argument specifies the system variable to be queried. Symbolic constants for each name value are found in the include file ⟨*unistd.h*⟩. The *len* argument specifies the size of the buffer referenced by the argument *buf*. If *len* is non-zero, *buf* is a non-null pointer, and *name* has a value, up to *len* - 1 bytes of the value are copied into the buffer *buf*. The copied value is always null terminated.

The available values are as follows:

- \_CS\_DARWIN\_USER\_DIR

  Provides the path to a user's folder. The directory will be created if it does not already exist.

  This directory is created with access permissions of 0755 and restricted by the [umask(2)](/umask/2.md) of the calling process and is not intended to be used for sensitive or temporary file storage, as all users can see files created here. If the user's umask allows it, files created here will be world readable, which could lead to information disclosure.

- \_CS\_DARWIN\_USER\_TEMP\_DIR

  Provides the path to a user's temporary items directory. The directory will be created it if does not already exist. This directory is created with access permissions of 0700 and restricted by the [umask(2)](/umask/2.md) of the calling process and is a good location for temporary files.

  By default, files in this location may be cleaned (removed) by the system if they are not accessed in 3 days.

- \_CS\_DARWIN\_USER\_CACHE\_DIR

  Provides the path to the user's cache directory. The directory will be created if it does not already exist. This directory is created with access permissions of 0700 and restricted by the [umask(2)](/umask/2.md) of the calling process and is a good location for user cache data as it will not be automatically cleaned by the system.

  Files in this location will be removed during safe boot.

- \_CS\_PATH

  Return a value for the PATH environment variable that finds all the standard utilities.

## RETURN VALUES

If the call to **confstr**() is not successful, 0 is returned and *errno* is set appropriately. Otherwise, if the variable does not have a configuration defined value, 0 is returned and *errno* is not modified. Otherwise, the buffer size needed to hold the entire configuration-defined value is returned. If this size is greater than the argument *len*, the string in *buf* was truncated.

## ERRORS

The **confstr**() function may fail and set *errno* for any of the errors specified for the library functions [malloc(3)](/malloc/3.md) and [sysctl(3)](/sysctl/3.md).

In addition, the following errors may be reported:

- \[EINVAL\]

  The value of the *name* argument is invalid.

- \[ENOMEM\]

  Insufficient storage space is available.

- \[EIO\]

  I/O error communicating with dirhelper(8).

## LEGACY ERRORS

If the call to **confstr**() is not successful, -1 (rather than 0) is returned and *errno* is set appropriately.

## SEE ALSO

[getconf(1)](/getconf/1.md), [pathconf(2)](/pathconf/2.md), [sysconf(3)](/sysconf/3.md), [sysctl(3)](/sysctl/3.md)

## HISTORY

The **confstr**() function first appeared in 4.4BSD.
