xref: /freebsd/sbin/hastd/nv.h (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2009-2010 The FreeBSD Foundation
5  * All rights reserved.
6  *
7  * This software was developed by Pawel Jakub Dawidek under sponsorship from
8  * the FreeBSD Foundation.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef	_NV_H_
33 #define	_NV_H_
34 
35 #include <sys/cdefs.h>
36 
37 #include <stdarg.h>
38 #include <stdbool.h>
39 #include <stdint.h>
40 #include <stdio.h>
41 
42 #include <ebuf.h>
43 
44 struct nv;
45 
46 struct nv *nv_alloc(void);
47 void nv_free(struct nv *nv);
48 int nv_error(const struct nv *nv);
49 int nv_set_error(struct nv *nv, int error);
50 int nv_validate(struct nv *nv, size_t *extrap);
51 
52 struct ebuf *nv_hton(struct nv *nv);
53 struct nv *nv_ntoh(struct ebuf *eb);
54 
55 void nv_add_int8(struct nv *nv, int8_t value, const char *namefmt, ...)
56     __printflike(3, 4);
57 void nv_add_uint8(struct nv *nv, uint8_t value, const char *namefmt, ...)
58     __printflike(3, 4);
59 void nv_add_int16(struct nv *nv, int16_t value, const char *namefmt, ...)
60     __printflike(3, 4);
61 void nv_add_uint16(struct nv *nv, uint16_t value, const char *namefmt, ...)
62     __printflike(3, 4);
63 void nv_add_int32(struct nv *nv, int32_t value, const char *namefmt, ...)
64     __printflike(3, 4);
65 void nv_add_uint32(struct nv *nv, uint32_t value, const char *namefmt, ...)
66     __printflike(3, 4);
67 void nv_add_int64(struct nv *nv, int64_t value, const char *namefmt, ...)
68     __printflike(3, 4);
69 void nv_add_uint64(struct nv *nv, uint64_t value, const char *namefmt, ...)
70     __printflike(3, 4);
71 void nv_add_int8_array(struct nv *nv, const int8_t *value, size_t size,
72     const char *namefmt, ...) __printflike(4, 5);
73 void nv_add_uint8_array(struct nv *nv, const uint8_t *value, size_t size,
74     const char *namefmt, ...) __printflike(4, 5);
75 void nv_add_int16_array(struct nv *nv, const int16_t *value, size_t size,
76     const char *namefmt, ...) __printflike(4, 5);
77 void nv_add_uint16_array(struct nv *nv, const uint16_t *value, size_t size,
78     const char *namefmt, ...) __printflike(4, 5);
79 void nv_add_int32_array(struct nv *nv, const int32_t *value, size_t size,
80     const char *namefmt, ...) __printflike(4, 5);
81 void nv_add_uint32_array(struct nv *nv, const uint32_t *value, size_t size,
82     const char *namefmt, ...) __printflike(4, 5);
83 void nv_add_int64_array(struct nv *nv, const int64_t *value, size_t size,
84     const char *namefmt, ...) __printflike(4, 5);
85 void nv_add_uint64_array(struct nv *nv, const uint64_t *value, size_t size,
86     const char *namefmt, ...) __printflike(4, 5);
87 void nv_add_string(struct nv *nv, const char *value, const char *namefmt, ...)
88     __printflike(3, 4);
89 void nv_add_stringf(struct nv *nv, const char *name, const char *valuefmt, ...)
90     __printflike(3, 4);
91 void nv_add_stringv(struct nv *nv, const char *name, const char *valuefmt,
92     va_list valueap) __printflike(3, 0);
93 
94 int8_t nv_get_int8(struct nv *nv, const char *namefmt, ...)
95     __printflike(2, 3);
96 uint8_t nv_get_uint8(struct nv *nv, const char *namefmt, ...)
97     __printflike(2, 3);
98 int16_t nv_get_int16(struct nv *nv, const char *namefmt, ...)
99     __printflike(2, 3);
100 uint16_t nv_get_uint16(struct nv *nv, const char *namefmt, ...)
101     __printflike(2, 3);
102 int32_t nv_get_int32(struct nv *nv, const char *namefmt, ...)
103     __printflike(2, 3);
104 uint32_t nv_get_uint32(struct nv *nv, const char *namefmt, ...)
105     __printflike(2, 3);
106 int64_t nv_get_int64(struct nv *nv, const char *namefmt, ...)
107     __printflike(2, 3);
108 uint64_t nv_get_uint64(struct nv *nv, const char *namefmt, ...)
109     __printflike(2, 3);
110 const int8_t *nv_get_int8_array(struct nv *nv, size_t *sizep,
111     const char *namefmt, ...) __printflike(3, 4);
112 const uint8_t *nv_get_uint8_array(struct nv *nv, size_t *sizep,
113     const char *namefmt, ...) __printflike(3, 4);
114 const int16_t *nv_get_int16_array(struct nv *nv, size_t *sizep,
115     const char *namefmt, ...) __printflike(3, 4);
116 const uint16_t *nv_get_uint16_array(struct nv *nv, size_t *sizep,
117     const char *namefmt, ...) __printflike(3, 4);
118 const int32_t *nv_get_int32_array(struct nv *nv, size_t *sizep,
119     const char *namefmt, ...) __printflike(3, 4);
120 const uint32_t *nv_get_uint32_array(struct nv *nv, size_t *sizep,
121     const char *namefmt, ...) __printflike(3, 4);
122 const int64_t *nv_get_int64_array(struct nv *nv, size_t *sizep,
123     const char *namefmt, ...) __printflike(3, 4);
124 const uint64_t *nv_get_uint64_array(struct nv *nv, size_t *sizep,
125     const char *namefmt, ...) __printflike(3, 4);
126 const char *nv_get_string(struct nv *nv, const char *namefmt, ...)
127     __printflike(2, 3);
128 
129 bool nv_exists(struct nv *nv, const char *namefmt, ...) __printflike(2, 3);
130 void nv_assert(struct nv *nv, const char *namefmt, ...) __printflike(2, 3);
131 void nv_dump(struct nv *nv);
132 
133 #endif	/* !_NV_H_ */
134