X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fstrv.c;h=b4c476eff27df9858698ad4f52e66210b6696bb7;hb=a1948c7bfeb87b54bc7715a44490c01593ee6e23;hp=67706dc381dfde9ecbd2fcd299d8a076cdb3b588;hpb=6e18964d3a365567954fe10ddcfad74babdc427c;p=elogind.git diff --git a/src/shared/strv.c b/src/shared/strv.c index 67706dc38..b4c476eff 100644 --- a/src/shared/strv.c +++ b/src/shared/strv.c @@ -378,6 +378,30 @@ int strv_push(char ***l, char *value) { return 0; } +int strv_push_prepend(char ***l, char *value) { + char **c; + unsigned n, i; + + if (!value) + return 0; + + n = strv_length(*l); + c = new(char*, n + 2); + if (!c) + return -ENOMEM; + + for (i = 0; i < n; i++) + c[i+1] = (*l)[i]; + + c[0] = value; + c[n+1] = NULL; + + free(*l); + *l = c; + + return 0; +} + int strv_consume(char ***l, char *value) { int r; @@ -388,6 +412,16 @@ int strv_consume(char ***l, char *value) { return r; } +int strv_consume_prepend(char ***l, char *value) { + int r; + + r = strv_push_prepend(l, value); + if (r < 0) + free(value); + + return r; +} + int strv_extend(char ***l, const char *value) { char *v; @@ -527,3 +561,18 @@ void strv_print(char **l) { STRV_FOREACH(s, l) puts(*s); } + +int strv_extendf(char ***l, const char *format, ...) { + va_list ap; + char *x; + int r; + + va_start(ap, format); + r = vasprintf(&x, format, ap); + va_end(ap); + + if (r < 0) + return -ENOMEM; + + return strv_consume(l, x); +}