summaryrefslogtreecommitdiff
path: root/core/state.c
diff options
context:
space:
mode:
authorIan Moffett <ian@mirocom.org>2026-05-23 01:28:05 -0400
committerIan Moffett <ian@mirocom.org>2026-05-23 01:28:05 -0400
commitc5f8f95059504748f07e0d3ca9d978669622428c (patch)
treecc64c48bb1e93c2df466f4fb007912628c319c91 /core/state.c
initial commit
Signed-off-by: Ian Moffett <ian@mirocom.org>
Diffstat (limited to 'core/state.c')
-rw-r--r--core/state.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/core/state.c b/core/state.c
new file mode 100644
index 0000000..7d80acd
--- /dev/null
+++ b/core/state.c
@@ -0,0 +1,34 @@
+#include <stdint.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include "cescal/state.h"
+
+int
+state_init(struct cescal_state *state, const char *pathname)
+{
+ if (state == NULL || pathname == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ state->in_fd = open(pathname, O_RDONLY);
+ if (state->in_fd < 0) {
+ return -1;
+ }
+
+ if (readbuf_init(&state->rb) < 0) {
+ close(state->in_fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+void
+state_close(struct cescal_state *state)
+{
+ close(state->in_fd);
+ state->in_fd = -1;
+}