comparison 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
comparison
equal deleted inserted replaced
1453:73a4158b2e55 1454:fff3b58d031c
1 /*
2 * DMLib
3 * -- Growable buffer implementation
4 * Programmed and designed by Matti 'ccr' Hamalainen
5 * (C) Copyright 2018 Tecnic Software productions (TNSP)
6 */
7 #ifndef DMGROWBUF_H
8 #define DMGROWBUF_H
9
10 #include "dmlib.h"
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 typedef struct
17 {
18 Uint8 *data;
19 size_t len, size, mingrow;
20 BOOL allocated;
21 } DMGrowBuf;
22
23
24 int dmGrowBufInit(DMGrowBuf *buf, const size_t initial, const size_t mingrow);
25 int dmGrowBufAlloc(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow);
26 void dmGrowBufFree(DMGrowBuf *buf);
27 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount);
28 int dmGrowBufResize(DMGrowBuf *buf);
29
30 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value);
31 BOOL dmGrowBufPutStrU8(DMGrowBuf *buf, const void *str, const size_t len);
32
33 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val);
34 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val);
35 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val);
36 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val);
37
38
39 #ifdef __cplusplus
40 }
41 #endif
42
43 #endif // DMGROWBUF_H