15ec81a23SMariusz Zaborski.\" 25ec81a23SMariusz Zaborski.\" Copyright (c) 2016 Adam Starak <starak.adam@gmail.com> 35ec81a23SMariusz Zaborski.\" All rights reserved. 45ec81a23SMariusz Zaborski.\" 55ec81a23SMariusz Zaborski.\" Redistribution and use in source and binary forms, with or without 65ec81a23SMariusz Zaborski.\" modification, are permitted provided that the following conditions 75ec81a23SMariusz Zaborski.\" are met: 85ec81a23SMariusz Zaborski.\" 1. Redistributions of source code must retain the above copyright 95ec81a23SMariusz Zaborski.\" notice, this list of conditions and the following disclaimer. 105ec81a23SMariusz Zaborski.\" 2. Redistributions in binary form must reproduce the above copyright 115ec81a23SMariusz Zaborski.\" notice, this list of conditions and the following disclaimer in the 125ec81a23SMariusz Zaborski.\" documentation and/or other materials provided with the distribution. 135ec81a23SMariusz Zaborski.\" 145ec81a23SMariusz Zaborski.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 155ec81a23SMariusz Zaborski.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 165ec81a23SMariusz Zaborski.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 175ec81a23SMariusz Zaborski.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 185ec81a23SMariusz Zaborski.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 195ec81a23SMariusz Zaborski.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 205ec81a23SMariusz Zaborski.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 215ec81a23SMariusz Zaborski.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 225ec81a23SMariusz Zaborski.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 235ec81a23SMariusz Zaborski.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 245ec81a23SMariusz Zaborski.\" SUCH DAMAGE. 255ec81a23SMariusz Zaborski.\" 26*ae1cc418SJohn Baldwin.Dd January 3, 2025 275ec81a23SMariusz Zaborski.Dt DNV 9 285ec81a23SMariusz Zaborski.Os 295ec81a23SMariusz Zaborski.Sh NAME 305ec81a23SMariusz Zaborski.Nm dnvlist_get , 31054cb42fSEnji Cooper.Nm dnvlist_take 32*ae1cc418SJohn Baldwin.Nd "API for getting name/value pairs with a default value" 335ec81a23SMariusz Zaborski.Sh LIBRARY 345ec81a23SMariusz Zaborski.Lb libnv 355ec81a23SMariusz Zaborski.Sh SYNOPSIS 365ec81a23SMariusz Zaborski.In sys/dnv.h 375ec81a23SMariusz Zaborski.Ft bool 385ec81a23SMariusz Zaborski.Fn dnvlist_get_bool "const nvlist_t *nvl" "const char *name" "bool defval" 395ec81a23SMariusz Zaborski.Ft uint64_t 405ec81a23SMariusz Zaborski.Fn dnvlist_get_number "const nvlist_t *nvl" "const char *name" "uint64_t defval" 415ec81a23SMariusz Zaborski.Ft char * 425ec81a23SMariusz Zaborski.Fn dnvlist_get_string "const nvlist_t *nvl" "const char *name" "const char *defval" 435ec81a23SMariusz Zaborski.Ft nvlist_t * 445ec81a23SMariusz Zaborski.Fn dnvlist_get_nvlist "const nvlist_t *nvl" "const char *name" "nvlist_t *defval" 455ec81a23SMariusz Zaborski.Ft int 465ec81a23SMariusz Zaborski.Fn dnvlist_get_descriptor "const nvlist_t *nvl" "const char *name" "int defval" 475ec81a23SMariusz Zaborski.Ft void * 485ec81a23SMariusz Zaborski.Fn dnvlist_get_binary "const nvlist_t *nvl" "const char *name" "size_t *sizep" "void *defval" "size_t defsize" 495ec81a23SMariusz Zaborski.Ft bool 505ec81a23SMariusz Zaborski.Fn dnvlist_take_bool "const nvlist_t *nvl" "const char *name" "bool defval" 515ec81a23SMariusz Zaborski.Ft uint64_t 525ec81a23SMariusz Zaborski.Fn dnvlist_take_number "const nvlist_t *nvl" "const char *name" "uint64_t defval" 535ec81a23SMariusz Zaborski.Ft char * 545ec81a23SMariusz Zaborski.Fn dnvlist_take_string "const nvlist_t *nvl" "const char *name" "const char *defval" 555ec81a23SMariusz Zaborski.Ft nvlist_t * 565ec81a23SMariusz Zaborski.Fn dnvlist_take_nvlist "const nvlist_t *nvl" "const char *name" "nvlist_t *defval" 575ec81a23SMariusz Zaborski.Ft int 585ec81a23SMariusz Zaborski.Fn dnvlist_take_descriptor "const nvlist_t *nvl" "const char *name" "int defval" 595ec81a23SMariusz Zaborski.Ft void * 605ec81a23SMariusz Zaborski.Fn dnvlist_take_binary "const nvlist_t *nvl" "const char *name" "size_t *sizep" "void *defval" "size_t defsize" 615ec81a23SMariusz Zaborski.Sh DESCRIPTION 625ec81a23SMariusz ZaborskiThe 635ec81a23SMariusz Zaborski.Nm libnv 645ec81a23SMariusz Zaborskilibrary permits easy management of name/value pairs and can send and receive 655ec81a23SMariusz Zaborskithem over sockets. 66*ae1cc418SJohn BaldwinFor more information, see 675ec81a23SMariusz Zaborski.Xr nv 9 . 685ec81a23SMariusz Zaborski.Pp 695ec81a23SMariusz ZaborskiThe 705ec81a23SMariusz Zaborski.Nm dnvlist_get 71*ae1cc418SJohn Baldwinfunctions return the value associated with 72*ae1cc418SJohn Baldwin.Fa name . 73*ae1cc418SJohn BaldwinIf an element named 74*ae1cc418SJohn Baldwin.Fa name 75*ae1cc418SJohn Baldwindoes not exist, the function returns the 765ec81a23SMariusz Zaborskivalue provided in 775ec81a23SMariusz Zaborski.Fa defval . 785ec81a23SMariusz ZaborskiReturned strings, nvlists, descriptors, binaries, or arrays must not be modified 79*ae1cc418SJohn Baldwinby the user since they still belong to the nvlist. 805ec81a23SMariusz ZaborskiIf the nvlist is in an error state, attempts to use any of these functions will 815ec81a23SMariusz Zaborskicause the program to abort. 825ec81a23SMariusz Zaborski.Pp 835ec81a23SMariusz ZaborskiThe 845ec81a23SMariusz Zaborski.Nm dnvlist_take 85*ae1cc418SJohn Baldwinfunctions return the value associated with 86*ae1cc418SJohn Baldwin.Fa name 87*ae1cc418SJohn Baldwinand removes the associated element from 88*ae1cc418SJohn Baldwin.Fa nvl . 89*ae1cc418SJohn BaldwinIf an element named 90*ae1cc418SJohn Baldwin.Fa name 91*ae1cc418SJohn Baldwindoes not exist, the value provided in 925ec81a23SMariusz Zaborski.Nm defval 935ec81a23SMariusz Zaborskiis returned. 945ec81a23SMariusz ZaborskiWhen the value is a string, binary, or array value, the caller is 955ec81a23SMariusz Zaborskiresponsible for freeing returned memory with 965ec81a23SMariusz Zaborski.Fn free 3 . 975ec81a23SMariusz ZaborskiWhen the value is an nvlist, the caller is responsible for destroying the 985ec81a23SMariusz Zaborskireturned nvlist with 995ec81a23SMariusz Zaborski.Fn nvlist_destroy . 1005ec81a23SMariusz ZaborskiWhen the value is a descriptor, the caller is responsible for closing the 1015ec81a23SMariusz Zaborskireturned descriptor with 1025ec81a23SMariusz Zaborski.Fn close 2 . 1035ec81a23SMariusz Zaborski.Sh SEE ALSO 1045ec81a23SMariusz Zaborski.Xr close 2 , 1055ec81a23SMariusz Zaborski.Xr free 3 , 1065ec81a23SMariusz Zaborski.Xr nv 9 1075ec81a23SMariusz Zaborski.Sh HISTORY 1085ec81a23SMariusz ZaborskiThe 1095ec81a23SMariusz Zaborski.Nm dnv 1105ec81a23SMariusz ZaborskiAPI appeared in 1115ec81a23SMariusz Zaborski.Fx 11.0 . 1125ec81a23SMariusz Zaborski.Sh AUTHORS 1135ec81a23SMariusz Zaborski.An -nosplit 1145ec81a23SMariusz ZaborskiThe 1155ec81a23SMariusz Zaborski.Nm dnv 1165ec81a23SMariusz ZaborskiAPI was implemented by 1175ec81a23SMariusz Zaborski.An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net 1185ec81a23SMariusz Zaborskiunder sponsorship from the FreeBSD Foundation. 1195ec81a23SMariusz ZaborskiThis manual page was written by 1205ec81a23SMariusz Zaborski.An Adam Starak Aq Mt starak.adam@gmail.com 121