-/*-*- Mode: C; c-basic-offset: 8 -*-*/
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
i = 0;
FOREACH_WORD_QUOTED(w, l, s, state)
- if (!(r[i++] = strndup(w, l))) {
+ if (!(r[i++] = cunescape_length(w, l))) {
strv_free(r);
return NULL;
}
if (!l)
return NULL;
- /* Drops every occurence of s in the string list */
+ /* Drops every occurrence of s in the string list */
for (f = t = l; *f; f++) {
return 0;
/* Add the entries of a to *k unless they already exist in *r
- * in which case they are overriden instead. This assumes
- * there is enough space in the r */
+ * in which case they are overridden instead. This assumes
+ * there is enough space in the r array. */
for (; *a; a++) {
char **j;
char **l, **k, **r, **j;
va_list ap;
- /* Deletes every entry fromx that is mentioned in the other
+ /* Deletes every entry from x that is mentioned in the other
* string lists */
n = strv_length(x);
return r;
}
+
+char **strv_env_set(char **x, const char *p) {
+
+ char **k, **r;
+
+ if (!(r = new(char*, strv_length(x)+2)))
+ return NULL;
+
+ k = r;
+ if (env_append(r, &k, x) < 0)
+ goto fail;
+
+ if (!(*(k++) = strdup(p)))
+ goto fail;
+
+ *k = NULL;
+
+ return r;
+
+fail:
+ for (k--; k >= r; k--)
+ free(*k);
+
+ free(r);
+
+ return NULL;
+
+}
+
+char *strv_env_get_with_length(char **l, const char *name, size_t k) {
+ char **i;
+
+ assert(name);
+
+ STRV_FOREACH(i, l)
+ if (strncmp(*i, name, k) == 0 &&
+ (*i)[k] == '=')
+ return *i + k + 1;
+
+ return NULL;
+}
+
+char *strv_env_get(char **l, const char *name) {
+ return strv_env_get_with_length(l, name, strlen(name));
+}
+
+char **strv_env_clean(char **l) {
+ char **r, **ret;
+
+ for (r = ret = l; *l; l++) {
+ const char *equal;
+
+ equal = strchr(*l, '=');
+
+ if (equal && equal[1] == 0) {
+ free(*l);
+ continue;
+ }
+
+ *(r++) = *l;
+ }
+
+ *r = NULL;
+
+ return ret;
+}
+
+char **strv_parse_nulstr(const char *s, size_t l) {
+ const char *p;
+ unsigned c = 0, i = 0;
+ char **v;
+
+ assert(s || l <= 0);
+
+ if (l <= 0)
+ return strv_new(NULL, NULL);
+
+ for (p = s; p < s + l; p++)
+ if (*p == 0)
+ c++;
+
+ if (s[l-1] != 0)
+ c++;
+
+ if (!(v = new0(char*, c+1)))
+ return NULL;
+
+ p = s;
+ while (p < s + l) {
+ const char *e;
+
+ e = memchr(p, 0, s + l - p);
+
+ if (!(v[i++] = strndup(p, e ? e - p : s + l - p))) {
+ strv_free(v);
+ return NULL;
+ }
+
+ if (!e)
+ break;
+
+ p = e + 1;
+ }
+
+ assert(i == c);
+
+ return v;
+}