forked from PlaneteCasio/Casio_asm
48 lines
1.4 KiB
C
48 lines
1.4 KiB
C
#ifndef BUFFER_H
|
|
#define BUFFER_H
|
|
|
|
#include "string.h"
|
|
|
|
typedef struct buffer_t {
|
|
int size;
|
|
int allocated;
|
|
void* data;
|
|
} buffer_t;
|
|
|
|
//creates a buffer with a fixed size
|
|
int allocBuffer(buffer_t *buffer, int size);
|
|
//creates a buffer around external data, does not copy
|
|
int wrapBuffer(buffer_t *buffer, char* data, int len);
|
|
|
|
//resizes a buffer
|
|
int resizeBuffer(buffer_t *buffer, int size);
|
|
//makes sure we have enough allocated memory
|
|
int preallocBuffer(buffer_t *buffer, int size, int free);
|
|
|
|
//copy a buffer into another
|
|
int copyBuffer(buffer_t *src, int srcPos, buffer_t *desc, int destPos, int len);
|
|
//appends a buffer to the end of another one
|
|
int appendBuffer(buffer_t *buffer, buffer_t *data, int len);
|
|
|
|
//write data into a buffer
|
|
int writeDataBuffer(buffer_t *buffer, int pos, void* data, int len);
|
|
//append data at the end of a buffer
|
|
int appendDataBuffer(buffer_t *buffer, void* data, int len);
|
|
//append string at the end of a buffer
|
|
int appendStringBuffer(buffer_t *buffer, char* str);
|
|
//append byte at the end of a buffer
|
|
int appendByteBuffer(buffer_t *buffer, int data);
|
|
//make the buffer a valid string
|
|
int toStringBuffer(buffer_t *buffer);
|
|
|
|
//get byte from buffer
|
|
#define getByteBuffer(buffer, offset) (((char*)(buffer)->data)[(offset)])
|
|
|
|
//destroy a buffer
|
|
int freeBuffer(buffer_t *buffer);
|
|
|
|
//checks if a buffer is valid
|
|
int checkBuffer(buffer_t *buffer);
|
|
|
|
#endif
|