/src/libconfig/lib/strvec.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* ---------------------------------------------------------------------------- |
2 | | libconfig - A library for processing structured configuration files |
3 | | Copyright (C) 2005-2025 Mark A Lindner |
4 | | |
5 | | This file is part of libconfig. |
6 | | |
7 | | This library is free software; you can redistribute it and/or |
8 | | modify it under the terms of the GNU Lesser General Public License |
9 | | as published by the Free Software Foundation; either version 2.1 of |
10 | | the License, or (at your option) any later version. |
11 | | |
12 | | This library is distributed in the hope that it will be useful, but |
13 | | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | Lesser General Public License for more details. |
16 | | |
17 | | You should have received a copy of the GNU Library General Public |
18 | | License along with this library; if not, see |
19 | | <http://www.gnu.org/licenses/>. |
20 | | ---------------------------------------------------------------------------- |
21 | | */ |
22 | | |
23 | | #include "strvec.h" |
24 | | #include "util.h" |
25 | | |
26 | | #include <stdlib.h> |
27 | | |
28 | 0 | #define CHUNK_SIZE 32 |
29 | | |
30 | | /* ------------------------------------------------------------------------- */ |
31 | | |
32 | | void libconfig_strvec_append(strvec_t *vec, const char *s) |
33 | 0 | { |
34 | 0 | if(vec->length == vec->capacity) |
35 | 0 | { |
36 | 0 | vec->capacity += CHUNK_SIZE; |
37 | 0 | vec->strings = (const char **)libconfig_realloc( |
38 | 0 | (void *)vec->strings, |
39 | 0 | (vec->capacity + 1) * sizeof(const char *)); |
40 | 0 | vec->end = vec->strings + vec->length; |
41 | 0 | } |
42 | |
|
43 | 0 | *(vec->end) = s; |
44 | 0 | ++(vec->end); |
45 | 0 | ++(vec->length); |
46 | 0 | } |
47 | | |
48 | | /* ------------------------------------------------------------------------- */ |
49 | | |
50 | | const char **libconfig_strvec_release(strvec_t *vec) |
51 | 2.20k | { |
52 | 2.20k | const char **r = vec->strings; |
53 | 2.20k | if(r) |
54 | 0 | *(vec->end) = NULL; |
55 | | |
56 | 2.20k | __zero(vec); |
57 | 2.20k | return(r); |
58 | 2.20k | } |
59 | | |
60 | | /* ------------------------------------------------------------------------- */ |
61 | | |
62 | | void libconfig_strvec_delete(const char *const *vec) |
63 | 6.81k | { |
64 | 6.81k | const char *const *p; |
65 | | |
66 | 6.81k | if(!vec) return; |
67 | | |
68 | 0 | for(p = vec; *p; ++p) |
69 | 0 | __delete(*p); |
70 | |
|
71 | 0 | __delete(vec); |
72 | 0 | } |
73 | | |
74 | | /* ------------------------------------------------------------------------- */ |