---
name: "xo_create"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/xo_create"
---

# xo\_create(3)

create and destroy libxo output handles

## NAME

**xo\_create**, **xo\_create\_to\_file**, **xo\_destroy** – create and destroy libxo output handles

## LIBRARY

library “libxo”

## SYNOPSIS

**#include \<libxo/xo.h\>**

*xo\_handle\_t* *\**\

**xo\_create**(*unsigned style*, *unsigned flags*);

*xo\_handle\_t* *\**\

**xo\_create\_to\_file**(*FILE \*fp*, *unsigned style*, *unsigned flags*);

*void*\

**xo\_destroy**(*xo\_handle\_t \*handle*);

## DESCRIPTION

A **libxo** handle can be allocated using the **xo\_create**() function.

```
  Example:
    xo_handle_t *xop = xo_create(XO_STYLE_JSON, XOF_WARN);
    ....
    xo_emit_h(xop, "testing\n");
```

By default, **libxo** writes output to standard output. A convenience function is provided for situations when output should be written to a different file.

Use the XOF\_CLOSE\_FP flag to trigger a call to [fclose(3)](/fclose/3.md) for the FILE pointer when the handle is destroyed.

The **xo\_destroy**() function releases a handle and any resources it is using. Calling **xo\_destroy**() with a NULL handle will release any resources associated with the default handle.

## SEE ALSO

[xo\_emit(3)](/xo_emit/3.md), [xo\_set\_options(3)](/xo_set_options/3.md), [libxo(3)](/libxo/3.md)

## HISTORY

The **libxo** library first appeared in FreeBSD 11.0.

## AUTHORS

**libxo** was written by Phil Shafer ⟨*phil@freebsd.org*⟩.
