26#ifndef FILE_STREAM_BUFFER_SIZE
28# define FILE_STREAM_BUFFER_SIZE 4096
37 int descriptor = open(file_name, flags);
41 log_error(
"Unable to open \"%s\": %s", file_name, strerror(errno));
42 return (
ifstream_t){.descriptor = -1, .opened =
false};
56 ifstream_t file = {.descriptor = descriptor, .opened =
false};
61 log_error(
"malloc failed: %s", strerror(errno));
#define FILE_STREAM_BUFFER_SIZE
ifstream_t file_from_descriptor(int descriptor)
Construct a file input stream from an externally managed file descriptor.
ifstream_t file_open(const char *file_name, int flags)
Construct a file input stream : Open the file and allocate the buffer.
Simplistic logging utilities.
#define log_error(...)
Report a condition causing the current operation to abort.
bool file_accumulate_infinite(ifstream_t *file, size_t count)
If possible, accumulate count bytes before returning.
bool file_accumulate(ifstream_t *file, size_t count)
If possible, accumulate count bytes before returning.
Dynamic string implementation.
size_t capacity
Maximum number of elements that can be stored.
bool opened
Is this file still open ?
int descriptor
Underlying file.
istream_t stream
Inherit from input stream.
bool(* accumulate)(struct input_stream *self, size_t count)
Ask if the stream can provide at least count bytes to read.
queue_t buffer
Circular buffer of bytes.