Main index | Section 9 | Options |
#include <sys/cnv.h>
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 the given cookie.
The cnvlist_type() function returns the type of an element associated with the given cookie. Types which can be returned are described in nv(9).
The cnvlist_get family of functions obtains the value associated with the given 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 family of functions returns the value associated with the given cookie and removes 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 the close(2).
The cnvlist_free family of functions removes an element of the supplied cookie and frees all resources. If an element of the given cookie has the wrong type or does not exist, the program is aborted.
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 , cnvlist_get_bool(cookie)); bcookie = cookie; break; case NV_TYPE_STRING: printf("test2: %s , cnvlist_get_string(cookie)); scookie = cookie; break; } }
name = cnvlist_take_string(scookie); cnvlist_free_bool(bcookie);
printf("test2: %s , name); free(name);
printf("nvlist_empty = %d , nvlist_empty(nvl)); nvlist_destroy(nvl);
return (0);
CNV (9) | June 18, 2018 |
Main index | Section 9 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | What is this horrible fascination with Unix? The operating system of the 1960s, still gaining in popularity in the 1990s. | ” |
— Donald A. Norman |