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_strvec API provide helpers to manipulate string vectors.
32 * When duplicating vectors, the strings are not duplicated in memory,
33 * a reference counter is used.
42 * Allocate a new empty string vector.
45 * The new strvec object, or NULL on error (errno is set).
47 struct ec_strvec *ec_strvec(void);
50 * Add a string in a vector.
53 * The pointer to the string vector.
55 * The string to be added at the end of the vector.
57 * 0 on success or -1 on error (errno is set).
59 int ec_strvec_add(struct ec_strvec *strvec, const char *s);
62 * Duplicate a string vector.
65 * The pointer to the string vector.
67 * The duplicated strvec object, or NULL on error (errno is set).
69 struct ec_strvec *ec_strvec_dup(const struct ec_strvec *strvec);
72 * Duplicate a part of a string vector.
75 * The pointer to the string vector.
77 * The index of the first string to duplicate.
79 * The number of strings to duplicate.
81 * The duplicated strvec object, or NULL on error (errno is set).
83 struct ec_strvec *ec_strvec_ndup(const struct ec_strvec *strvec,
84 size_t off, size_t len);
87 * Free a string vector.
90 * The pointer to the string vector.
92 void ec_strvec_free(struct ec_strvec *strvec);
95 * Get the length of a string vector.
98 * The pointer to the string vector.
100 * The length of the vector.
102 size_t ec_strvec_len(const struct ec_strvec *strvec);
105 * Get a string element from a vector.
108 * The pointer to the string vector.
110 * The index of the string to get.
112 * The string stored at given index, or NULL on error (strvec is NULL
115 const char *ec_strvec_val(const struct ec_strvec *strvec, size_t idx);
118 * Dump a string vector.
121 * The stream where the dump is sent.
123 * The pointer to the string vector.
125 void ec_strvec_dump(FILE *out, const struct ec_strvec *strvec);