X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=strv.c;h=4fe1e332536a243619e9449f6fcab14bd49b2041;hb=c0dafa4853b52741e9a4845419c00611426cefd8;hp=ecad6d59806b880e923df900511c26ae662e1c17;hpb=6091827530d6dd43479d6709fb6e9f745c11e900;p=elogind.git diff --git a/strv.c b/strv.c index ecad6d598..4fe1e3325 100644 --- a/strv.c +++ b/strv.c @@ -1,5 +1,24 @@ /*-*- Mode: C; c-basic-offset: 8 -*-*/ +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see . +***/ + #include #include #include @@ -115,3 +134,43 @@ fail: free(a); return NULL; } + +char **strv_merge(char **a, char **b) { + char **r, **k; + + if (!a) + return strv_copy(b); + + if (!b) + return strv_copy(a); + + if (!(r = new(char*, strv_length(a)+strv_length(b)+1))) + return NULL; + + for (k = r; *a; k++, a++) + if (!(*k = strdup(*a))) + goto fail; + for (; *b; k++, b++) + if (!(*k = strdup(*b))) + goto fail; + + *k = NULL; + return r; + +fail: + for (k--; k >= r; k--) + free(*k); + + return NULL; + +} + +bool strv_contains(char **l, const char *s) { + char **i; + + STRV_FOREACH(i, l) + if (streq(*i, s)) + return true; + + return false; +}