X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fstrv.c;h=a5ce7e9593652f9f095b1801454fd061caf69034;hb=f10dda3b82dd493eada52bcc52b790a1cc1094e6;hp=117382ed80052d14620a744f269b827a3cfd9a27;hpb=5f1be48b264e4d556f688062cc6f4a1e03f9f455;p=elogind.git diff --git a/src/shared/strv.c b/src/shared/strv.c index 117382ed8..a5ce7e959 100644 --- a/src/shared/strv.c +++ b/src/shared/strv.c @@ -64,11 +64,7 @@ void strv_free(char **l) { free(l); } -void strv_freep(char ***l) { - strv_free(*l); -} - -char **strv_copy(char **l) { +char **strv_copy(char * const *l) { char **r, **k; k = r = new(char*, strv_length(l) + 1); @@ -88,7 +84,7 @@ char **strv_copy(char **l) { return r; } -unsigned strv_length(char **l) { +unsigned strv_length(char * const *l) { unsigned n = 0; if (!l) @@ -391,32 +387,43 @@ fail: return NULL; } -int strv_extend(char ***l, const char *value) { +int strv_push(char ***l, char *value) { char **c; - char *v; unsigned n; if (!value) return 0; - v = strdup(value); - if (!v) - return -ENOMEM; - n = strv_length(*l); c = realloc(*l, sizeof(char*) * (n + 2)); - if (!c) { - free(v); + if (!c) return -ENOMEM; - } - c[n] = v; + c[n] = value; c[n+1] = NULL; *l = c; return 0; } +int strv_extend(char ***l, const char *value) { + char *v; + int r; + + if (!value) + return 0; + + v = strdup(value); + if (!v) + return -ENOMEM; + + r = strv_push(l, v); + if (r < 0) + free(v); + + return r; +} + char **strv_uniq(char **l) { char **i;