JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
man pages section 3: Extended Library Functions, Volume 3     Oracle Solaris 11.1 Information Library
search filter icon
search icon

Document Information

Preface

Extended Library Functions, Volume 3

endprojent(3PROJECT)

Exacct(3PERL)

Exacct::Catalog(3PERL)

Exacct::File(3PERL)

Exacct::Object(3PERL)

Exacct::Object::Group(3PERL)

Exacct::Object::Item(3PERL)

fgetprojent(3PROJECT)

getdefaultproj(3PROJECT)

getprojbyid(3PROJECT)

getprojbyname(3PROJECT)

getprojent(3PROJECT)

getprojidbyname(3PROJECT)

inproj(3PROJECT)

Kstat(3PERL)

Lgrp(3PERL)

libpicl(3PICL)

libpicltree(3PICLTREE)

nv_alloc_fini(3NVPAIR)

nv_alloc_init(3NVPAIR)

nv_alloc_reset(3NVPAIR)

nvlist_add_boolean(3NVPAIR)

nvlist_add_boolean_array(3NVPAIR)

nvlist_add_boolean_value(3NVPAIR)

nvlist_add_byte(3NVPAIR)

nvlist_add_byte_array(3NVPAIR)

nvlist_add_double(3NVPAIR)

nvlist_add_int16(3NVPAIR)

nvlist_add_int16_array(3NVPAIR)

nvlist_add_int32(3NVPAIR)

nvlist_add_int32_array(3NVPAIR)

nvlist_add_int64(3NVPAIR)

nvlist_add_int64_array(3NVPAIR)

nvlist_add_int8(3NVPAIR)

nvlist_add_int8_array(3NVPAIR)

nvlist_add_nvlist(3NVPAIR)

nvlist_add_nvlist_array(3NVPAIR)

nvlist_add_nvpair(3NVPAIR)

nvlist_add_string(3NVPAIR)

nvlist_add_string_array(3NVPAIR)

nvlist_add_uint16(3NVPAIR)

nvlist_add_uint16_array(3NVPAIR)

nvlist_add_uint32(3NVPAIR)

nvlist_add_uint32_array(3NVPAIR)

nvlist_add_uint64(3NVPAIR)

nvlist_add_uint64_array(3NVPAIR)

nvlist_add_uint8(3NVPAIR)

nvlist_add_uint8_array(3NVPAIR)

nvlist_alloc(3NVPAIR)

nvlist_dup(3NVPAIR)

nvlist_exists(3NVPAIR)

nvlist_flag(3NVPAIR)

nvlist_free(3NVPAIR)

nvlist_lookup_boolean(3NVPAIR)

nvlist_lookup_boolean_array(3NVPAIR)

nvlist_lookup_boolean_value(3NVPAIR)

nvlist_lookup_byte(3NVPAIR)

nvlist_lookup_byte_array(3NVPAIR)

nvlist_lookup_double(3NVPAIR)

nvlist_lookup_int16(3NVPAIR)

nvlist_lookup_int16_array(3NVPAIR)

nvlist_lookup_int32(3NVPAIR)

nvlist_lookup_int32_array(3NVPAIR)

nvlist_lookup_int64(3NVPAIR)

nvlist_lookup_int64_array(3NVPAIR)

nvlist_lookup_int8(3NVPAIR)

nvlist_lookup_int8_array(3NVPAIR)

nvlist_lookup_nv_alloc(3NVPAIR)

nvlist_lookup_nvlist(3NVPAIR)

nvlist_lookup_nvlist_array(3NVPAIR)

nvlist_lookup_nvpair(3NVPAIR)

nvlist_lookup_pairs(3NVPAIR)

nvlist_lookup_string(3NVPAIR)

nvlist_lookup_string_array(3NVPAIR)

nvlist_lookup_uint16(3NVPAIR)

nvlist_lookup_uint16_array(3NVPAIR)

nvlist_lookup_uint32(3NVPAIR)

nvlist_lookup_uint32_array(3NVPAIR)

nvlist_lookup_uint64(3NVPAIR)

nvlist_lookup_uint64_array(3NVPAIR)

