X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fstrv.c;h=c8ff5745e82024bead8e6f997f1d1f0f4e0815b6;hp=d9aef982246c0dc158b4a190ce8832a340cfc088;hb=81ab0d3c65206140fffafefa6d14e8494edc44cb;hpb=d6c9574fb558d9e304699b1cc7522c3b133adfc9 diff --git a/src/strv.c b/src/strv.c index d9aef9822..c8ff5745e 100644 --- a/src/strv.c +++ b/src/strv.c @@ -355,7 +355,7 @@ char **strv_remove(char **l, const char *s) { 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++) { @@ -379,8 +379,8 @@ static int env_append(char **r, char ***k, char **a) { 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; @@ -474,7 +474,7 @@ char **strv_env_delete(char **x, unsigned n_lists, ...) { 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); @@ -556,3 +556,66 @@ char *strv_env_get_with_length(char **l, const char *name, size_t k) { 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; +}