initctl: recactor, share fgetval() with rest of Finit

Note: this highly useful function should probably migrate to libite.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-11-20 10:43:30 +01:00
parent d3a0631390
commit 006dd12b09
2 changed files with 41 additions and 26 deletions
-26
View File
@@ -1363,32 +1363,6 @@ static int cmd_parse(int argc, char *argv[], struct cmd *command)
return command[0].cb(NULL); /* default cmd */
}
static char *fgetval(char *line, const char *key, char *sep)
{
char *ptr, *str, *copy;
size_t len;
str = copy = strdup(line);
if (!copy)
return NULL;
ptr = strsep(&str, sep);
if (ptr && strcmp(ptr, key)) {
fail:
free(copy);
return NULL;
}
ptr = strsep(&str, sep);
if (!ptr)
goto fail;
len = strlen(ptr) + 1;
memmove(copy, ptr, len);
return realloc(copy, len);
}
static void cleanup(void)
{
if (finit_conf)