nvlist_lookup_uint8(3NVPAIR)

nvlist_lookup_uint8_array(3NVPAIR)

nvlist_merge(3NVPAIR)

nvlist_next_nvpair(3NVPAIR)

nvlist_pack(3NVPAIR)

nvlist_remove(3NVPAIR)

nvlist_remove_all(3NVPAIR)

nvlist_size(3NVPAIR)

nvlist_unpack(3NVPAIR)

nvlist_xalloc(3NVPAIR)

nvlist_xdup(3NVPAIR)

nvlist_xpack(3NVPAIR)

nvlist_xunpack(3NVPAIR)

nvpair_name(3NVPAIR)

nvpair_type(3NVPAIR)

nvpair_value_boolean_array(3NVPAIR)

nvpair_value_boolean_value(3NVPAIR)

nvpair_value_byte(3NVPAIR)

nvpair_value_byte_array(3NVPAIR)

nvpair_value_double(3NVPAIR)

nvpair_value_int16(3NVPAIR)

nvpair_value_int16_array(3NVPAIR)

nvpair_value_int32(3NVPAIR)

nvpair_value_int32_array(3NVPAIR)

nvpair_value_int64(3NVPAIR)

nvpair_value_int64_array(3NVPAIR)

nvpair_value_int8(3NVPAIR)

nvpair_value_int8_array(3NVPAIR)

nvpair_value_nvlist(3NVPAIR)

nvpair_value_nvlist_array(3NVPAIR)

nvpair_value_string(3NVPAIR)

nvpair_value_string_array(3NVPAIR)

nvpair_value_uint16(3NVPAIR)

nvpair_value_uint16_array(3NVPAIR)

nvpair_value_uint32(3NVPAIR)

nvpair_value_uint32_array(3NVPAIR)

nvpair_value_uint64(3NVPAIR)

nvpair_value_uint64_array(3NVPAIR)

nvpair_value_uint8(3NVPAIR)

nvpair_value_uint8_array(3NVPAIR)

pam(3PAM)

pam_acct_mgmt(3PAM)

pam_authenticate(3PAM)

pam_chauthtok(3PAM)

pam_close_session(3PAM)

pam_end(3PAM)

pam_eval(3PAM)

pam_get_data(3PAM)

pam_getenv(3PAM)

pam_getenvlist(3PAM)

pam_get_item(3PAM)

pam_get_user(3PAM)

pam_open_session(3PAM)

pam_putenv(3PAM)

pam_setcred(3PAM)

pam_set_data(3PAM)

pam_set_item(3PAM)

pam_sm(3PAM)

pam_sm_acct_mgmt(3PAM)

pam_sm_authenticate(3PAM)

pam_sm_chauthtok(3PAM)

pam_sm_close_session(3PAM)

pam_sm_open_session(3PAM)

pam_sm_setcred(3PAM)

pam_start(3PAM)

pam_strerror(3PAM)

papiAttributeListAddBoolean(3PAPI)

papiAttributeListAddCollection(3PAPI)

papiAttributeListAddDatetime(3PAPI)

papiAttributeListAddInteger(3PAPI)

papiAttributeListAddMetadata(3PAPI)

papiAttributeListAddRange(3PAPI)

papiAttributeListAddResolution(3PAPI)

papiAttributeListAddString(3PAPI)

papiAttributeListAddValue(3PAPI)

papiAttributeListDelete(3PAPI)

papiAttributeListFind(3PAPI)

papiAttributeListFree(3PAPI)

papiAttributeListFromString(3PAPI)

papiAttributeListGetBoolean(3PAPI)

papiAttributeListGetCollection(3PAPI)

papiAttributeListGetDatetime(3PAPI)

papiAttributeListGetInteger(3PAPI)

papiAttributeListGetMetadata(3PAPI)

papiAttributeListGetNext(3PAPI)

papiAttributeListGetRange(3PAPI)

papiAttributeListGetResolution(3PAPI)

papiAttributeListGetString(3PAPI)

papiAttributeListGetValue(3PAPI)

papiAttributeListToString(3PAPI)

papiJobCancel(3PAPI)

papiJobFree(3PAPI)

