Mercurial > hg > dmlib
diff src/dmgrowbuf.h @ 1454:fff3b58d031c
Add a growable buffer implementation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 10 May 2018 18:33:57 +0300 |
parents | |
children | a957b318fbe2 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dmgrowbuf.h Thu May 10 18:33:57 2018 +0300 @@ -0,0 +1,43 @@ +/* + * DMLib + * -- Growable buffer implementation + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2018 Tecnic Software productions (TNSP) + */ +#ifndef DMGROWBUF_H +#define DMGROWBUF_H + +#include "dmlib.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct +{ + Uint8 *data; + size_t len, size, mingrow; + BOOL allocated; +} DMGrowBuf; + + +int dmGrowBufInit(DMGrowBuf *buf, const size_t initial, const size_t mingrow); +int dmGrowBufAlloc(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow); +void dmGrowBufFree(DMGrowBuf *buf); +BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount); +int dmGrowBufResize(DMGrowBuf *buf); + +BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value); +BOOL dmGrowBufPutStrU8(DMGrowBuf *buf, const void *str, const size_t len); + +BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val); +BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val); +BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val); +BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val); + + +#ifdef __cplusplus +} +#endif + +#endif // DMGROWBUF_H