blob: c55a5bef72f443027977602ddcfa5699f13ba9b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*
* 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)
{
int error;
if (in_path == NULL || state == NULL) {
return -1;
}
state->in_fp = fopen(in_path, "r");
if (state->in_fp == NULL) {
perror("fopen");
return -1;
}
if ((error = ptrbox_init(&state->ptrbox)) < 0) {
fclose(state->in_fp);
printf("fatal: failed to create pointer box\n");
return error;
}
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;
ptrbox_destroy(&state->ptrbox);
}
|