papiJobGetAttributeList(3PAPI)

papiJobGetId(3PAPI)

papiJobGetJobTicket(3PAPI)

papiJobGetPrinterName(3PAPI)

papiJobHold(3PAPI)

papiJobListFree(3PAPI)

papiJobModify(3PAPI)

papiJobMove(3PAPI)

papiJobPromote(3PAPI)

papiJobQuery(3PAPI)

papiJobRelease(3PAPI)

papiJobRestart(3PAPI)

papiJobStreamClose(3PAPI)

papiJobStreamOpen(3PAPI)

papiJobStreamWrite(3PAPI)

papiJobSubmit(3PAPI)

papiJobSubmitByReference(3PAPI)

papiJobValidate(3PAPI)

papiLibrarySupportedCall(3PAPI)

papiLibrarySupportedCalls(3PAPI)

papiPrinterAdd(3PAPI)

papiPrinterDisable(3PAPI)

papiPrinterEnable(3PAPI)

papiPrinterFree(3PAPI)

papiPrinterGetAttributeList(3PAPI)

papiPrinterListFree(3PAPI)

papiPrinterListJobs(3PAPI)

papiPrinterModify(3PAPI)

papiPrinterPause(3PAPI)

papiPrinterPurgeJobs(3PAPI)

papiPrinterQuery(3PAPI)

papiPrinterRemove(3PAPI)

papiPrinterResume(3PAPI)

papiPrintersList(3PAPI)

papiServiceCreate(3PAPI)

papiServiceDestroy(3PAPI)

papiServiceGetAppData(3PAPI)

papiServiceGetAttributeList(3PAPI)

papiServiceGetEncryption(3PAPI)

papiServiceGetPassword(3PAPI)

papiServiceGetServiceName(3PAPI)

papiServiceGetStatusMessage(3PAPI)

papiServiceGetUserName(3PAPI)

papiServiceSetAppData(3PAPI)

papiServiceSetAuthCB(3PAPI)

papiServiceSetEncryption(3PAPI)

papiServiceSetPassword(3PAPI)

papiServiceSetUserName(3PAPI)

papiStatusString(3PAPI)

picld_log(3PICLTREE)

picld_plugin_register(3PICLTREE)

picl_find_node(3PICL)

picl_get_first_prop(3PICL)

picl_get_frutree_parent(3PICL)

picl_get_next_by_col(3PICL)

picl_get_next_by_row(3PICL)

picl_get_next_prop(3PICL)

picl_get_node_by_path(3PICL)

picl_get_prop_by_name(3PICL)

picl_get_propinfo(3PICL)

picl_get_propinfo_by_name(3PICL)

picl_get_propval(3PICL)

picl_get_propval_by_name(3PICL)

picl_get_root(3PICL)

picl_initialize(3PICL)

picl_set_propval(3PICL)

picl_set_propval_by_name(3PICL)

picl_shutdown(3PICL)

picl_strerror(3PICL)

picl_wait(3PICL)

picl_walk_tree_by_class(3PICL)

pool_associate(3POOL)

pool_component_info(3POOL)

pool_component_to_elem(3POOL)

pool_conf_alloc(3POOL)

pool_conf_close(3POOL)

pool_conf_commit(3POOL)

pool_conf_export(3POOL)

pool_conf_free(3POOL)

pool_conf_info(3POOL)

pool_conf_location(3POOL)

pool_conf_open(3POOL)

pool_conf_remove(3POOL)

pool_conf_rollback(3POOL)

pool_conf_status(3POOL)

pool_conf_to_elem(3POOL)

pool_conf_update(3POOL)

pool_conf_validate(3POOL)

pool_create(3POOL)

pool_destroy(3POOL)

pool_dissociate(3POOL)

pool_dynamic_location(3POOL)

pool_error(3POOL)

pool_get_binding(3POOL)

pool_get_owning_resource(3POOL)

pool_get_pool(3POOL)

pool_get_property(3POOL)

pool_get_resource(3POOL)

pool_get_resource_binding(3POOL)

pool_get_status(3POOL)

pool_info(3POOL)

pool_put_property(3POOL)

pool_query_components(3POOL)

