7 #include "line_stream.h"
9 #include "lt/lt_adapters.h"
10 #include "system/nth_alloc.h"
11 #include "system/log.h"
21 LineStream *create_line_stream(const char *filename,
33 LineStream *line_stream = PUSH_LT(
35 nth_alloc(sizeof(LineStream)),
37 if (line_stream == NULL) {
42 line_stream->stream = PUSH_LT(
44 fopen(filename, mode),
46 if (line_stream->stream == NULL) {
47 log_fail("Could not open file '%s': %s\n", filename, strerror(errno));
51 line_stream->buffer = PUSH_LT(
53 nth_alloc(sizeof(char) * capacity),
55 if (line_stream->buffer == NULL) {
59 line_stream->capacity = capacity;
64 void destroy_line_stream(LineStream *line_stream)
68 RETURN_LT0(line_stream->lt);
71 const char *line_stream_next(LineStream *line_stream)
74 return fgets(line_stream->buffer,
75 (int) line_stream->capacity,