Mercurial > hg > dmlib
annotate src/dmgrowbuf.c @ 1687:383ca5f6e78b
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 01 Jun 2018 02:21:24 +0300 |
parents | 064fc2e3ee64 |
children | 9611ecd2c4fb |
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); |
1687 | 21 |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
22 if (buf == NULL) |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
23 return DMERR_NULLPTR; |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
24 |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
25 memset(buf, 0, sizeof(DMGrowBuf)); |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
26 |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
27 return DMERR_OK; |
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 |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
31 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
|
32 { |
1459 | 33 int res; |
34 | |
1687 | 35 DM_DBG("dmGrowBufAlloc(%p, %" DM_PRIu_SIZE_T ", %" DM_PRIu_SIZE_T ")\n", |
36 buf, initial, mingrow); | |
37 | |
1459 | 38 if ((res = dmGrowBufInit(buf)) != DMERR_OK) |
39 return res; | |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 buf->len = 0; |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
42 buf->offs = 0; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 buf->size = initial; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 buf->mingrow = mingrow; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 buf->allocated = FALSE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
1509
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
47 // Allocate the data |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
48 if ((buf->adata = buf->data = dmMalloc0(initial)) == NULL) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 return DMERR_MALLOC; |
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 return DMERR_OK; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 } |
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 |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
55 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
|
56 { |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 int res; |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
58 if (pbuf == NULL) |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
59 return DMERR_NULLPTR; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
1687 | 61 DM_DBG("dmGrowBufNew(%p, %" DM_PRIu_SIZE_T ", %" DM_PRIu_SIZE_T ")\n", |
62 pbuf, initial, mingrow); | |
63 | |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 if ((*pbuf = dmMalloc0(sizeof(DMGrowBuf))) == NULL) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 return DMERR_MALLOC; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
67 if ((res = dmGrowBufAlloc(*pbuf, initial, mingrow)) != DMERR_OK) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 { |
1459 | 69 // The "allocated" flag has not yet been set |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 dmGrowBufFree(*pbuf); |
1459 | 71 |
72 // .. thus free the allocated struct here | |
73 dmFreeR(pbuf); | |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 return res; |
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 (*pbuf)->allocated = TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 return res; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 void dmGrowBufFree(DMGrowBuf *buf) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 { |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
84 DM_DBG("dmGrowBufFree(%p)\n", buf); |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 if (buf != NULL) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 { |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
87 DM_DBG( |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
88 " buf->adata = %p\n" |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
89 " buf->data = %p\n" |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
90 " buf->allocated = %s\n", |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
91 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
|
92 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
93 dmFreeR(&buf->adata); |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
94 buf->data = NULL; |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
95 |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 if (buf->allocated) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 dmFree(buf); |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
102 void dmGrowBufPush(DMGrowBuf *buf) |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
103 { |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
104 if (buf != NULL && buf->adata != NULL) |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
105 { |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
106 DM_DBG("dmGrowBufPush(%p): size=%" DM_PRIu_SIZE_T "\n" |
1687 | 107 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n", |
108 buf, buf->size, buf->nstack, buf->offs, buf->len); | |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
109 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
110 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
|
111 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
|
112 buf->nstack++; |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
113 |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
114 buf->offs = buf->len; |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
115 buf->data = buf->adata + buf->offs; |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
116 buf->len = 0; |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
117 |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
118 DM_DBG( |
1687 | 119 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n", |
120 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
|
121 } |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
122 else |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
123 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
|
124 } |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
125 |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
126 |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
127 void dmGrowBufPop(DMGrowBuf *buf) |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
128 { |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
129 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
|
130 { |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
131 DM_DBG("dmGrowBufPop(%p): size=%" DM_PRIu_SIZE_T "\n" |
1687 | 132 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n", |
133 buf, buf->size, buf->nstack, buf->offs, buf->len); | |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
134 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
135 buf->nstack--; |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
136 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
|
137 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
|
138 |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
139 buf->data = buf->adata + buf->offs; |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
140 |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
141 DM_DBG( |
1687 | 142 " nstack=%d [offs=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T "]\n", |
143 buf->nstack, buf->offs, buf->len); | |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
144 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
145 } |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
146 else |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
147 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
|
148 } |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
149 |
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
150 |
1530
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
151 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
|
152 { |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
153 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
|
154 " 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
|
155 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
|
156 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
157 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
|
158 return FALSE; |
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 if (clear) |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
161 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
|
162 |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
163 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
|
164 buf->size = nsize; |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
165 |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
166 return TRUE; |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
167 } |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
168 |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
169 |
1509
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
170 // |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
171 // 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
|
172 // 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
|
173 // current buffer "len". |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
174 // |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 { |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
177 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
|
178 { |
1530
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
179 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
|
180 if (!dmGrowBufRealloc(buf, buf->offs + buf->len + grow, TRUE)) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 return FALSE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
1509
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
188 // |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
189 // 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
|
190 // Buffer is enlarged to nsize + mingrow. |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
191 // |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
192 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize) |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
193 { |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
194 if (buf->adata == NULL || buf->offs + nsize > buf->size) |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
195 { |
1530
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
196 if (!dmGrowBufRealloc(buf, buf->offs + nsize + buf->mingrow, TRUE)) |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
197 return FALSE; |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
198 } |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
199 |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
200 return TRUE; |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
201 } |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
202 |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
203 |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 int dmGrowBufResize(DMGrowBuf *buf) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 { |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 if (buf == NULL) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 return DMERR_NULLPTR; |
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 buf->size = buf->len; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 if (buf->len == 0) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 return DMERR_OK; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 |
1530
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
213 if (!dmGrowBufRealloc(buf, buf->size, FALSE)) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 return DMERR_MALLOC; |
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 return DMERR_OK; |
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 |
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 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 { |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 if (!dmGrowBufGrow(buf, sizeof(Uint8))) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 return FALSE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 buf->data[buf->len++] = value; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 |
1477
e8fe529f4341
Rename one of the growbuf functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1459
diff
changeset
|
231 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
|
232 { |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 if (str == NULL) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 return FALSE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 |
1484
a0166c4050be
Fix dmGrowBufPut() to not include extra byte.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
236 if (!dmGrowBufGrow(buf, len)) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 return FALSE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 |
1484
a0166c4050be
Fix dmGrowBufPut() to not include extra byte.
Matti Hamalainen <ccr@tnsp.org>
parents:
1477
diff
changeset
|
239 memcpy(buf->data + buf->len, str, len); |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 buf->len += len; |
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 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 } |
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 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val) |
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 if (!dmGrowBufGrow(buf, sizeof(Uint16))) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 return FALSE; |
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 buf->data[buf->len++] = (val >> 8) & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 buf->data[buf->len++] = val & 0xff; |
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 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 } |
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 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val) |
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 if (!dmGrowBufGrow(buf, sizeof(Uint16))) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 return FALSE; |
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 buf->data[buf->len++] = val & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 buf->data[buf->len++] = (val >> 8) & 0xff; |
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 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 { |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 if (!dmGrowBufGrow(buf, sizeof(Uint32))) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 return FALSE; |
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 buf->data[buf->len++] = (val >> 24) & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 buf->data[buf->len++] = (val >> 16) & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 buf->data[buf->len++] = (val >> 8) & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 buf->data[buf->len++] = val & 0xff; |
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 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 { |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 if (!dmGrowBufGrow(buf, sizeof(Uint32))) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 return FALSE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 buf->data[buf->len++] = val & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 buf->data[buf->len++] = (val >> 8) & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 buf->data[buf->len++] = (val >> 16) & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 buf->data[buf->len++] = (val >> 24) & 0xff; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 } |