2 * Copyright (c) 2013 The FreeBSD Foundation
5 * This software was developed by Pawel Jakub Dawidek under sponsorship from
6 * the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
42 #define DNVLIST_GET(ftype, type) \
44 dnvlist_get_##type(const nvlist_t *nvl, const char *name, ftype defval) \
47 return (dnvlist_getf_##type(nvl, defval, "%s", name)); \
50 DNVLIST_GET(bool, bool)
51 DNVLIST_GET(uint64_t, number)
52 DNVLIST_GET(const char *, string)
53 DNVLIST_GET(const nvlist_t *, nvlist)
54 DNVLIST_GET(int, descriptor)
59 dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep,
60 const void *defval, size_t defsize)
63 return (dnvlist_getf_binary(nvl, sizep, defval, defsize, "%s", name));
66 #define DNVLIST_GETF(ftype, type) \
68 dnvlist_getf_##type(const nvlist_t *nvl, ftype defval, \
69 const char *namefmt, ...) \
74 va_start(nameap, namefmt); \
75 value = dnvlist_getv_##type(nvl, defval, namefmt, nameap); \
81 DNVLIST_GETF(bool, bool)
82 DNVLIST_GETF(uint64_t, number)
83 DNVLIST_GETF(const char *, string)
84 DNVLIST_GETF(const nvlist_t *, nvlist)
85 DNVLIST_GETF(int, descriptor)
90 dnvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const void *defval,
91 size_t defsize, const char *namefmt, ...)
96 va_start(nameap, namefmt);
97 value = dnvlist_getv_binary(nvl, sizep, defval, defsize, namefmt,
104 #define DNVLIST_GETV(ftype, type) \
106 dnvlist_getv_##type(const nvlist_t *nvl, ftype defval, \
107 const char *namefmt, va_list nameap) \
112 va_copy(cnameap, nameap); \
113 if (nvlist_existsv_##type(nvl, namefmt, cnameap)) \
114 value = nvlist_getv_##type(nvl, namefmt, nameap); \
121 DNVLIST_GETV(bool, bool)
122 DNVLIST_GETV(uint64_t, number)
123 DNVLIST_GETV(const char *, string)
124 DNVLIST_GETV(const nvlist_t *, nvlist)
125 DNVLIST_GETV(int, descriptor)
130 dnvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const void *defval,
131 size_t defsize, const char *namefmt, va_list nameap)
136 va_copy(cnameap, nameap);
137 if (nvlist_existsv_binary(nvl, namefmt, cnameap)) {
138 value = nvlist_getv_binary(nvl, sizep, namefmt, nameap);
148 #define DNVLIST_TAKE(ftype, type) \
150 dnvlist_take_##type(nvlist_t *nvl, const char *name, ftype defval) \
153 return (dnvlist_takef_##type(nvl, defval, "%s", name)); \
156 DNVLIST_TAKE(bool, bool)
157 DNVLIST_TAKE(uint64_t, number)
158 DNVLIST_TAKE(char *, string)
159 DNVLIST_TAKE(nvlist_t *, nvlist)
160 DNVLIST_TAKE(int, descriptor)
165 dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep,
166 void *defval, size_t defsize)
169 return (dnvlist_takef_binary(nvl, sizep, defval, defsize, "%s", name));
172 #define DNVLIST_TAKEF(ftype, type) \
174 dnvlist_takef_##type(nvlist_t *nvl, ftype defval, \
175 const char *namefmt, ...) \
180 va_start(nameap, namefmt); \
181 value = dnvlist_takev_##type(nvl, defval, namefmt, nameap); \
187 DNVLIST_TAKEF(bool, bool)
188 DNVLIST_TAKEF(uint64_t, number)
189 DNVLIST_TAKEF(char *, string)
190 DNVLIST_TAKEF(nvlist_t *, nvlist)
191 DNVLIST_TAKEF(int, descriptor)
196 dnvlist_takef_binary(nvlist_t *nvl, size_t *sizep, void *defval,
197 size_t defsize, const char *namefmt, ...)
202 va_start(nameap, namefmt);
203 value = dnvlist_takev_binary(nvl, sizep, defval, defsize, namefmt,
210 #define DNVLIST_TAKEV(ftype, type) \
212 dnvlist_takev_##type(nvlist_t *nvl, ftype defval, const char *namefmt, \
218 va_copy(cnameap, nameap); \
219 if (nvlist_existsv_##type(nvl, namefmt, cnameap)) \
220 value = nvlist_takev_##type(nvl, namefmt, nameap); \
227 DNVLIST_TAKEV(bool, bool)
228 DNVLIST_TAKEV(uint64_t, number)
229 DNVLIST_TAKEV(char *, string)
230 DNVLIST_TAKEV(nvlist_t *, nvlist)
231 DNVLIST_TAKEV(int, descriptor)
236 dnvlist_takev_binary(nvlist_t *nvl, size_t *sizep, void *defval,
237 size_t defsize, const char *namefmt, va_list nameap)
242 va_copy(cnameap, nameap);
243 if (nvlist_existsv_binary(nvl, namefmt, cnameap)) {
244 value = nvlist_takev_binary(nvl, sizep, namefmt, nameap);