pool_query_pool_resources(3POOL)

pool_query_pools(3POOL)

pool_query_resource_components(3POOL)

pool_query_resources(3POOL)

pool_resource_create(3POOL)

pool_resource_destroy(3POOL)

pool_resource_info(3POOL)

pool_resource_to_elem(3POOL)

pool_resource_transfer(3POOL)

pool_resource_type_list(3POOL)

pool_resource_xtransfer(3POOL)

pool_rm_property(3POOL)

pool_set_binding(3POOL)

pool_set_status(3POOL)

pool_static_location(3POOL)

pool_strerror(3POOL)

pool_to_elem(3POOL)

pool_value_alloc(3POOL)

pool_value_free(3POOL)

pool_value_get_bool(3POOL)

pool_value_get_double(3POOL)

pool_value_get_int64(3POOL)

pool_value_get_name(3POOL)

pool_value_get_string(3POOL)

pool_value_get_type(3POOL)

pool_value_get_uint64(3POOL)

pool_value_set_bool(3POOL)

pool_value_set_double(3POOL)

pool_value_set_int64(3POOL)

pool_value_set_name(3POOL)

pool_value_set_string(3POOL)

pool_value_set_uint64(3POOL)

pool_version(3POOL)

pool_walk_components(3POOL)

pool_walk_pools(3POOL)

pool_walk_properties(3POOL)

pool_walk_resources(3POOL)

Privilege(3PERL)

proc_service(3PROC)

Project(3PERL)

project_walk(3PROJECT)

ps_kill(3PROC)

ps_lcontinue(3PROC)

ps_lgetcxregs(3PROC)

ps_lgetcxregsize(3PROC)

ps_lgetfpregs(3PROC)

ps_lgetregs(3PROC)

ps_lgetxregs(3PROC)

ps_lgetxregsize(3PROC)

ps_lrolltoaddr(3PROC)

ps_lsetcxregs(3PROC)

ps_lsetfpregs(3PROC)

ps_lsetregs(3PROC)

ps_lsetxregs(3PROC)

ps_lstop(3PROC)

ps_pcontinue(3PROC)

ps_pdread(3PROC)

ps_pdwrite(3PROC)

ps_pglobal_lookup(3PROC)

ps_pglobal_sym(3PROC)

ps_pread(3PROC)

ps_pstop(3PROC)

ps_ptread(3PROC)

ps_ptwrite(3PROC)

ps_pwrite(3PROC)

ptree_add_node(3PICLTREE)

ptree_add_prop(3PICLTREE)

ptree_add_row_to_table(3PICLTREE)

ptree_create_and_add_node(3PICLTREE)

ptree_create_and_add_prop(3PICLTREE)

ptree_create_node(3PICLTREE)

ptree_create_prop(3PICLTREE)

ptree_create_table(3PICLTREE)

ptree_delete_node(3PICLTREE)

ptree_delete_prop(3PICLTREE)

ptree_destroy_node(3PICLTREE)

ptree_destroy_prop(3PICLTREE)

ptree_find_node(3PICLTREE)

ptree_get_first_prop(3PICLTREE)

ptree_get_frutree_parent(3PICLTREE)

ptree_get_next_by_col(3PICLTREE)

ptree_get_next_by_row(3PICLTREE)

ptree_get_next_prop(3PICLTREE)

ptree_get_node_by_path(3PICLTREE)

ptree_get_prop_by_name(3PICLTREE)

ptree_get_propinfo(3PICLTREE)

ptree_get_propinfo_by_name(3PICLTREE)

ptree_get_propval(3PICLTREE)

ptree_get_propval_by_name(3PICLTREE)

ptree_get_root(3PICLTREE)

ptree_init_propinfo(3PICLTREE)

ptree_post_event(3PICLTREE)

ptree_register_handler(3PICLTREE)

ptree_unregister_handler(3PICLTREE)

ptree_update_propval(3PICLTREE)

ptree_update_propval_by_name(3PICLTREE)

ptree_walk_tree_by_class(3PICLTREE)

reparse_add(3REPARSE)

reparse_create(3REPARSE)

reparse_delete(3REPARSE)

