Files
quip/core/state.c
Ian Moffett 0fa8ad12ca initial commit
Signed-off-by: Ian Moffett <ian@mirocom.org>
2026-03-21 06:15:27 -04:00

48 lines
835 B
C

/*
* Copyright (c) 2026, Mirocom Laboratories
* Provided under the BSD-3 clause
*
* Abstract:
* This file implements the quip state machine
* Author:
* Ian M. Moffett <ian@mirocom.org>
*/
#include <stddef.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "common/state.h"
int
quip_state_init(const char *build_file, struct quip_state *state)
{
if (build_file == NULL || state == NULL) {
errno = -EINVAL;
return -1;
}
memset(state, 0, sizeof(*state));
state->line_num = 1;
state->in_fd = open(build_file, O_RDONLY);
if (state->in_fd < 0) {
return -1;
}
return 0;
}
void
quip_state_destroy(struct quip_state *state)
{
if (state == NULL) {
return;
}
close(state->in_fd);
state->in_fd = -1;
}