aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-27 12:05:39 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-27 12:05:39 +0530
commit94472267467be35d94c3509f034bd0826866cf05 (patch)
tree311f3b213f5302940bc102200bea85a0d3b437c1 /src
parent955face03fc66f20fd03c94a3cb00fbe025ed8dc (diff)
config: implement config_fetch_and_parse()
Diffstat (limited to 'src')
-rw-r--r--src/config.c20
1 files changed, 20 insertions, 0 deletions
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;
+}