1 1.2 christos /* $NetBSD: cnv.h,v 1.2 2018/09/08 14:02:15 christos Exp $ */ 2 1.2 christos 3 1.1 christos /*- 4 1.1 christos * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5 1.1 christos * 6 1.1 christos * Copyright (c) 2016 Adam Starak <starak.adam (at) gmail.com> 7 1.1 christos * All rights reserved. 8 1.1 christos * 9 1.1 christos * Redistribution and use in source and binary forms, with or without 10 1.1 christos * modification, are permitted provided that the following conditions 11 1.1 christos * are met: 12 1.1 christos * 1. Redistributions of source code must retain the above copyright 13 1.1 christos * notice, this list of conditions and the following disclaimer. 14 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 christos * notice, this list of conditions and the following disclaimer in the 16 1.1 christos * documentation and/or other materials provided with the distribution. 17 1.1 christos * 18 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 19 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 22 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 1.1 christos * SUCH DAMAGE. 29 1.1 christos * 30 1.1 christos * $FreeBSD: head/sys/sys/cnv.h 335343 2018-06-18 21:26:58Z oshogbo $ 31 1.1 christos */ 32 1.1 christos 33 1.1 christos #ifndef _CNV_H_ 34 1.1 christos #define _CNV_H_ 35 1.1 christos 36 1.1 christos #include <sys/cdefs.h> 37 1.1 christos 38 1.2 christos #if !defined(_KERNEL) && !defined(_STANDALONE) 39 1.1 christos #include <stdarg.h> 40 1.1 christos #include <stdbool.h> 41 1.1 christos #include <stdint.h> 42 1.1 christos #include <stdio.h> 43 1.1 christos #endif 44 1.1 christos 45 1.1 christos #ifndef _NVLIST_T_DECLARED 46 1.1 christos #define _NVLIST_T_DECLARED 47 1.1 christos struct nvlist; 48 1.1 christos 49 1.1 christos typedef struct nvlist nvlist_t; 50 1.1 christos #endif 51 1.1 christos 52 1.1 christos __BEGIN_DECLS 53 1.1 christos 54 1.1 christos /* 55 1.1 christos * Functions which returns information about the given cookie. 56 1.1 christos */ 57 1.1 christos const char *cnvlist_name(const void *cookie); 58 1.1 christos int cnvlist_type(const void *cookie); 59 1.1 christos 60 1.1 christos /* 61 1.1 christos * The cnvlist_get functions returns value associated with the given cookie. 62 1.1 christos * If it returns a pointer, the pointer represents internal buffer and should 63 1.1 christos * not be freed by the caller. 64 1.1 christos */ 65 1.1 christos 66 1.1 christos bool cnvlist_get_bool(const void *cookie); 67 1.1 christos uint64_t cnvlist_get_number(const void *cookie); 68 1.1 christos const char *cnvlist_get_string(const void *cookie); 69 1.1 christos const nvlist_t *cnvlist_get_nvlist(const void *cookie); 70 1.1 christos const void *cnvlist_get_binary(const void *cookie, size_t *sizep); 71 1.1 christos const bool *cnvlist_get_bool_array(const void *cookie, size_t *nitemsp); 72 1.1 christos const uint64_t *cnvlist_get_number_array(const void *cookie, size_t *nitemsp); 73 1.1 christos const char * const *cnvlist_get_string_array(const void *cookie, size_t *nitemsp); 74 1.1 christos const nvlist_t * const *cnvlist_get_nvlist_array(const void *cookie, size_t *nitemsp); 75 1.2 christos #if !defined(_KERNEL) && !defined(_STANDALONE) 76 1.1 christos int cnvlist_get_descriptor(const void *cookie); 77 1.1 christos const int *cnvlist_get_descriptor_array(const void *cookie, size_t *nitemsp); 78 1.1 christos #endif 79 1.1 christos 80 1.1 christos 81 1.1 christos /* 82 1.1 christos * The cnvlist_take functions returns value associated with the given cookie and 83 1.1 christos * remove the given entry from the nvlist. 84 1.1 christos * The caller is responsible for freeing received data. 85 1.1 christos */ 86 1.1 christos 87 1.1 christos bool cnvlist_take_bool(void *cookie); 88 1.1 christos uint64_t cnvlist_take_number(void *cookie); 89 1.1 christos char *cnvlist_take_string(void *cookie); 90 1.1 christos nvlist_t *cnvlist_take_nvlist(void *cookie); 91 1.1 christos void *cnvlist_take_binary(void *cookie, size_t *sizep); 92 1.1 christos bool *cnvlist_take_bool_array(void *cookie, size_t *nitemsp); 93 1.1 christos uint64_t *cnvlist_take_number_array(void *cookie, size_t *nitemsp); 94 1.1 christos char **cnvlist_take_string_array(void *cookie, size_t *nitemsp); 95 1.1 christos nvlist_t **cnvlist_take_nvlist_array(void *cookie, size_t *nitemsp); 96 1.2 christos #if !defined(_KERNEL) && !defined(_STANDALONE) 97 1.1 christos int cnvlist_take_descriptor(void *cookie); 98 1.1 christos int *cnvlist_take_descriptor_array(void *cookie, size_t *nitemsp); 99 1.1 christos #endif 100 1.1 christos 101 1.1 christos /* 102 1.1 christos * The cnvlist_free functions removes the given name/value pair from the nvlist based on cookie 103 1.1 christos * and frees memory associated with it. 104 1.1 christos */ 105 1.1 christos 106 1.1 christos void cnvlist_free_bool(void *cookie); 107 1.1 christos void cnvlist_free_number(void *cookie); 108 1.1 christos void cnvlist_free_string(void *cookie); 109 1.1 christos void cnvlist_free_nvlist(void *cookie); 110 1.1 christos void cnvlist_free_binary(void *cookie); 111 1.1 christos void cnvlist_free_bool_array(void *cookie); 112 1.1 christos void cnvlist_free_number_array(void *cookie); 113 1.1 christos void cnvlist_free_string_array(void *cookie); 114 1.1 christos void cnvlist_free_nvlist_array(void *cookie); 115 1.2 christos #if !defined(_KERNEL) && !defined(_STANDALONE) 116 1.1 christos void cnvlist_free_descriptor(void *cookie); 117 1.1 christos void cnvlist_free_descriptor_array(void *cookie); 118 1.1 christos #endif 119 1.1 christos 120 1.1 christos __END_DECLS 121 1.1 christos 122 1.1 christos #endif /* !_CNV_H_ */ 123