aboutsummaryrefslogtreecommitdiff
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
parent955face03fc66f20fd03c94a3cb00fbe025ed8dc (diff)
config: implement config_fetch_and_parse()
-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;
+}