Add some buffer management routines

This commit is contained in:
Sasha Koshka
2023-11-06 02:53:19 -05:00
parent e042d5b45e
commit e6ca2a97fc
4 changed files with 124 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
#ifndef _XmdBuffer_h
#define _XmdBuffer_h
#include <stddef.h>
/* Buffer is a struct that keeps track of a variable length array of data. It
is like a piggy bank, you can add stuff to it and then break it to get access
to all the things you put in. It is intended to be used for reading in
variable length strings and files. */
typedef struct _XmdBuffer XmdBuffer;
/* XmdBufferNew creates a new buffer with the specified element size. */
XmdBuffer *XmdBufferNew (size_t element);
/* XmdBufferPush adds a new element to the buffer. */
void XmdBufferPush (XmdBuffer *buffer, void *element);
/* XmdBufferBreak frees the buffer without freeing its data. Its data is
returned and must be freed manually at some point. */
void *XmdBufferBreak (XmdBuffer *buffer);
/* XmdBufferFree frees the buffer and any data associated with it. */
void XmdBufferFree (XmdBuffer *buffer);
#endif