aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/config.h1
-rw-r--r--src/config.c20
2 files changed, 21 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h
index baf4fef..4451054 100644
--- a/include/config.h
+++ b/include/config.h
@@ -13,5 +13,6 @@ typedef struct {
} config_t;
config_t *config_parse(char *content);
+config_t *config_fetch_and_parse(char *path);
#endif
diff --git a/src/config.c b/src/config.c
index b268057..46a3ad2 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1,6 +1,7 @@
#define _GNU_SOURCE
#include <config.h>
+#include <filehandler.h>
#include <list.h>
#include <stdio.h>
#include <stdlib.h>
@@ -60,3 +61,22 @@ config_parse(char *content)
config->array_values = array_values;
return config;
}
+
+config_t *
+config_fetch_and_parse(char *path)
+{
+ FILE *f = fopen(path, "r");
+ if (f == NULL) {
+ printf("Could not open %s\n", path);
+ return NULL;
+ }
+
+ size_t s = fsize(f);
+ char *content = fcontent(f, s);
+ fclose(f);
+
+ config_t *config = config_parse(content);
+ free(content);
+
+ return config;
+}