comparison src/dmgrowbuf.h @ 1747:5e928618fdc8

Change DMGrowBuf API somewhat and implement more copy operations.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 11 Jun 2018 13:57:07 +0300
parents 7eb00206b36d
children 3d4bb20f6739
comparison
equal deleted inserted replaced
1746:dd57dd9430cb 1747:5e928618fdc8
26 size, // Actual allocated size 26 size, // Actual allocated size
27 len, // Size requested 27 len, // Size requested
28 mingrow; // Minimum amount of bytes the allocation size grows by 28 mingrow; // Minimum amount of bytes the allocation size grows by
29 29
30 BOOL 30 BOOL
31 allocated, // TRUE if this structure itself has been allocated and can be freed, FALSE if static
32 backwards, // TRUE if the buffer grows backwards (e.g. "offs" moves backwards) 31 backwards, // TRUE if the buffer grows backwards (e.g. "offs" moves backwards)
33 literal, // TRUE if dmGrowBufPut*() functions stores data "literally" in backwards mode 32 literal, // TRUE if dmGrowBufPut*() functions stores data "literally" in backwards mode
34 is_const; // TRUE will cause any reallocs etc. modifications to fail 33 is_const; // TRUE will cause any reallocs etc. modifications to fail
35 } DMGrowBuf; 34 } DMGrowBuf;
36 35
37 36
38 int dmGrowBufInit(DMGrowBuf *buf); 37 int dmGrowBufInit(DMGrowBuf *buf);
39 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow); 38 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow);
40 int dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow);
41 void dmGrowBufFree(DMGrowBuf *buf); 39 void dmGrowBufFree(DMGrowBuf *buf);
42 40
41 DMGrowBuf * dmGrowBufCopy(DMGrowBuf *dst, const DMGrowBuf *src, const size_t enlarge);
42 DMGrowBuf * dmGrowBufCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t enlarge);
43 DMGrowBuf * dmGrowBufConstCopy(DMGrowBuf *dst, const DMGrowBuf *src); 43 DMGrowBuf * dmGrowBufConstCopy(DMGrowBuf *dst, const DMGrowBuf *src);
44 DMGrowBuf * dmGrowBufCreateFrom(DMGrowBuf *buf, Uint8 *data, size_t len); 44 DMGrowBuf * dmGrowBufConstCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs);
45 static inline DMGrowBuf * dmGrowBufCreateFromOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs) 45 DMGrowBuf * dmGrowBufConstCreateFrom(DMGrowBuf *buf, Uint8 *data, size_t len);
46 {
47 return dmGrowBufCreateFrom(dst, src->data + offs, src->len - offs);
48 }
49 46
50 47
51 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount); 48 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount);
52 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize); 49 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize);
53 50