---
name: "cnv"
section: "9"
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/cnv"
---

# cnv(9)

API for managing name/value pairs by cookie

## NAME

**cnvlist\_get**, **cnvlist\_take**, **cnvlist\_free** – API for managing name/value pairs by cookie

## LIBRARY

library “libnv”

## SYNOPSIS

**#include \<sys/cnv.h\>**

*const* *char* *\**\

**cnvlist\_name**(*const void \*cookie*);

*int*\

**cnvlist\_type**(*const void \*cookie*);

*bool*\

**cnvlist\_get\_bool**(*const void \*cookie*);

*uint64\_t*\

**cnvlist\_get\_number**(*const void \*cookie*);

*const char \**\

**cnvlist\_get\_string**(*const void \*cookie*);

*const nvlist\_t \**\

**cnvlist\_get\_nvlist**(*const void \*cookie*);

*const void \**\

**cnvlist\_get\_binary**(*const void \*cookie*, *size\_t \*sizep*);

*const bool \**\

**cnvlist\_get\_bool\_array**(*const void \*cookie*, *size\_t \*nitemsp*);

*const uint64\_t \**\

**cnvlist\_get\_number\_array**(*const void \*cookie*, *size\_t \*nitemsp*);

*const char \* const \**\

**cnvlist\_get\_string\_array**(*const void \*cookie*, *size\_t \*nitemsp*);

*const nvlist\_t \* const \**\

**cnvlist\_get\_nvlist\_array**(*const void \*cookie*, *size\_t \*nitemsp*);

*int*\

**cnvlist\_get\_descriptor**(*const void \*cookie*);

*const int \**\

**cnvlist\_get\_descriptor\_array**(*const void \*cookie*, *size\_t \*nitemsp*);

*bool*\

**cnvlist\_take\_bool**(*void \*cookie*);

*uint64\_t*\

**cnvlist\_take\_number**(*void \*cookie*);

*const char \**\

**cnvlist\_take\_string**(*void \*cookie*);

*const nvlist\_t \**\

**cnvlist\_take\_nvlist**(*void \*cookie*);

*const void \**\

**cnvlist\_take\_binary**(*void \*cookie*, *size\_t \*sizep*);

*const bool \**\

**cnvlist\_take\_bool\_array**(*void \*cookie*, *size\_t \*nitemsp*);

*const uint64\_t \**\

**cnvlist\_take\_number\_array**(*void \*cookie*, *size\_t \*nitemsp*);

*const char \* const \**\

**cnvlist\_take\_string\_array**(*void \*cookie*, *size\_t \*nitemsp*);

*const nvlist\_t \* const \**\

**cnvlist\_take\_nvlist\_array**(*void \*cookie*, *size\_t \*nitemsp*);

*int*\

**cnvlist\_take\_descriptor**(*void \*cookie*);

*const int \**\

**cnvlist\_take\_descriptor\_array**(*void \*cookie*, *size\_t \*nitemsp*);

*void*\

**cnvlist\_free\_null**(*void \*cookie*);

*void*\

**cnvlist\_free\_bool**(*void \*cookie*);

*void*\

**cnvlist\_free\_number**(*void \*cookie*);

*void*\

**cnvlist\_free\_string**(*void \*cookie*);

*void*\

**cnvlist\_free\_nvlist**(*void \*cookie*);

*void*\

**cnvlist\_free\_descriptor**(*void \*cookie*);

*void*\

**cnvlist\_free\_binary**(*void \*cookie*);

*void*\

**cnvlist\_free\_bool\_array**(*void \*cookie*);

*void*\

**cnvlist\_free\_number\_array**(*void \*cookie*);

*void*\

**cnvlist\_free\_string\_array**(*void \*cookie*);

*void*\

**cnvlist\_free\_nvlist\_array**(*void \*cookie*);

*void*\

**cnvlist\_free\_descriptor\_array**(*void \*cookie*);

## DESCRIPTION

The **libnv** library permits easy management of name/value pairs and can send and receive them over sockets. For more information, see [nv(9)](/nv/9.md).

The concept of cookies is explained in **nvlist\_next**(), **nvlist\_get\_parent**(), and **nvlist\_get\_pararr**() from [nv(9)](/nv/9.md).

The **cnvlist\_name**() function returns the name of an element associated with *cookie*.

The **cnvlist\_type**() function returns the type of an element associated with *cookie*. Types which can be returned are described in [nv(9)](/nv/9.md).

The **cnvlist\_get** functions return the value associated with *cookie*. Returned strings, nvlists, descriptors, binaries, or arrays must not be modified by the user since they still belong to the nvlist. The nvlist must not be in an error state.

The **cnvlist\_take** functions return the value associated with the given cookie and remove the element from the nvlist. When the value is a string, binary, or array value, the caller is responsible for freeing the returned memory with **free**(*3*). When the value is an nvlist, the caller is responsible for destroying the returned nvlist with **nvlist\_destroy**(). When the value is a descriptor, the caller is responsible for closing the returned descriptor with **close**(*2*).

The **cnvlist\_free** functions remove the element identified by *cookie* and free any associated resources. If the element identified by *cookie* has the wrong type or does not exist, the program aborts.

## EXAMPLES

The following example demonstrates how to deal with the cnvlist API.

```
int type;
void *cookie, *scookie, *bcookie;
nvlist_t *nvl;
char *name;
nvl = nvlist_create(0);
nvlist_add_bool(nvl, "test", 1 == 2);
nvlist_add_string(nvl, "test2", "cnvlist");
cookie = NULL;
while (nvlist_next(nvl, &type, &cookie) != NULL) {
        switch (type) {
        case NV_TYPE_BOOL:
                printf("test: %d\n", cnvlist_get_bool(cookie));
                bcookie = cookie;
                break;
        case NV_TYPE_STRING:
                printf("test2: %s\n", cnvlist_get_string(cookie));
                scookie = cookie;
                break;
        }
}
name = cnvlist_take_string(scookie);
cnvlist_free_bool(bcookie);
printf("test2: %s\n", name);
free(name);
printf("nvlist_empty = %d\n", nvlist_empty(nvl));
nvlist_destroy(nvl);
return (0);
```

## SEE ALSO

[close(2)](/close/2.md), [free(3)](/free/3.md), [nv(9)](/nv/9.md)

## AUTHORS

The **cnv** API was created during the Google Summer Of Code 2016 by Adam Starak.
