nv.h revision 256281
11590Srgrimes/*-
21590Srgrimes * Copyright (c) 2009-2010 The FreeBSD Foundation
31590Srgrimes * All rights reserved.
41590Srgrimes *
51590Srgrimes * This software was developed by Pawel Jakub Dawidek under sponsorship from
61590Srgrimes * the FreeBSD Foundation.
71590Srgrimes *
81590Srgrimes * Redistribution and use in source and binary forms, with or without
91590Srgrimes * modification, are permitted provided that the following conditions
101590Srgrimes * are met:
111590Srgrimes * 1. Redistributions of source code must retain the above copyright
121590Srgrimes *    notice, this list of conditions and the following disclaimer.
131590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141590Srgrimes *    notice, this list of conditions and the following disclaimer in the
151590Srgrimes *    documentation and/or other materials provided with the distribution.
161590Srgrimes *
171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271590Srgrimes * SUCH DAMAGE.
281590Srgrimes *
291590Srgrimes * $FreeBSD: stable/10/sbin/hastd/nv.h 217732 2011-01-22 22:38:18Z pjd $
3087710Smarkm */
3187710Smarkm
3287710Smarkm#ifndef	_NV_H_
3387710Smarkm#define	_NV_H_
341590Srgrimes
3587710Smarkm#include <sys/cdefs.h>
3632503Scharnier
371590Srgrimes#include <stdarg.h>
3887710Smarkm#include <stdbool.h>
3987710Smarkm#include <stdint.h>
4032503Scharnier#include <stdio.h>
4132503Scharnier
4278733Sdd#include <ebuf.h>
4314443Sjoerg
44200418Sdelphijstruct nv;
4587710Smarkm
461590Srgrimesstruct nv *nv_alloc(void);
471590Srgrimesvoid nv_free(struct nv *nv);
481590Srgrimesint nv_error(const struct nv *nv);
491590Srgrimesint nv_set_error(struct nv *nv, int error);
5032503Scharnierint nv_validate(struct nv *nv, size_t *extrap);
5132503Scharnier
5232503Scharnierstruct ebuf *nv_hton(struct nv *nv);
5332503Scharnierstruct nv *nv_ntoh(struct ebuf *eb);
5432503Scharnier
5532503Scharniervoid nv_add_int8(struct nv *nv, int8_t value, const char *namefmt, ...)
5632503Scharnier    __printflike(3, 4);
571590Srgrimesvoid nv_add_uint8(struct nv *nv, uint8_t value, const char *namefmt, ...)
581590Srgrimes    __printflike(3, 4);
591590Srgrimesvoid nv_add_int16(struct nv *nv, int16_t value, const char *namefmt, ...)
6014443Sjoerg    __printflike(3, 4);
61178642Sdelphijvoid nv_add_uint16(struct nv *nv, uint16_t value, const char *namefmt, ...)
621590Srgrimes    __printflike(3, 4);
631590Srgrimesvoid nv_add_int32(struct nv *nv, int32_t value, const char *namefmt, ...)
641590Srgrimes    __printflike(3, 4);
65178642Sdelphijvoid nv_add_uint32(struct nv *nv, uint32_t value, const char *namefmt, ...)
6687710Smarkm    __printflike(3, 4);
6787710Smarkmvoid nv_add_int64(struct nv *nv, int64_t value, const char *namefmt, ...)
681590Srgrimes    __printflike(3, 4);
6932503Scharniervoid nv_add_uint64(struct nv *nv, uint64_t value, const char *namefmt, ...)
7032503Scharnier    __printflike(3, 4);
7132503Scharniervoid nv_add_int8_array(struct nv *nv, const int8_t *value, size_t size,
7232503Scharnier    const char *namefmt, ...) __printflike(4, 5);
731590Srgrimesvoid nv_add_uint8_array(struct nv *nv, const uint8_t *value, size_t size,
741590Srgrimes    const char *namefmt, ...) __printflike(4, 5);
751590Srgrimesvoid nv_add_int16_array(struct nv *nv, const int16_t *value, size_t size,
7632503Scharnier    const char *namefmt, ...) __printflike(4, 5);
7732503Scharniervoid nv_add_uint16_array(struct nv *nv, const uint16_t *value, size_t size,
781590Srgrimes    const char *namefmt, ...) __printflike(4, 5);
791590Srgrimesvoid nv_add_int32_array(struct nv *nv, const int32_t *value, size_t size,
801590Srgrimes    const char *namefmt, ...) __printflike(4, 5);
811590Srgrimesvoid nv_add_uint32_array(struct nv *nv, const uint32_t *value, size_t size,
821590Srgrimes    const char *namefmt, ...) __printflike(4, 5);
83229386Sedvoid nv_add_int64_array(struct nv *nv, const int64_t *value, size_t size,
841590Srgrimes    const char *namefmt, ...) __printflike(4, 5);
851590Srgrimesvoid nv_add_uint64_array(struct nv *nv, const uint64_t *value, size_t size,
861590Srgrimes    const char *namefmt, ...) __printflike(4, 5);
87130494Sbmsvoid nv_add_string(struct nv *nv, const char *value, const char *namefmt, ...)
881590Srgrimes    __printflike(3, 4);
893829Sachevoid nv_add_stringf(struct nv *nv, const char *name, const char *valuefmt, ...)
901590Srgrimes    __printflike(3, 4);
911590Srgrimesvoid nv_add_stringv(struct nv *nv, const char *name, const char *valuefmt,
923829Sache    va_list valueap) __printflike(3, 0);
933829Sache
943829Sacheint8_t nv_get_int8(struct nv *nv, const char *namefmt, ...)
953829Sache    __printflike(2, 3);
963829Sacheuint8_t nv_get_uint8(struct nv *nv, const char *namefmt, ...)
973829Sache    __printflike(2, 3);
983829Sacheint16_t nv_get_int16(struct nv *nv, const char *namefmt, ...)
991590Srgrimes    __printflike(2, 3);
1001590Srgrimesuint16_t nv_get_uint16(struct nv *nv, const char *namefmt, ...)
1011590Srgrimes    __printflike(2, 3);
1021590Srgrimesint32_t nv_get_int32(struct nv *nv, const char *namefmt, ...)
1031590Srgrimes    __printflike(2, 3);
1041590Srgrimesuint32_t nv_get_uint32(struct nv *nv, const char *namefmt, ...)
1051590Srgrimes    __printflike(2, 3);
1061590Srgrimesint64_t nv_get_int64(struct nv *nv, const char *namefmt, ...)
1071590Srgrimes    __printflike(2, 3);
1081590Srgrimesuint64_t nv_get_uint64(struct nv *nv, const char *namefmt, ...)
1091590Srgrimes    __printflike(2, 3);
1101590Srgrimesconst int8_t *nv_get_int8_array(struct nv *nv, size_t *sizep,
1111590Srgrimes    const char *namefmt, ...) __printflike(3, 4);
112188886Sdelphijconst uint8_t *nv_get_uint8_array(struct nv *nv, size_t *sizep,
113188886Sdelphij    const char *namefmt, ...) __printflike(3, 4);
114188886Sdelphijconst int16_t *nv_get_int16_array(struct nv *nv, size_t *sizep,
1151590Srgrimes    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