4939a74752
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
51 lines
1.0 KiB
C
51 lines
1.0 KiB
C
/**
|
||
* An interface that wraps files and strings.
|
||
* Allows stream–like reading from it.
|
||
*/
|
||
#ifndef BUFFER_H
|
||
#define BUFFER_H
|
||
|
||
/**
|
||
* An interface to a source of textual data.
|
||
*/
|
||
typedef struct Buffer Buffer;
|
||
|
||
/**
|
||
* Opens a file.
|
||
*
|
||
* @param path The path to the file.
|
||
* @returns The newly–opened buffer.
|
||
*/
|
||
Buffer* buffer_open_file(const char* path);
|
||
|
||
/**
|
||
* Opens a string.
|
||
*
|
||
* The string is not copied, and must not be free'd until the
|
||
* buffer itself has been closed.
|
||
*
|
||
* @param string The contents stored in the buffer.
|
||
* @returns A newly–opened buffer that reads from the string.
|
||
*/
|
||
Buffer* buffer_open_string(const char* string);
|
||
|
||
/**
|
||
* Closes the buffer.
|
||
*
|
||
* @param buffer The buffer to close.
|
||
*/
|
||
void buffer_close(Buffer* buffer);
|
||
|
||
/**
|
||
* Reads a single character from the buffer.
|
||
*
|
||
* If there are no more characters in the buffer,
|
||
* this returns `-1`.
|
||
*
|
||
* @param buffer The buffer to read from.
|
||
* @returns the next character in the buffer.
|
||
*/
|
||
char buffer_read(Buffer* buffer);
|
||
|
||
#endif
|