1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
30 char *strv_find(char **l, const char *name) {
41 void strv_free(char **l) {
53 char **strv_copy(char **l) {
56 if (!(r = new(char*, strv_length(l)+1)))
59 for (k = r; *l; k++, l++)
60 if (!(*k = strdup(*l)))
67 for (k--, l--; k >= r; k--, l--)
73 unsigned strv_length(char **l) {
85 char **strv_new(const char *x, ...) {
88 unsigned n = 0, i = 0;
96 while (va_arg(ap, const char*))
102 if (!(a = new(char*, n+1)))
106 if (!(a[i] = strdup(x))) {
115 while ((s = va_arg(ap, const char*))) {
116 if (!(a[i] = strdup(s)))
138 char **strv_merge(char **a, char **b) {
147 if (!(r = new(char*, strv_length(a)+strv_length(b)+1)))
150 for (k = r; *a; k++, a++)
151 if (!(*k = strdup(*a)))
154 if (!(*k = strdup(*b)))
161 for (k--; k >= r; k--)
168 bool strv_contains(char **l, const char *s) {