annotate src/dmgrowbuf.c @ 1536:064fc2e3ee64

Add compile-time debugging information to DMGrowBuf.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 12 May 2018 04:12:46 +0300
parents 260bf529a8f2
children 383ca5f6e78b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Growable buffer implementation
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * (C) Copyright 2018 Tecnic Software productions (TNSP)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmgrowbuf.h"
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
9 //#define DM_GROWBUF_DEBUG 1
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
10
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
11 #ifdef DM_GROWBUF_DEBUG
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
12 # define DM_DBG(...) do { fprintf(stderr, __VA_ARGS__); } while (0)
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
13 #else
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
14 # define DM_DBG(...) do { } while (0)
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
15 #endif
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
16
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
1458
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
18 int dmGrowBufInit(DMGrowBuf *buf)
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
19 {
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
20 DM_DBG("dmGrowBufInit(%p)\n", buf);
1458
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
21 if (buf == NULL)
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
22 return DMERR_NULLPTR;
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
23
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
24 memset(buf, 0, sizeof(DMGrowBuf));
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
25
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
26 return DMERR_OK;
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
27 }
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
28
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
29
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
30 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow)
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 {
1459
1155f4bc4afc More work on growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
32 int res;
1155f4bc4afc More work on growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
33
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
34 DM_DBG("dmGrowBufAlloc(%p, %" DM_PRIu_SIZE_T ", %" DM_PRIu_SIZE_T ")\n", buf, initial, mingrow);
1459
1155f4bc4afc More work on growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
35 if ((res = dmGrowBufInit(buf)) != DMERR_OK)
1155f4bc4afc More work on growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
36 return res;
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 buf->len = 0;
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
39 buf->offs = 0;
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 buf->size = initial;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 buf->mingrow = mingrow;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 buf->allocated = FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
1509
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
44 // Allocate the data
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
45 if ((buf->adata = buf->data = dmMalloc0(initial)) == NULL)
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 return DMERR_MALLOC;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 return DMERR_OK;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
1458
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
52 int dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow)
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 int res;
1458
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
55 if (pbuf == NULL)
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
56 return DMERR_NULLPTR;
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
58 DM_DBG("dmGrowBufNew(%p, %" DM_PRIu_SIZE_T ", %" DM_PRIu_SIZE_T ")\n", pbuf, initial, mingrow);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 if ((*pbuf = dmMalloc0(sizeof(DMGrowBuf))) == NULL)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 return DMERR_MALLOC;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
1458
b2dd6a72d162 Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1455
diff changeset
62 if ((res = dmGrowBufAlloc(*pbuf, initial, mingrow)) != DMERR_OK)
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
1459
1155f4bc4afc More work on growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
64 // The "allocated" flag has not yet been set
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 dmGrowBufFree(*pbuf);
1459
1155f4bc4afc More work on growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
66
1155f4bc4afc More work on growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
67 // .. thus free the allocated struct here
1155f4bc4afc More work on growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1458
diff changeset
68 dmFreeR(pbuf);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 return res;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 (*pbuf)->allocated = TRUE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 return res;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 void dmGrowBufFree(DMGrowBuf *buf)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 {
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
79 DM_DBG("dmGrowBufFree(%p)\n", buf);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 if (buf != NULL)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 {
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
82 DM_DBG(
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
83 " buf->adata = %p\n"
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
84 " buf->data = %p\n"
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
85 " buf->allocated = %s\n",
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
86 buf->adata, buf->data, buf->allocated ? "YES" : "NO");
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
87
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
88 dmFreeR(&buf->adata);
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
89 buf->data = NULL;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
90
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 if (buf->allocated)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 dmFree(buf);
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
97 void dmGrowBufPush(DMGrowBuf *buf)
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
98 {
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
99 if (buf != NULL && buf->adata != NULL)
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
100 {
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
101 DM_DBG("dmGrowBufPush(%p): size=%" DM_PRIu_SIZE_T "\n"
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
102 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n", buf, buf->size, buf->nstack, buf->offs, buf->len);
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
103
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
104 buf->stack[buf->nstack].offs = buf->offs;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
105 buf->stack[buf->nstack].len = buf->len;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
106 buf->nstack++;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
107
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
108 buf->offs = buf->len;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
109 buf->data = buf->adata + buf->offs;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
110 buf->len = 0;
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
111
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
112 DM_DBG(
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
113 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n", buf->nstack, buf->offs, buf->len);
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
114 }
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
115 else
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
116 DM_DBG("dmGrowBufPush(%p)\n", buf);
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
117 }
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
118
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
119
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
120 void dmGrowBufPop(DMGrowBuf *buf)
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
121 {
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
122 if (buf != NULL && buf->adata != NULL && buf->nstack > 0)
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
123 {
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
124 DM_DBG("dmGrowBufPop(%p): size=%" DM_PRIu_SIZE_T "\n"
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
125 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n", buf, buf->size, buf->nstack, buf->offs, buf->len);
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
126
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
127 buf->nstack--;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
128 buf->offs = buf->stack[buf->nstack].offs;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
129 buf->len += buf->stack[buf->nstack].len;
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
130
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
131 buf->data = buf->adata + buf->offs;
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
132
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
133 DM_DBG(
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
134 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n", buf->nstack, buf->offs, buf->len);
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
135
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
136 }
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
137 else
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
138 DM_DBG("dmGrowBufPop(%p)\n", buf);
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
139 }
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
140
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
141
1530
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
142 static BOOL dmGrowBufRealloc(DMGrowBuf *buf, const size_t nsize, const BOOL clear)
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
143 {
1536
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
144 DM_DBG("dmGrowBufRealloc(%p): size=%" DM_PRIu_SIZE_T "\n"
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
145 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n",
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
146 buf, buf->size, buf->nstack, buf->offs, buf->len);
064fc2e3ee64 Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1531
diff changeset
147
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
148 if ((buf->adata = dmRealloc(buf->adata, nsize)) == NULL)
1530
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
149 return FALSE;
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
150
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
151 if (clear)
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
152 memset(buf->adata + buf->size, 0, nsize - buf->size);
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
153
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
154 buf->data = buf->adata + buf->offs;
1530
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
155 buf->size = nsize;
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
156
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
157 return TRUE;
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
158 }
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
159
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
160
1509
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
161 //
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
162 // Grow the buffer by "amount" bytes, but at least by buf->mingrow,
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
163 // if there is not enough space for at least that amount compared to
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
164 // current buffer "len".
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
165 //
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 {
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
168 if (buf->adata == NULL || buf->offs + buf->len + amount >= buf->size)
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 {
1530
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
170 size_t grow = (amount > buf->mingrow) ? amount : buf->mingrow;
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
171 if (!dmGrowBufRealloc(buf, buf->offs + buf->len + grow, TRUE))
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 return FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 return TRUE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
1509
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
179 //
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
180 // Grow the buffer if "nsize" is larger than the current buffer size.
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
181 // Buffer is enlarged to nsize + mingrow.
15afe578f0ae Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents: 1508
diff changeset
182 //
1455
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
183 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize)
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
184 {
1531
260bf529a8f2 Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1530
diff changeset
185 if (buf->adata == NULL || buf->offs + nsize > buf->size)
1455
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
186 {
1530
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
187 if (!dmGrowBufRealloc(buf, buf->offs + nsize + buf->mingrow, TRUE))
1455
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
188 return FALSE;
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
189 }
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
190
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
191 return TRUE;
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
192 }
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
193
a957b318fbe2 Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1454
diff changeset
194
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 int dmGrowBufResize(DMGrowBuf *buf)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 if (buf == NULL)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 return DMERR_NULLPTR;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 buf->size = buf->len;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 if (buf->len == 0)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 return DMERR_OK;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
1530
94eb6a8a7d56 Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents: 1509
diff changeset
204 if (!dmGrowBufRealloc(buf, buf->size, FALSE))
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 return DMERR_MALLOC;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 return DMERR_OK;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 if (!dmGrowBufGrow(buf, sizeof(Uint8)))
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 return FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 buf->data[buf->len++] = value;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 return TRUE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
1477
e8fe529f4341 Rename one of the growbuf functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1459
diff changeset
222 BOOL dmGrowBufPut(DMGrowBuf *buf, const void *str, const size_t len)
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 if (str == NULL)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 return FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
1484
a0166c4050be Fix dmGrowBufPut() to not include extra byte.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
227 if (!dmGrowBufGrow(buf, len))
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 return FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229
1484
a0166c4050be Fix dmGrowBufPut() to not include extra byte.
Matti Hamalainen <ccr@tnsp.org>
parents: 1477
diff changeset
230 memcpy(buf->data + buf->len, str, len);
1454
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 buf->len += len;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 return TRUE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 if (!dmGrowBufGrow(buf, sizeof(Uint16)))
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 return FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 buf->data[buf->len++] = (val >> 8) & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 buf->data[buf->len++] = val & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 return TRUE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 if (!dmGrowBufGrow(buf, sizeof(Uint16)))
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 return FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 buf->data[buf->len++] = val & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 buf->data[buf->len++] = (val >> 8) & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 return TRUE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 if (!dmGrowBufGrow(buf, sizeof(Uint32)))
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 return FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 buf->data[buf->len++] = (val >> 24) & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 buf->data[buf->len++] = (val >> 16) & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 buf->data[buf->len++] = (val >> 8) & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 buf->data[buf->len++] = val & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 return TRUE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 }
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val)
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 {
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 if (!dmGrowBufGrow(buf, sizeof(Uint32)))
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 return FALSE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 buf->data[buf->len++] = val & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 buf->data[buf->len++] = (val >> 8) & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 buf->data[buf->len++] = (val >> 16) & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 buf->data[buf->len++] = (val >> 24) & 0xff;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 return TRUE;
fff3b58d031c Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 }