reparse_deref(3REPARSE)

reparse_free(3REPARSE)

reparse_init(3REPARSE)

reparse_parse(3REPARSE)

reparse_remove(3REPARSE)

reparse_unparse(3REPARSE)

reparse_validate(3REPARSE)

rp_plugin_init(3REPARSE)

setproject(3PROJECT)

setprojent(3PROJECT)

Task(3PERL)

Ucred(3PERL)

nvlist_alloc

, nvlist_free

, nvlist_size

, nvlist_pack

, nvlist_unpack

, nvlist_dup

, nvlist_merge

, nvlist_flag

, nvlist_xalloc

, nvlist_xpack

, nvlist_xunpack

, nvlist_xdup

, nvlist_lookup_nv_alloc

, nv_alloc_init

, nv_alloc_reset

, nv_alloc_fini

- manage a name-value pair list

Synopsis

cc [ flag... ] file... -lnvpair [ library... ]
#include <libnvpair.h> 

int nvlist_alloc(nvlist_t **nvlp, uint_t nvflag, int flag);
int nvlist_xalloc(nvlist_t **nvlp, uint_t nvflag,
     nv_alloc_t * nva);
void nvlist_free(nvlist_t *nvl);
int nvlist_size(nvlist_t *nvl, size_t *size, int encoding);
int nvlist_pack(nvlist_t *nvl, char **bufp, size_t *buflen,
     int encoding, int flag);
int nvlist_xpack(nvlist_t *nvl, char **bufp, size_t *buflen,
     int encoding, nv_alloc_t * nva);
int nvlist_unpack(char *buf, size_t buflen, nvlist_t **nvlp,
     int flag);
int nvlist_xunpack(char *buf, size_t buflen, nvlist_t **nvlp,
     nv_alloc_t * nva);
int nvlist_dup(nvlist_t *nvl, nvlist_t **nvlp, int flag);
int nvlist_xdup(nvlist_t *nvl, nvlist_t **nvlp,
     nv_alloc_t * nva);
int nvlist_merge(nvlist_t *dst, nvlist_t *nvl, int flag);
uint_t  nvlist_nvflag(nvlist_t *nvl);
nv_alloc_t * nvlist_lookup_nv_alloc(nvlist_t *nvl);
int nv_alloc_init(nv_alloc_t *nva, const nv_alloc_ops_t *nvo,
     /* args */ ...);
void nv_alloc_reset(nv_alloc_t *nva);
void nv_alloc_fini(nv_alloc_t *nva);

Parameters

nvlp

Address of a pointer to nvlist_t.

nvflag

Specify bit fields defining nvlist properties:

NV_UNIQUE_NAME

The nvpair names are unique.

NV_UNIQUE_NAME_TYPE

Name-data type combination is unique.

See nvlist_add_boolean_value(3NVPAIR) for a description of these flags values, and for behavior when neither is specified.

flag

Specify 0. Reserved for future use.

nvl

The nvlist_t to be processed.

dst

The destination nvlist_t.

size

Pointer to buffer to contain the encoded size.

bufp

Address of buffer to pack nvlist into. Must be 8-byte aligned. If NULL, library will allocate memory.

buf

Buffer containing packed nvlist.

buflen

Size of buffer bufp or buf points to.

encoding

Encoding method for packing.

nvo

Pluggable allocator operations pointer (nv_alloc_ops_t).

nva

A pointer to an nv_alloc_t structure to be used for the specified nvlist_t.

Description

List Manipulation

The nvlist_alloc() function allocates a new name-value pair list and updates nvlp to point to the handle. The nvflag argument specifies nvlist properties to remain persistent across packing, unpacking, and duplication. If NV_UNIQUE_NAME was specified for nvflag, existing nvpairs with matching names are removed before the new nvpair is added. If NV_UNIQUE_NAME_TYPE was specified for nvflag, existing nvpairs with matching names and data types are removed before the new nvpair is added. See nvlist_add_byte(3NVPAIR) for more information.

The nvlist_xalloc() function is identical to nvlist_alloc() except that nvlist_xalloc() can use a different allocator, as described in the Pluggable Allocators section.

