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