1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

conf-parse: add generic parser for strv

This commit is contained in:
Lennart Poettering 2009-11-19 02:51:44 +01:00
parent 07232470c8
commit 57d42a5f66
2 changed files with 50 additions and 0 deletions

View File

@ -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;
}

View File

@ -29,5 +29,6 @@ int config_parse_unsigned(const char *filename, unsigned line, const char *secti
int config_parse_size(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
int config_parse_bool(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
int config_parse_string(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
int config_parse_strv(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
#endif