summaryrefslogtreecommitdiff
path: root/strv.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-05-09 23:53:52 +0200
committerLennart Poettering <lennart@poettering.net>2010-05-09 23:53:52 +0200
commit1137a57c2677936bab56c26591a42c93a5e670a8 (patch)
tree52a4b49bae3558526bcede18fbc3aba48857a967 /strv.c
parent6e620becc8543e9ea8381fcd779dd932c2464749 (diff)
environment: allow control of the environment block via D-Bus
Diffstat (limited to 'strv.c')
-rw-r--r--strv.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/strv.c b/strv.c
index ed5755a0d1..a749096f9a 100644
--- a/strv.c
+++ b/strv.c
@@ -434,3 +434,70 @@ fail:
return NULL;
}
+
+static bool env_match(const char *t, const char *pattern) {
+ assert(t);
+ assert(pattern);
+
+ /* pattern a matches string a
+ * a matches a=
+ * a matches a=b
+ * a= matches a=
+ * a=b matches a=b
+ * a= does not match a
+ * a=b does not match a=
+ * a=b does not match a
+ * a=b does not match a=c */
+
+ if (streq(t, pattern))
+ return true;
+
+ if (!strchr(pattern, '=')) {
+ size_t l = strlen(pattern);
+
+ return strncmp(t, pattern, l) == 0 && t[l] == '=';
+ }
+
+ return false;
+}
+
+char **strv_env_delete(char **x, ...) {
+ size_t n = 0, i = 0;
+ char **l, **k, **r, **j;
+ va_list ap;
+
+ /* Deletes every entry fromx that is mentioned in the other
+ * string lists */
+
+ n = strv_length(x);
+
+ if (!(r = new(char*, n+1)))
+ return NULL;
+
+ STRV_FOREACH(k, x) {
+ va_start(ap, x);
+
+ while ((l = va_arg(ap, char**)))
+ STRV_FOREACH(j, l)
+ if (env_match(*k, *j))
+ goto delete;
+
+ va_end(ap);
+
+ if (!(r[i++] = strdup(*k))) {
+ strv_free(r);
+ return NULL;
+ }
+
+ continue;
+
+ delete:
+ va_end(ap);
+ }
+
+ r[i] = NULL;
+
+ assert(i <= n);
+
+ return r;
+}