carta
cnvlist_free_descriptor_array(9)

cnvlist_free_descriptor_array9

Api for managing name/value pairs by cookie

Part of cnv(9).

Usage

const char *

int

bool

uint64_t

const char *

const nvlist_t *

const void *

const bool *

const uint64_t *

const char * const *

const nvlist_t * const *

int

const int *

bool

uint64_t

const char *

const nvlist_t *

const void *

const bool *

const uint64_t *

const char * const *

const nvlist_t * const *

int

const int *

void

void

void

void

void

void

void

void

void

void

void

void

Library

library “libnv”

Overview

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

The concept of cookies is explained in nvlist_next(), nvlist_get_parent(), and nvlist_get_pararr() from nv(9).

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).

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);

History

  • FreeBSD 16.0-CURRENT (2026-10-27) to FreeBSD 14.3-RELEASE: the text shown here
  • FreeBSD 14.2-RELEASE to FreeBSD 13.3-RELEASE
  • FreeBSD 13.2-RELEASE to FreeBSD 13.1-RELEASE
  • FreeBSD 13.0-RELEASE
  • FreeBSD 12.4-RELEASE
  • FreeBSD 12.3-RELEASE
  • FreeBSD 12.2-RELEASE
  • FreeBSD 12.1-RELEASE
  • FreeBSD 12.0-RELEASE
  • FreeBSD 11.4-RELEASE
  • FreeBSD 11.3-RELEASE

Authors

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

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.