1*a792b843Sthorpej /* $NetBSD: prop_array.h,v 1.17 2020/06/06 21:25:59 thorpej Exp $ */ 2774eb1a3Sthorpej 3774eb1a3Sthorpej /*- 4*a792b843Sthorpej * Copyright (c) 2006, 2009, 2020 The NetBSD Foundation, Inc. 5774eb1a3Sthorpej * All rights reserved. 6774eb1a3Sthorpej * 7774eb1a3Sthorpej * This code is derived from software contributed to The NetBSD Foundation 8774eb1a3Sthorpej * by Jason R. Thorpe. 9774eb1a3Sthorpej * 10774eb1a3Sthorpej * Redistribution and use in source and binary forms, with or without 11774eb1a3Sthorpej * modification, are permitted provided that the following conditions 12774eb1a3Sthorpej * are met: 13774eb1a3Sthorpej * 1. Redistributions of source code must retain the above copyright 14774eb1a3Sthorpej * notice, this list of conditions and the following disclaimer. 15774eb1a3Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 16774eb1a3Sthorpej * notice, this list of conditions and the following disclaimer in the 17774eb1a3Sthorpej * documentation and/or other materials provided with the distribution. 18774eb1a3Sthorpej * 19774eb1a3Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20774eb1a3Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21774eb1a3Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22774eb1a3Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23774eb1a3Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24774eb1a3Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25774eb1a3Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26774eb1a3Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27774eb1a3Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28774eb1a3Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29774eb1a3Sthorpej * POSSIBILITY OF SUCH DAMAGE. 30774eb1a3Sthorpej */ 31774eb1a3Sthorpej 32774eb1a3Sthorpej #ifndef _PROPLIB_PROP_ARRAY_H_ 33774eb1a3Sthorpej #define _PROPLIB_PROP_ARRAY_H_ 34774eb1a3Sthorpej 35774eb1a3Sthorpej #include <prop/prop_object.h> 36774eb1a3Sthorpej 37774eb1a3Sthorpej typedef struct _prop_array *prop_array_t; 38774eb1a3Sthorpej 39774eb1a3Sthorpej __BEGIN_DECLS 40774eb1a3Sthorpej prop_array_t prop_array_create(void); 41774eb1a3Sthorpej prop_array_t prop_array_create_with_capacity(unsigned int); 42774eb1a3Sthorpej 43774eb1a3Sthorpej prop_array_t prop_array_copy(prop_array_t); 44774eb1a3Sthorpej prop_array_t prop_array_copy_mutable(prop_array_t); 45774eb1a3Sthorpej 46774eb1a3Sthorpej unsigned int prop_array_capacity(prop_array_t); 47774eb1a3Sthorpej unsigned int prop_array_count(prop_array_t); 4804377267Sthorpej bool prop_array_ensure_capacity(prop_array_t, unsigned int); 49774eb1a3Sthorpej 50774eb1a3Sthorpej void prop_array_make_immutable(prop_array_t); 5104377267Sthorpej bool prop_array_mutable(prop_array_t); 52774eb1a3Sthorpej 53774eb1a3Sthorpej prop_object_iterator_t prop_array_iterator(prop_array_t); 54774eb1a3Sthorpej 55774eb1a3Sthorpej prop_object_t prop_array_get(prop_array_t, unsigned int); 5604377267Sthorpej bool prop_array_set(prop_array_t, unsigned int, prop_object_t); 5704377267Sthorpej bool prop_array_add(prop_array_t, prop_object_t); 58774eb1a3Sthorpej void prop_array_remove(prop_array_t, unsigned int); 593e69f1b2Sthorpej 6004377267Sthorpej bool prop_array_equals(prop_array_t, prop_array_t); 61d21620b2Sthorpej 62d21620b2Sthorpej char * prop_array_externalize(prop_array_t); 63d21620b2Sthorpej prop_array_t prop_array_internalize(const char *); 64d21620b2Sthorpej 6504377267Sthorpej bool prop_array_externalize_to_file(prop_array_t, const char *); 66d21620b2Sthorpej prop_array_t prop_array_internalize_from_file(const char *); 671aea07a3Sthorpej 681aea07a3Sthorpej #if defined(__NetBSD__) 69133d4142Sbad struct plistref; 70133d4142Sbad 711aea07a3Sthorpej #if !defined(_KERNEL) && !defined(_STANDALONE) 72133d4142Sbad bool prop_array_externalize_to_pref(prop_array_t, struct plistref *); 73afca4e3bSjym bool prop_array_internalize_from_pref(const struct plistref *, 74afca4e3bSjym prop_array_t *); 751aea07a3Sthorpej int prop_array_send_ioctl(prop_array_t, int, unsigned long); 761aea07a3Sthorpej int prop_array_recv_ioctl(int, unsigned long, prop_array_t *); 77afca4e3bSjym int prop_array_send_syscall(prop_array_t, struct plistref *); 78afca4e3bSjym int prop_array_recv_syscall(const struct plistref *, 7907247bb7Sbouyer prop_array_t *); 801aea07a3Sthorpej #elif defined(_KERNEL) 81133d4142Sbad int prop_array_copyin(const struct plistref *, prop_array_t *); 82b87b6dbcSchristos int prop_array_copyin_size(const struct plistref *, prop_array_t *, 83b87b6dbcSchristos size_t); 84dc31d933Sbouyer int prop_array_copyout(struct plistref *, prop_array_t); 851aea07a3Sthorpej int prop_array_copyin_ioctl(const struct plistref *, const u_long, 861aea07a3Sthorpej prop_array_t *); 87de9e5b2fSchristos int prop_array_copyin_ioctl_size(const struct plistref *, 88de9e5b2fSchristos const u_long, prop_array_t *, 89de9e5b2fSchristos size_t); 901aea07a3Sthorpej int prop_array_copyout_ioctl(struct plistref *, const u_long, 911aea07a3Sthorpej prop_array_t); 921aea07a3Sthorpej #endif 931aea07a3Sthorpej #endif /* __NetBSD__ */ 941aea07a3Sthorpej 959b09c481Shaad /* 969b09c481Shaad * Utility routines to make it more convenient to work with values 979b09c481Shaad * stored in dictionaries. 989b09c481Shaad */ 999b09c481Shaad bool prop_array_get_bool(prop_array_t, unsigned int, 1009b09c481Shaad bool *); 1019b09c481Shaad bool prop_array_set_bool(prop_array_t, unsigned int, 1029b09c481Shaad bool); 1039b09c481Shaad 104*a792b843Sthorpej bool prop_array_get_schar(prop_array_t, unsigned int, 105*a792b843Sthorpej signed char *); 106*a792b843Sthorpej bool prop_array_get_uchar(prop_array_t, unsigned int, 107*a792b843Sthorpej unsigned char *); 108*a792b843Sthorpej bool prop_array_set_schar(prop_array_t, unsigned int, 109*a792b843Sthorpej signed char); 110*a792b843Sthorpej bool prop_array_set_uchar(prop_array_t, unsigned int, 111*a792b843Sthorpej unsigned char); 112*a792b843Sthorpej 113*a792b843Sthorpej bool prop_array_get_short(prop_array_t, unsigned int, 114*a792b843Sthorpej short *); 115*a792b843Sthorpej bool prop_array_get_ushort(prop_array_t, unsigned int, 116*a792b843Sthorpej unsigned short *); 117*a792b843Sthorpej bool prop_array_set_short(prop_array_t, unsigned int, 118*a792b843Sthorpej short); 119*a792b843Sthorpej bool prop_array_set_ushort(prop_array_t, unsigned int, 120*a792b843Sthorpej unsigned short); 121*a792b843Sthorpej 122*a792b843Sthorpej bool prop_array_get_int(prop_array_t, unsigned int, 123*a792b843Sthorpej int *); 124*a792b843Sthorpej bool prop_array_get_uint(prop_array_t, unsigned int, 125*a792b843Sthorpej unsigned int *); 126*a792b843Sthorpej bool prop_array_set_int(prop_array_t, unsigned int, 127*a792b843Sthorpej int); 128*a792b843Sthorpej bool prop_array_set_uint(prop_array_t, unsigned int, 129*a792b843Sthorpej unsigned int); 130*a792b843Sthorpej 131*a792b843Sthorpej bool prop_array_get_long(prop_array_t, unsigned int, 132*a792b843Sthorpej long *); 133*a792b843Sthorpej bool prop_array_get_ulong(prop_array_t, unsigned int, 134*a792b843Sthorpej unsigned long *); 135*a792b843Sthorpej bool prop_array_set_long(prop_array_t, unsigned int, 136*a792b843Sthorpej long); 137*a792b843Sthorpej bool prop_array_set_ulong(prop_array_t, unsigned int, 138*a792b843Sthorpej unsigned long); 139*a792b843Sthorpej 140*a792b843Sthorpej bool prop_array_get_longlong(prop_array_t, unsigned int, 141*a792b843Sthorpej long long *); 142*a792b843Sthorpej bool prop_array_get_ulonglong(prop_array_t, unsigned int, 143*a792b843Sthorpej unsigned long long *); 144*a792b843Sthorpej bool prop_array_set_longlong(prop_array_t, unsigned int, 145*a792b843Sthorpej long long); 146*a792b843Sthorpej bool prop_array_set_ulonglong(prop_array_t, unsigned int, 147*a792b843Sthorpej unsigned long long); 148*a792b843Sthorpej 149*a792b843Sthorpej bool prop_array_get_intptr(prop_array_t, unsigned int, 150*a792b843Sthorpej intptr_t *); 151*a792b843Sthorpej bool prop_array_get_uintptr(prop_array_t, unsigned int, 152*a792b843Sthorpej uintptr_t *); 153*a792b843Sthorpej bool prop_array_set_intptr(prop_array_t, unsigned int, 154*a792b843Sthorpej intptr_t); 155*a792b843Sthorpej bool prop_array_set_uintptr(prop_array_t, unsigned int, 156*a792b843Sthorpej uintptr_t); 157*a792b843Sthorpej 1589b09c481Shaad bool prop_array_get_int8(prop_array_t, unsigned int, 1599b09c481Shaad int8_t *); 1609b09c481Shaad bool prop_array_get_uint8(prop_array_t, unsigned int, 1619b09c481Shaad uint8_t *); 1629b09c481Shaad bool prop_array_set_int8(prop_array_t, unsigned int, 1639b09c481Shaad int8_t); 1649b09c481Shaad bool prop_array_set_uint8(prop_array_t, unsigned int, 1659b09c481Shaad uint8_t); 1669b09c481Shaad 1679b09c481Shaad bool prop_array_get_int16(prop_array_t, unsigned int, 1689b09c481Shaad int16_t *); 1699b09c481Shaad bool prop_array_get_uint16(prop_array_t, unsigned int, 1709b09c481Shaad uint16_t *); 1719b09c481Shaad bool prop_array_set_int16(prop_array_t, unsigned int, 1729b09c481Shaad int16_t); 1739b09c481Shaad bool prop_array_set_uint16(prop_array_t, unsigned int, 1749b09c481Shaad uint16_t); 1759b09c481Shaad 1769b09c481Shaad bool prop_array_get_int32(prop_array_t, unsigned int, 1779b09c481Shaad int32_t *); 1789b09c481Shaad bool prop_array_get_uint32(prop_array_t, unsigned int, 1799b09c481Shaad uint32_t *); 1809b09c481Shaad bool prop_array_set_int32(prop_array_t, unsigned int, 1819b09c481Shaad int32_t); 1829b09c481Shaad bool prop_array_set_uint32(prop_array_t, unsigned int, 1839b09c481Shaad uint32_t); 1849b09c481Shaad 1859b09c481Shaad bool prop_array_get_int64(prop_array_t, unsigned int, 1869b09c481Shaad int64_t *); 1879b09c481Shaad bool prop_array_get_uint64(prop_array_t, unsigned int, 1889b09c481Shaad uint64_t *); 1899b09c481Shaad bool prop_array_set_int64(prop_array_t, unsigned int, 1909b09c481Shaad int64_t); 1919b09c481Shaad bool prop_array_set_uint64(prop_array_t, unsigned int, 1929b09c481Shaad uint64_t); 1939b09c481Shaad 194*a792b843Sthorpej bool prop_array_set_and_rel(prop_array_t, unsigned int, 195*a792b843Sthorpej prop_object_t); 196*a792b843Sthorpej 197*a792b843Sthorpej bool prop_array_add_bool(prop_array_t, bool); 198*a792b843Sthorpej 199*a792b843Sthorpej bool prop_array_add_schar(prop_array_t, signed char); 200*a792b843Sthorpej bool prop_array_add_uchar(prop_array_t, unsigned char); 201*a792b843Sthorpej 202*a792b843Sthorpej bool prop_array_add_short(prop_array_t, short); 203*a792b843Sthorpej bool prop_array_add_ushort(prop_array_t, unsigned short); 204*a792b843Sthorpej 205*a792b843Sthorpej bool prop_array_add_int(prop_array_t, int); 206*a792b843Sthorpej bool prop_array_add_uint(prop_array_t, unsigned int); 207*a792b843Sthorpej 208*a792b843Sthorpej bool prop_array_add_long(prop_array_t, long); 209*a792b843Sthorpej bool prop_array_add_ulong(prop_array_t, unsigned long); 210*a792b843Sthorpej 211*a792b843Sthorpej bool prop_array_add_longlong(prop_array_t, long long); 212*a792b843Sthorpej bool prop_array_add_ulonglong(prop_array_t, unsigned long long); 213*a792b843Sthorpej 214*a792b843Sthorpej bool prop_array_add_intptr(prop_array_t, intptr_t); 215*a792b843Sthorpej bool prop_array_add_uintptr(prop_array_t, uintptr_t); 216*a792b843Sthorpej 217185aec71Shaad bool prop_array_add_int8(prop_array_t, int8_t); 218185aec71Shaad bool prop_array_add_uint8(prop_array_t, uint8_t); 219185aec71Shaad 220185aec71Shaad bool prop_array_add_int16(prop_array_t, int16_t); 221185aec71Shaad bool prop_array_add_uint16(prop_array_t, uint16_t); 222185aec71Shaad 223185aec71Shaad bool prop_array_add_int32(prop_array_t, int32_t); 224185aec71Shaad bool prop_array_add_uint32(prop_array_t, uint32_t); 225185aec71Shaad 226185aec71Shaad bool prop_array_add_int64(prop_array_t, int64_t); 227185aec71Shaad bool prop_array_add_uint64(prop_array_t, uint64_t); 228185aec71Shaad 229*a792b843Sthorpej bool prop_array_get_string(prop_array_t, unsigned int, 230*a792b843Sthorpej const char **); 231*a792b843Sthorpej bool prop_array_set_string(prop_array_t, unsigned int, 232*a792b843Sthorpej const char *); 233*a792b843Sthorpej bool prop_array_add_string(prop_array_t, const char *); 234*a792b843Sthorpej bool prop_array_set_string_nocopy(prop_array_t, unsigned int, 235*a792b843Sthorpej const char *); 236*a792b843Sthorpej bool prop_array_add_string_nocopy(prop_array_t, const char *); 237*a792b843Sthorpej 238*a792b843Sthorpej bool prop_array_get_data(prop_array_t, unsigned int, 239*a792b843Sthorpej const void **, size_t *); 240*a792b843Sthorpej bool prop_array_set_data(prop_array_t, unsigned int, 241*a792b843Sthorpej const void *, size_t); 242*a792b843Sthorpej bool prop_array_add_data(prop_array_t, 243*a792b843Sthorpej const void *, size_t); 244*a792b843Sthorpej bool prop_array_set_data_nocopy(prop_array_t, unsigned int, 245*a792b843Sthorpej const void *, size_t); 246*a792b843Sthorpej bool prop_array_add_data_nocopy(prop_array_t, 247*a792b843Sthorpej const void *, size_t); 248*a792b843Sthorpej 249*a792b843Sthorpej bool prop_array_add_and_rel(prop_array_t, prop_object_t); 250*a792b843Sthorpej 251*a792b843Sthorpej 252*a792b843Sthorpej /* Deprecated functions. */ 253*a792b843Sthorpej 25466c6aeebSpgoyette bool prop_array_add_cstring(prop_array_t, const char *); 2559b09c481Shaad bool prop_array_get_cstring(prop_array_t, unsigned int, 2569b09c481Shaad char **); 2579b09c481Shaad bool prop_array_set_cstring(prop_array_t, unsigned int, 2589b09c481Shaad const char *); 2599b09c481Shaad 26066c6aeebSpgoyette bool prop_array_add_cstring_nocopy(prop_array_t, const char *); 2619b09c481Shaad bool prop_array_get_cstring_nocopy(prop_array_t, 2629b09c481Shaad unsigned int, 2639b09c481Shaad const char **); 2649b09c481Shaad bool prop_array_set_cstring_nocopy(prop_array_t, 2659b09c481Shaad unsigned int, 2669b09c481Shaad const char *); 267774eb1a3Sthorpej __END_DECLS 268774eb1a3Sthorpej 269774eb1a3Sthorpej #endif /* _PROPLIB_PROP_ARRAY_H_ */ 270