51 size_t needed = length + 1;
53 br->
buf =
static_cast<char *
>(realloc(br->
buf, needed));
66 FILE *file = fopen(filepath,
"rb");
68 LOG(failureLevel, failureMessage, filepath, strerror(errno));
75 fseek(file, 0L, SEEK_END);
77 fseek(file, 0, SEEK_SET);
98 memcpy(br->
buf, data, length);
128 size_t cp =
MIN(length, (
size_t)(newline - curr + 1));
130 strncpy(buffer, curr, cp);
133 strncpy(buffer, curr, length);
void bufferreader_destroy(BufferReader *br)
Destroy a BufferReader.
Implements a buffer reader.
BufferReader * bufferreader_create()
Create a new BufferReader.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
char * current_line
Pointer to the next line of the buffer.
char * bufferreader_data(BufferReader *br)
Get the whole buffer, independently of the calls to bufferreader_next_line().
char * bufferreader_get_line(BufferReader *br, char *buffer, size_t length)
Copy the next line in the buffer, keeping the newline.
size_t bufferreader_current_line(BufferReader *br)
Return the index of the last line returned by bufferreader_next_line().
static void bufferreader_init_for_length(BufferReader *br, size_t length)
Ensure the buffer can hold the specified length, initialize all fields.
size_t buffer_length
Used size of buf.
size_t line_index
Current line index.
size_t allocated_size
Allocated size of buf.
Global type definitions and header inclusions.
size_t bufferreader_data_length(BufferReader *br)
Return the length of the buffer data.
BufferReader * bufferreader_init_from_file(BufferReader *br, const char *filepath, const char *failureMessage, LogLevel failureLevel)
Initialize or create a BufferReader from a file path.
BufferReader * bufferreader_init_from_memory(BufferReader *br, const char *data, size_t length)
Initialize or create a BufferReader from a memory block.
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
Compatibility implementations of useful nonstandard types and functions.
LogLevel
Log levels for the LOG() function.
int mtar_read_data(mtar_t *tar, void *ptr, unsigned size)
char * bufferreader_next_line(BufferReader *br)
Return the next line in the buffer, as separated by a newline.
void bufferreader_init_from_tar_file(BufferReader *br, mtar_t *tar, mtar_header_t *h)
Initialize a BufferReader from a tar file entry.