1 | /* $NetBSD: dnv.h,v 1.2 2018/09/08 14:02:15 christos Exp $ */ |
2 | |
3 | /*- |
4 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD |
5 | * |
6 | * Copyright (c) 2013 The FreeBSD Foundation |
7 | * All rights reserved. |
8 | * |
9 | * This software was developed by Pawel Jakub Dawidek under sponsorship from |
10 | * the FreeBSD Foundation. |
11 | * |
12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions |
14 | * are met: |
15 | * 1. Redistributions of source code must retain the above copyright |
16 | * notice, this list of conditions and the following disclaimer. |
17 | * 2. Redistributions in binary form must reproduce the above copyright |
18 | * notice, this list of conditions and the following disclaimer in the |
19 | * documentation and/or other materials provided with the distribution. |
20 | * |
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | * SUCH DAMAGE. |
32 | * |
33 | * $FreeBSD: head/sys/sys/dnv.h 326823 2017-12-13 16:13:17Z pfg $ |
34 | */ |
35 | |
36 | #ifndef _DNV_H_ |
37 | #define _DNV_H_ |
38 | |
39 | #include <sys/cdefs.h> |
40 | |
41 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
42 | #include <stdarg.h> |
43 | #include <stdbool.h> |
44 | #include <stddef.h> |
45 | #include <stdint.h> |
46 | #endif |
47 | |
48 | #ifndef _NVLIST_T_DECLARED |
49 | #define _NVLIST_T_DECLARED |
50 | struct nvlist; |
51 | |
52 | typedef struct nvlist nvlist_t; |
53 | #endif |
54 | |
55 | __BEGIN_DECLS |
56 | |
57 | /* |
58 | * The dnvlist_get functions returns value associated with the given name. |
59 | * If it returns a pointer, the pointer represents internal buffer and should |
60 | * not be freed by the caller. |
61 | * If no element of the given name and type exists, the function will return |
62 | * provided default value. |
63 | */ |
64 | |
65 | bool dnvlist_get_bool(const nvlist_t *nvl, const char *name, bool defval); |
66 | uint64_t dnvlist_get_number(const nvlist_t *nvl, const char *name, uint64_t defval); |
67 | const char *dnvlist_get_string(const nvlist_t *nvl, const char *name, const char *defval); |
68 | const nvlist_t *dnvlist_get_nvlist(const nvlist_t *nvl, const char *name, const nvlist_t *defval); |
69 | int dnvlist_get_descriptor(const nvlist_t *nvl, const char *name, int defval); |
70 | const void *dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep, const void *defval, size_t defsize); |
71 | |
72 | /* |
73 | * The dnvlist_take functions returns value associated with the given name and |
74 | * remove corresponding nvpair. |
75 | * If it returns a pointer, the caller has to free it. |
76 | * If no element of the given name and type exists, the function will return |
77 | * provided default value. |
78 | */ |
79 | |
80 | bool dnvlist_take_bool(nvlist_t *nvl, const char *name, bool defval); |
81 | uint64_t dnvlist_take_number(nvlist_t *nvl, const char *name, uint64_t defval); |
82 | char *dnvlist_take_string(nvlist_t *nvl, const char *name, char *defval); |
83 | nvlist_t *dnvlist_take_nvlist(nvlist_t *nvl, const char *name, nvlist_t *defval); |
84 | int dnvlist_take_descriptor(nvlist_t *nvl, const char *name, int defval); |
85 | void *dnvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep, void *defval, size_t defsize); |
86 | |
87 | __END_DECLS |
88 | |
89 | #endif /* !_DNV_H_ */ |
90 | |