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