The nvlist_free() function frees a name-value pair list.

The nvlist_nvflag() function returns the nvflag value for the nvlist, specified when it was allocated using nvlist_alloc() or nvlist_xalloc().

The nvlist_size() function returns the minimum size of a contiguous buffer large enough to pack nvl. The encoding parameter specifies the method of encoding when packing nvl. Supported encoding methods are:

NV_ENCODE_NATIVE

Straight bcopy() as described in bcopy(3C).

NV_ENCODE_XDR

Use XDR encoding, suitable for sending to another host.

The nvlist_pack() function packs nvl into contiguous memory starting at *bufp. The encoding parameter specifies the method of encoding (see above).

The nvlist_xpack() function is identical to nvlist_pack() except that nvlist_xpack() can use a different allocator.

The nvlist_unpack() function takes a buffer with a packed nvlist_t and unpacks it into a searchable nvlist_t. The library allocates memory for nvlist_t. The caller is responsible for freeing the memory by calling nvlist_free().

The nvlist_xunpack() function is identical to nvlist_unpack() except that nvlist_xunpack() can use a different allocator.

The nvlist_dup() function makes a copy of nvl and updates nvlp to point to the copy.

The nvlist_xdup() function is identical to nvlist_dup() except that nvlist_xdup() can use a different allocator.

The nvlist_merge() function adds copies of all name-value pairs from nvl to dst. Name-value pairs in dst are replaced with name-value pairs from nvl that have identical names (if dst has the type NV_UNIQUE_NAME) or identical names and types (if dst has the type NV_UNIQUE_NAME_TYPE).

The nvlist_lookup_nv_alloc() function retrieves the pointer to the allocator that was used when manipulating a name-value pair list.

Pluggable Allocators

Using Pluggable Allocators

The nv_alloc_init(), nv_alloc_reset() and nv_alloc_fini() functions provide an interface to specify the allocator to be used when manipulating a name-value pair list.

The nv_alloc_init() function determines the allocator properties and puts them into the nva argument. The application must specify the nv_arg and nvo arguments and an optional variable argument list. The optional arguments are passed to the (*nv_ao_init()) function.

The nva argument must be passed to nvlist_xalloc(), nvlist_xpack(), nvlist_xunpack() and nvlist_xdup().

The nv_alloc_reset() function is responsible for resetting the allocator properties to the data specified by nv_alloc_init(). When no (*nv_ao_reset()) function is specified, nv_alloc_reset() has no effect.

The nv_alloc_fini() function destroys the allocator properties determined by nv_alloc_init(). When a (*nv_ao_fini()) function is specified, it is called from nv_alloc_fini().

The disposition of the allocated objects and the memory used to store them is left to the allocator implementation.

The nv_alloc_nosleep nv_alloc_t can be used with nvlist_xalloc() to mimic the behavior of nvlist_alloc().

The nvpair allocator framework provides a pointer to the operation structure of a fixed buffer allocator. This allocator, nv_fixed_ops, uses a pre-allocated buffer for memory allocations. It is intended primarily for kernel use and is described on nvlist_alloc(9F).

An example program that uses the pluggable allocator functionality is provided on nvlist_alloc(9F).

Creating Pluggable Allocators

Any producer of name-value pairs can specify its own allocator functions. The application must provide the following pluggable allocator operations:

int (*nv_ao_init)(nv_alloc_t *nva, va_list nv_valist);
void (*nv_ao_fini)(nv_alloc_t *nva);
void *(*nv_ao_alloc)(nv_alloc_t *nva, size_t sz);
void (*nv_ao_reset)(nv_alloc_t *nva);
void (*nv_ao_free)(nv_alloc_t *nva, void *buf, size_t sz);

The nva argument of the allocator implementation is always the first argument.

The optional (*nv_ao_init()) function is responsible for filling the data specified by nv_alloc_init() into the nva_arg argument. The (*nv_ao_init()) function is only called when nv_alloc_init() is executed.

The optional (*nv_ao_fini()) function is responsible for the cleanup of the allocator implementation. It is called by nv_alloc_fini().

The required (*nv_ao_alloc()) function is used in the nvpair allocation framework for memory allocation. The sz argument specifies the size of the requested buffer.

