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

# xprintf\_domain(3)

extensible printf domains

## NAME

**copy\_printf\_domain**, **free\_printf\_domain**, **new\_printf\_domain**, **register\_printf\_domain\_function**, **register\_printf\_domain\_render\_std** – extensible printf domains

## SYNOPSIS

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

*printf\_domain\_t*\

**copy\_printf\_domain**(*printf\_domain\_t domain*);

*void*\

**free\_printf\_domain**(*printf\_domain\_t domain*);

*printf\_domain\_t*\

**new\_printf\_domain**(*void*);

*int*\

**register\_printf\_domain\_function**(*printf\_domain\_t domain*, *int spec*, *printf\_function \*render*, *printf\_arginfo\_function \*arginfo*, *,*, *void \*context*);

*int*\

**register\_printf\_domain\_render\_std**(*printf\_domain\_t domain*, *const char \*specs*);

## DESCRIPTION

A printf domain is an extensible printf (see [xprintf(5)](/xprintf/5.md)) structure defining a set of conversion specifiers that will be used in calls to the routines discussed in [xprintf(3)](/xprintf/3.md) and [xprintf\_comp(3)](/xprintf_comp/3.md). Domains can be modified independently of one another, and do not affect the behavior of the normal printf calls in [printf(3)](/printf/3.md).

To create a new domain, call **new\_printf\_domain**(); the standard POSIX conversion specifiers are defined by default. To make a copy of an existing domain, use **copy\_printf\_domain**(). When a domain is no longer needed, call **free\_printf\_domain**() to release the associated memory.

The **register\_printf\_domain\_function**() function is used to add, modify or remove conversion specifiers for a given domain. The *spec* argument is the specifier character, which can be any printable (non-control) ASCII character, except for those characters that are used as flag/option characters. The set of flag/option characters includes the space character, and the following:

```
# $ ' * + , - . 0 1 2 3 4 5 6 7 8 9 : ; L _ h j l q t v z
```

Two user-defined callback function must also be given; see [xprintf(5)](/xprintf/5.md) for a description of these callback functions and an example of use. Setting either or both callbacks to NULL deletes the given specifier from the domain. Note that while it is permissible to redefine the standard conversion specifiers, it is not usually recommended as it may cause confusion.

The **register\_printf\_domain\_render\_std**() function is used to add pre-defined conversion specifiers to the given domain. The *specs* argument is a null-terminated C string containing one or more of the following specifier characters:

- H

  Hex dump. The ‘H’ specifier takes two arguments; the first is a pointer to the data to dump, while the second argument is the length of the data, given as type *unsigned*. Normally, 16 characters are displayed per line, as pairs of hex characters separated by spaces. Specifying a field width less than 16 will display that number of characters per line. Setting the ‘+’ (showsign) flag will prefix each line with the hex offset of the beginning character in that line. Setting the ‘#’ (alternate form) flag will postfix an ASCII representation to each line, with ‘.’ representing non-printable characters.

- M

  Errno. The ‘M’ specifier displayed the text representation of the given *int* argument, expected to be a valid *errno* value (as returned by [strerror(3)](/strerror/3.md)). Invalid errno values are represent by the “errno=” string followed by the decimal and hex values of the argument.

- Q

  Quoted. The ‘Q’ specifier displays a null-terminated string argument as a C string, with leading and trailing double quotes. Newlines, carriage-returns and tabs are represented by ‘\\n’, ‘\\r’ and ‘\\t’, respectively, while backslashes and double quotes are preceeded with a backslash. All other whitespace characters not including space itself (those in which [isspace(3)](/isspace/3.md) returns true) are displayed as octal escape sequences (a backslash followed by three octal digits). All other characters print as themselves.

- T

  time\_t/timeval/timespec. The ‘T’ specifier displays the three types of time values as a single decimal value. The argument should be a pointer to the time value to be converted. Setting the appropriate flags indicates which type is indicated:

  - ll

    The ‘ll’ (long long) flag indicates the argument points to a *struct* *timespec* structure. The default precision is 9.

  - l

    The ‘l’ (long) flag indicates the argument points to a *struct* *timeval* structure. The default precision is 6.

  - (none)

    By default, the argument points to a *time\_t* value. The default precision is 0 (the fractional part is not displayed).

    If the ‘#’ (alternate form) flag is specified, the value is displayed in years, days, hours, minutes and seconds, as in: “3y123d21h59m59s.987654” (zero values are not displayed at all). Note that the years are 365 days (no leap days).

- V

  String vis. The ‘V’ specifier uses [strvisx(3)](/strvisx/3.md) to display the null-terminated C string argument. The precision value can be used to limit the amount of the string that is processed (defaults to the entire string).

  Flag values can be used to obtain different encodings:

  - \+

    The ‘+’ (showsign) flag uses the “VIS\_WHITE \| VIS\_HTTPSTYLE” flag value to [strvisx(3)](/strvisx/3.md).

  - 0

    The ‘0’ (leading zero) flag uses the “VIS\_WHITE \| VIS\_OCTAL” flag value to [strvisx(3)](/strvisx/3.md).

  - \#

    The ‘#’ (alternate form) flag uses the “VIS\_WHITE” flag value to [strvisx(3)](/strvisx/3.md).

  - (none)

    The default flag value to [strvisx(3)](/strvisx/3.md) is “VIS\_WHITE \| VIS\_CSTYLE \| VIS\_OCTAL”.

## RETURN VALUES

The **new\_printf\_domain**() and **copy\_printf\_domain**() functions return the new domain, or NULL on failure (usually out of memory condition).

The **register\_printf\_domain\_function**() and **register\_printf\_domain\_render\_std**() return zero on success and -1 on failure (usually due to an improper specifier character or out of memory condition).

## SEE ALSO

[printf(3)](/printf/3.md), [strvisx(3)](/strvisx/3.md), [xprintf(3)](/xprintf/3.md), [xprintf\_comp(3)](/xprintf_comp/3.md), [xprintf(5)](/xprintf/5.md)
