xref: /freebsd/sbin/hastd/nv.h (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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  * $FreeBSD$
32  */
33 
34 #ifndef	_NV_H_
35 #define	_NV_H_
36 
37 #include <sys/cdefs.h>
38 
39 #include <stdarg.h>
40 #include <stdbool.h>
41 #include <stdint.h>
42 #include <stdio.h>
43 
44 #include <ebuf.h>
45 
46 struct nv;
47 
48 struct nv *nv_alloc(void);
49 void nv_free(struct nv *nv);
50 int nv_error(const struct nv *nv);
51 int nv_set_error(struct nv *nv, int error);
52 int nv_validate(struct nv *nv, size_t *extrap);
53 
54 struct ebuf *nv_hton(struct nv *nv);
55 struct nv *nv_ntoh(struct ebuf *eb);
56 
57 void nv_add_int8(struct nv *nv, int8_t value, const char *namefmt, ...)
58     __printflike(3, 4);
59 void nv_add_uint8(struct nv *nv, uint8_t value, const char *namefmt, ...)
60     __printflike(3, 4);
61 void nv_add_int16(struct nv *nv, int16_t value, const char *namefmt, ...)
62     __printflike(3, 4);
63 void nv_add_uint16(struct nv *nv, uint16_t value, const char *namefmt, ...)
64     __printflike(3, 4);
65 void nv_add_int32(struct nv *nv, int32_t value, const char *namefmt, ...)
66     __printflike(3, 4);
67 void nv_add_uint32(struct nv *nv, uint32_t value, const char *namefmt, ...)
68     __printflike(3, 4);
69 void nv_add_int64(struct nv *nv, int64_t value, const char *namefmt, ...)
70     __printflike(3, 4);
71 void nv_add_uint64(struct nv *nv, uint64_t value, const char *namefmt, ...)
72     __printflike(3, 4);
73 void nv_add_int8_array(struct nv *nv, const int8_t *value, size_t size,
74     const char *namefmt, ...) __printflike(4, 5);
75 void nv_add_uint8_array(struct nv *nv, const uint8_t *value, size_t size,
76     const char *namefmt, ...) __printflike(4, 5);
77 void nv_add_int16_array(struct nv *nv, const int16_t *value, size_t size,
78     const char *namefmt, ...) __printflike(4, 5);
79 void nv_add_uint16_array(struct nv *nv, const uint16_t *value, size_t size,
80     const char *namefmt, ...) __printflike(4, 5);
81 void nv_add_int32_array(struct nv *nv, const int32_t *value, size_t size,
82     const char *namefmt, ...) __printflike(4, 5);
83 void nv_add_uint32_array(struct nv *nv, const uint32_t *value, size_t size,
84     const char *namefmt, ...) __printflike(4, 5);
85 void nv_add_int64_array(struct nv *nv, const int64_t *value, size_t size,
86     const char *namefmt, ...) __printflike(4, 5);
87 void nv_add_uint64_array(struct nv *nv, const uint64_t *value, size_t size,
88     const char *namefmt, ...) __printflike(4, 5);
89 void nv_add_string(struct nv *nv, const char *value, const char *namefmt, ...)
90     __printflike(3, 4);
91 void nv_add_stringf(struct nv *nv, const char *name, const char *valuefmt, ...)
92     __printflike(3, 4);
93 void nv_add_stringv(struct nv *nv, const char *name, const char *valuefmt,
94     va_list valueap) __printflike(3, 0);
95 
96 int8_t nv_get_int8(struct nv *nv, const char *namefmt, ...)
97     __printflike(2, 3);
98 uint8_t nv_get_uint8(struct nv *nv, const char *namefmt, ...)
99     __printflike(2, 3);
100 int16_t nv_get_int16(struct nv *nv, const char *namefmt, ...)
101     __printflike(2, 3);
102 uint16_t nv_get_uint16(struct nv *nv, const char *namefmt, ...)
103     __printflike(2, 3);
104 int32_t nv_get_int32(struct nv *nv, const char *namefmt, ...)
105     __printflike(2, 3);
106 uint32_t nv_get_uint32(struct nv *nv, const char *namefmt, ...)
107     __printflike(2, 3);
108 int64_t nv_get_int64(struct nv *nv, const char *namefmt, ...)
109     __printflike(2, 3);
110 uint64_t nv_get_uint64(struct nv *nv, const char *namefmt, ...)
111     __printflike(2, 3);
112 const int8_t *nv_get_int8_array(struct nv *nv, size_t *sizep,
113     const char *namefmt, ...) __printflike(3, 4);
114 const uint8_t *nv_get_uint8_array(struct nv *nv, size_t *sizep,
115     const char *namefmt, ...) __printflike(3, 4);
116 const int16_t *nv_get_int16_array(struct nv *nv, size_t *sizep,
117     const char *namefmt, ...) __printflike(3, 4);
118 const uint16_t *nv_get_uint16_array(struct nv *nv, size_t *sizep,
119     const char *namefmt, ...) __printflike(3, 4);
120 const int32_t *nv_get_int32_array(struct nv *nv, size_t *sizep,
121     const char *namefmt, ...) __printflike(3, 4);
122 const uint32_t *nv_get_uint32_array(struct nv *nv, size_t *sizep,
123     const char *namefmt, ...) __printflike(3, 4);
124 const int64_t *nv_get_int64_array(struct nv *nv, size_t *sizep,
125     const char *namefmt, ...) __printflike(3, 4);
126 const uint64_t *nv_get_uint64_array(struct nv *nv, size_t *sizep,
127     const char *namefmt, ...) __printflike(3, 4);
128 const char *nv_get_string(struct nv *nv, const char *namefmt, ...)
129     __printflike(2, 3);
130 
131 bool nv_exists(struct nv *nv, const char *namefmt, ...) __printflike(2, 3);
132 void nv_assert(struct nv *nv, const char *namefmt, ...) __printflike(2, 3);
133 void nv_dump(struct nv *nv);
134 
135 #endif	/* !_NV_H_ */
136