2 * Copyright (c) 2016, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the University of California, Berkeley nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * The ec_vec API provide helpers to manipulate vectors of objects
38 #include <sys/types.h>
42 /* if NULL, default does nothing */
43 typedef void (*ec_vec_elt_free_t)(void *ptr);
45 /* if NULL, default is:
46 * memcpy(dst, src, vec->elt_size)
48 typedef void (*ec_vec_elt_copy_t)(void *dst, void *src);
50 struct ec_vec *ec_vec(size_t elt_size, size_t size,
51 ec_vec_elt_copy_t copy, ec_vec_elt_free_t free);
52 int ec_vec_add_by_ref(struct ec_vec *vec, void *ptr);
54 int ec_vec_add_ptr(struct ec_vec *vec, void *elt);
55 int ec_vec_add_u8(struct ec_vec *vec, uint8_t elt);
56 int ec_vec_add_u16(struct ec_vec *vec, uint16_t elt);
57 int ec_vec_add_u32(struct ec_vec *vec, uint32_t elt);
58 int ec_vec_add_u64(struct ec_vec *vec, uint64_t elt);
60 int ec_vec_get(void *ptr, const struct ec_vec *vec, size_t idx);
62 struct ec_vec *ec_vec_dup(const struct ec_vec *vec);
63 struct ec_vec *ec_vec_ndup(const struct ec_vec *vec,
64 size_t off, size_t len);
65 void ec_vec_free(struct ec_vec *vec);
68 size_t ec_vec_len(const struct ec_vec *vec);