2 * Copyright (c) 2009-2010 The FreeBSD Foundation
5 * This software was developed by Pawel Jakub Dawidek under sponsorship from
6 * the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
44 #define NV_TYPE_INT8 1
45 #define NV_TYPE_UINT8 2
46 #define NV_TYPE_INT16 3
47 #define NV_TYPE_UINT16 4
48 #define NV_TYPE_INT32 5
49 #define NV_TYPE_UINT32 6
50 #define NV_TYPE_INT64 7
51 #define NV_TYPE_UINT64 8
52 #define NV_TYPE_INT8_ARRAY 9
53 #define NV_TYPE_UINT8_ARRAY 10
54 #define NV_TYPE_INT16_ARRAY 11
55 #define NV_TYPE_UINT16_ARRAY 12
56 #define NV_TYPE_INT32_ARRAY 13
57 #define NV_TYPE_UINT32_ARRAY 14
58 #define NV_TYPE_INT64_ARRAY 15
59 #define NV_TYPE_UINT64_ARRAY 16
60 #define NV_TYPE_STRING 17
62 #define NV_TYPE_MASK 0x7f
63 #define NV_TYPE_FIRST NV_TYPE_INT8
64 #define NV_TYPE_LAST NV_TYPE_STRING
66 #define NV_ORDER_NETWORK 0x00
67 #define NV_ORDER_HOST 0x80
69 #define NV_ORDER_MASK 0x80
73 struct nv *nv_alloc(void);
74 void nv_free(struct nv *nv);
75 int nv_error(const struct nv *nv);
76 int nv_set_error(struct nv *nv, int error);
77 int nv_validate(struct nv *nv, size_t *extrap);
79 struct ebuf *nv_hton(struct nv *nv);
80 struct nv *nv_ntoh(struct ebuf *eb);
82 void nv_add_int8(struct nv *nv, int8_t value, const char *namefmt, ...)
84 void nv_add_uint8(struct nv *nv, uint8_t value, const char *namefmt, ...)
86 void nv_add_int16(struct nv *nv, int16_t value, const char *namefmt, ...)
88 void nv_add_uint16(struct nv *nv, uint16_t value, const char *namefmt, ...)
90 void nv_add_int32(struct nv *nv, int32_t value, const char *namefmt, ...)
92 void nv_add_uint32(struct nv *nv, uint32_t value, const char *namefmt, ...)
94 void nv_add_int64(struct nv *nv, int64_t value, const char *namefmt, ...)
96 void nv_add_uint64(struct nv *nv, uint64_t value, const char *namefmt, ...)
98 void nv_add_int8_array(struct nv *nv, const int8_t *value, size_t size,
99 const char *namefmt, ...) __printflike(4, 5);
100 void nv_add_uint8_array(struct nv *nv, const uint8_t *value, size_t size,
101 const char *namefmt, ...) __printflike(4, 5);
102 void nv_add_int16_array(struct nv *nv, const int16_t *value, size_t size,
103 const char *namefmt, ...) __printflike(4, 5);
104 void nv_add_uint16_array(struct nv *nv, const uint16_t *value, size_t size,
105 const char *namefmt, ...) __printflike(4, 5);
106 void nv_add_int32_array(struct nv *nv, const int32_t *value, size_t size,
107 const char *namefmt, ...) __printflike(4, 5);
108 void nv_add_uint32_array(struct nv *nv, const uint32_t *value, size_t size,
109 const char *namefmt, ...) __printflike(4, 5);
110 void nv_add_int64_array(struct nv *nv, const int64_t *value, size_t size,
111 const char *namefmt, ...) __printflike(4, 5);
112 void nv_add_uint64_array(struct nv *nv, const uint64_t *value, size_t size,
113 const char *namefmt, ...) __printflike(4, 5);
114 void nv_add_string(struct nv *nv, const char *value, const char *namefmt, ...)
116 void nv_add_stringf(struct nv *nv, const char *name, const char *valuefmt, ...)
118 void nv_add_stringv(struct nv *nv, const char *name, const char *valuefmt,
119 va_list valueap) __printflike(3, 0);
121 int8_t nv_get_int8(struct nv *nv, const char *namefmt, ...)
123 uint8_t nv_get_uint8(struct nv *nv, const char *namefmt, ...)
125 int16_t nv_get_int16(struct nv *nv, const char *namefmt, ...)
127 uint16_t nv_get_uint16(struct nv *nv, const char *namefmt, ...)
129 int32_t nv_get_int32(struct nv *nv, const char *namefmt, ...)
131 uint32_t nv_get_uint32(struct nv *nv, const char *namefmt, ...)
133 int64_t nv_get_int64(struct nv *nv, const char *namefmt, ...)
135 uint64_t nv_get_uint64(struct nv *nv, const char *namefmt, ...)
137 const int8_t *nv_get_int8_array(struct nv *nv, size_t *sizep,
138 const char *namefmt, ...) __printflike(3, 4);
139 const uint8_t *nv_get_uint8_array(struct nv *nv, size_t *sizep,
140 const char *namefmt, ...) __printflike(3, 4);
141 const int16_t *nv_get_int16_array(struct nv *nv, size_t *sizep,
142 const char *namefmt, ...) __printflike(3, 4);
143 const uint16_t *nv_get_uint16_array(struct nv *nv, size_t *sizep,
144 const char *namefmt, ...) __printflike(3, 4);
145 const int32_t *nv_get_int32_array(struct nv *nv, size_t *sizep,
146 const char *namefmt, ...) __printflike(3, 4);
147 const uint32_t *nv_get_uint32_array(struct nv *nv, size_t *sizep,
148 const char *namefmt, ...) __printflike(3, 4);
149 const int64_t *nv_get_int64_array(struct nv *nv, size_t *sizep,
150 const char *namefmt, ...) __printflike(3, 4);
151 const uint64_t *nv_get_uint64_array(struct nv *nv, size_t *sizep,
152 const char *namefmt, ...) __printflike(3, 4);
153 const char *nv_get_string(struct nv *nv, const char *namefmt, ...)
156 void nv_dump(struct nv *nv);