X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbasic%2Fstrv.c;h=3a021003fae8b2e22c4e25a0a94411d8b819156b;hp=825fdcbdfe10474c9f2036c88b3da8ec6e7fdb72;hb=6766baac570c65a49f0eed23f181af1cab52b37f;hpb=166f4e4fb53a82900ff9ae080e0ff37d35d4dacd diff --git a/src/basic/strv.c b/src/basic/strv.c index 825fdcbdf..3a021003f 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -20,12 +18,16 @@ ***/ #include +#include #include +#include #include #include #include "alloc-util.h" #include "escape.h" +#include "extract-word.h" +//#include "fileio.h" #include "string-util.h" #include "strv.h" #include "util.h" @@ -200,6 +202,7 @@ char **strv_new(const char *x, ...) { return r; } +#if 0 /// UNNEEDED by elogind int strv_extend_strv(char ***a, char **b, bool filter_duplicates) { char **s, **t; size_t p, q, i = 0, j; @@ -244,7 +247,6 @@ rollback: return -ENOMEM; } -#if 0 /// UNNEEDED by elogind int strv_extend_strv_concat(char ***a, char **b, const char *suffix) { int r; char **s; @@ -373,7 +375,7 @@ char *strv_join(char **l, const char *separator) { n = 0; STRV_FOREACH(s, l) { - if (n != 0) + if (s != l) n += k; n += strlen(*s); } @@ -384,7 +386,7 @@ char *strv_join(char **l, const char *separator) { e = r; STRV_FOREACH(s, l) { - if (e != r) + if (s != l) e = stpcpy(e, separator); e = stpcpy(e, *s); @@ -881,4 +883,23 @@ rollback: nl[k] = NULL; return -ENOMEM; } + +int fputstrv(FILE *f, char **l, const char *separator, bool *space) { + bool b = false; + char **s; + int r; + + /* Like fputs(), but for strv, and with a less stupid argument order */ + + if (!space) + space = &b; + + STRV_FOREACH(s, l) { + r = fputs_with_space(f, *s, separator, space); + if (r < 0) + return r; + } + + return 0; +} #endif // 0