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