summaryrefslogtreecommitdiff
path: root/conf-parser.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-11-19 02:51:44 +0100
committerLennart Poettering <lennart@poettering.net>2009-11-19 02:51:44 +0100
commit57d42a5f661084af3d460a80112fab5dffd91591 (patch)
tree7324cddd72261764b06d7bc02c0d44ed73fc3dd0 /conf-parser.c
parent07232470c869976ae2d7a36799bc6b0126d7e820 (diff)
conf-parse: add generic parser for strv
Diffstat (limited to 'conf-parser.c')
-rw-r--r--conf-parser.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/conf-parser.c b/conf-parser.c
index c45acd7702..e50597491b 100644
--- a/conf-parser.c
+++ b/conf-parser.c
@@ -9,6 +9,7 @@
#include "conf-parser.h"
#include "util.h"
#include "macro.h"
+#include "strv.h"
#define WHITESPACE " \t\n"
#define COMMENTS "#;\n"
@@ -319,3 +320,51 @@ int config_parse_string(
return 0;
}
+
+
+int config_parse_strv(
+ const char *filename,
+ unsigned line,
+ const char *section,
+ const char *lvalue,
+ const char *rvalue,
+ void *data,
+ void *userdata) {
+
+ char*** sv = data;
+ char **n;
+ char *w;
+ unsigned k;
+ size_t l;
+ char *state;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ k = strv_length(*sv);
+ FOREACH_WORD(w, &l, rvalue, state)
+ k++;
+
+ if (!(n = new(char*, k+1)))
+ return -ENOMEM;
+
+ for (k = 0; (*sv)[k]; k++)
+ n[k] = (*sv)[k];
+ FOREACH_WORD(w, &l, rvalue, state)
+ if (!(n[k++] = strndup(w, l)))
+ goto fail;
+
+ n[k] = NULL;
+ free(*sv);
+ *sv = n;
+
+ return 0;
+
+fail:
+ for (; k > 0; k--)
+ free(n[k-1]);
+
+ return -ENOMEM;
+}