summaryrefslogtreecommitdiff
path: root/core/state.c
diff options
context:
space:
mode:
authorChloe M. <chloe@aptel.org>2026-08-23 04:49:51 +0000
committerChloe M. <chloe@aptel.org>2026-08-23 04:49:51 +0000
commit78b925a4d86b57e58e6322b7cad7bc47098618fd (patch)
treee66da7a598bb4be1ca869f72600112dda34a4067 /core/state.c
initial commit
There is some work to be done on top of this such as creating a way to manage memory to be freed later without needing to manually manage every pointer. Signed-off-by: Chloe M. <chloe@aptel.org>
Diffstat (limited to 'core/state.c')
-rw-r--r--core/state.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/core/state.c b/core/state.c
new file mode 100644
index 0000000..ce1c286
--- /dev/null
+++ b/core/state.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#include <stdio.h>
+#include "defconf/state.h"
+
+int
+defconf_state_init(const char *in_path, struct defconf_state *state)
+{
+ if (in_path == NULL || state == NULL) {
+ return -1;
+ }
+
+ state->in_fp = fopen(in_path, "r");
+ if (state->in_fp == NULL) {
+ perror("fopen");
+ return -1;
+ }
+
+ state->lex_cache = '\0';
+ return 0;
+}
+
+void
+defconf_state_destroy(struct defconf_state *state)
+{
+ if (state == NULL) {
+ return;
+ }
+
+ fclose(state->in_fp);
+ state->in_fp = NULL;
+}