35 lines
595 B
C
35 lines
595 B
C
|
|
#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;
|
||
|
|
}
|