forked from flash/temporary-satori-hole
40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
#ifndef H_SATORI_BUFFER
|
|
#define H_SATORI_BUFFER
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
|
|
#define SAT_BUFFER_PIECE_SIZE (1024)
|
|
#define SAT_BUFFER_PIECE_MAX (SAT_BUFFER_PIECE_SIZE - 1)
|
|
|
|
typedef struct _sat_buffer_piece {
|
|
struct _sat_buffer_piece *next;
|
|
char data[SAT_BUFFER_PIECE_SIZE];
|
|
} sat_buffer_piece, *sat_buffer_piece_ptr;
|
|
|
|
typedef struct _sat_buffer {
|
|
size_t available;
|
|
sat_buffer_piece_ptr start;
|
|
|
|
size_t rPos;
|
|
sat_buffer_piece_ptr rCurrent;
|
|
|
|
size_t wPos;
|
|
sat_buffer_piece_ptr wCurrent;
|
|
} sat_buffer, *sat_buffer_ptr;
|
|
|
|
sat_buffer_ptr sat_buffer_alloc(void);
|
|
void sat_buffer_free(sat_buffer_ptr buffer);
|
|
|
|
bool sat_buffer_pending(sat_buffer_ptr buffer);
|
|
size_t sat_buffer_available(sat_buffer_ptr buffer);
|
|
void sat_buffer_tidy(sat_buffer_ptr buffer);
|
|
|
|
int sat_buffer_write(sat_buffer_ptr buffer, char *source, size_t count);
|
|
void sat_buffer_putc(sat_buffer_ptr buffer, char value);
|
|
|
|
int sat_buffer_read(sat_buffer_ptr buffer, char *target, size_t length);
|
|
char sat_buffer_getc(sat_buffer_ptr buffer);
|
|
|
|
#endif // H_SATORI_BUFFER
|