The optional (*nv_ao_reset()) function is responsible for resetting the nva_arg argument to the data specified by nv_alloc_init().

The required (*nv_ao_free()) function is used in the nvpair allocator framework for memory deallocation. The buf argument is a pointer to a block previously allocated by the (*nv_ao_alloc()) function. The size argument sz must exactly match the original allocation.

The disposition of the allocated objects and the memory used to store them is left to the allocator implementation.

Return Values

These functions return 0 on success and an error value on failure.

The nvlist_lookup_nv_alloc() function returns a pointer to an allocator.

Errors

These functions will fail if:

EINVAL

There is an invalid argument.

The nvlist_alloc(), nvlist_dup(), nvlist_pack(), nvlist_unpack(), nvlist_merge(), nvlist_xalloc(), nvlist_xdup(), nvlist_xpack(), and nvlist_xunpack() functions will fail if:

ENOMEM

There is insufficient memory.

The nvlist_pack(), nvlist_unpack(), nvlist_xpack(), and nvlist_xunpack() functions will fail if:

EFAULT

An encode/decode error occurs.

ENOTSUP

An encode/decode method is not supported.

Examples

/*
 * Program to create an nvlist.
 */
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <libnvpair.h>

/* generate a packed nvlist */
static int
create_packed_nvlist(char **buf, uint_t *buflen, int encode)
{
    uchar_t bytes[] = {0xaa, 0xbb, 0xcc, 0xdd};
    int32_t int32[] = {3, 4, 5};
    char *strs[] = {"child0", "child1", "child2"};
    int err;
    nvlist_t *nvl;

    err = nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0);    /* allocate list */
    if (err) {
        (void) printf("nvlist_alloc() failed\n");
        return (err);
    }

    /* add a value of some types */
    if ((nvlist_add_byte(nvl, "byte", bytes[0]) != 0) ||
        (nvlist_add_int32(nvl, "int32", int32[0]) != 0) ||
        (nvlist_add_int32_array(nvl, "int32_array", int32, 3) != 0) ||
        (nvlist_add_string_array(nvl, "string_array", strs, 3) != 0)) {
        nvlist_free(nvl);
        return (-1);
    }

    err = nvlist_size(nvl, buflen, encode);
    if (err) {
        (void) printf("nvlist_size: %s\n", strerror(err));
        nvlist_free(nvl);
        return (err);
    }

    /* pack into contig. memory */
    err = nvlist_pack(nvl, buf, buflen, encode, 0);
    if (err)
        (void) printf("nvlist_pack: %s\n", strerror(err));

    /* free the original list */
    nvlist_free(nvl);
    return (err);
}

/* selectively print nvpairs */
static void
nvlist_lookup_and_print(nvlist_t *nvl)
{
    char **str_val;
    int i, int_val;
    uint_t nval;

    if (nvlist_lookup_int32(nvl, "int32", &int_val) == 0)
        (void) printf("int32 = %d\n", int_val);
    if (nvlist_lookup_string_array(nvl, "string_array", &str_val, &nval)
        == 0) {
            (void) printf("string_array =");
            for (i = 0; i < nval; i++)
                    (void) printf(" %s", str_val[i]);
            (void) printf("\n");
    }
}

/*ARGSUSED*/
int
main(int argc, char *argv[])
{
    int err;
    char *buf = NULL;
    size_t buflen;
    nvlist_t *nvl = NULL;

    if (create_packed_nvlist(&buf, &buflen, NV_ENCODE_XDR) != 0) {
        (void) printf("cannot create packed nvlist buffer\n");
        return(-1);
        }

    /* unpack into an nvlist_t */
    err = nvlist_unpack(buf, buflen, &nvl, 0);
    if (err) {
        (void) printf("nvlist_unpack(): %s\n", strerror(err));
        return(-1);
    }

    /* selectively print out attributes */
    nvlist_lookup_and_print(nvl);
    return(0);
}

Attributes

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
MT-Safe

See Also

libnvpair(3LIB), attributes(5), nvlist_add_boolean_value(3NVPAIR), nvlist_alloc(9F)