Mercurial > hg > dmlib
comparison src/dmgrowbuf.c @ 2298:b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
dmGrowBufConstCopyOffsSize().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 04 Jul 2019 10:54:16 +0300 |
parents | 39b4e06785f5 |
children | c801995cbb13 |
comparison
equal
deleted
inserted
replaced
2297:39b4e06785f5 | 2298:b5abfff07ca9 |
---|---|
142 { | 142 { |
143 return dmGrowBufConstCreateFrom(dst, src->data + offs, src->len - offs); | 143 return dmGrowBufConstCreateFrom(dst, src->data + offs, src->len - offs); |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 DMGrowBuf * dmGrowBufConstCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len) | |
148 { | |
149 if (src->len < offs + len) | |
150 return NULL; | |
151 | |
152 return dmGrowBufConstCreateFrom(dst, src->data + offs, len); | |
153 } | |
154 | |
155 | |
147 DMGrowBuf * dmGrowBufCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t enlarge) | 156 DMGrowBuf * dmGrowBufCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t enlarge) |
148 { | 157 { |
149 DMGrowBuf tmp; | 158 DMGrowBuf tmp; |
150 return dmGrowBufCopy(dst, | 159 return dmGrowBufCopy(dst, |
151 dmGrowBufConstCreateFrom(&tmp, src->data + offs, src->len - offs), enlarge); | 160 dmGrowBufConstCreateFrom(&tmp, src->data + offs, src->len - offs), enlarge); |
161 } | |
162 | |
163 | |
164 DMGrowBuf * dmGrowBufCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len, const size_t enlarge) | |
165 { | |
166 DMGrowBuf tmp; | |
167 | |
168 if (src->len < offs + len) | |
169 return NULL; | |
170 | |
171 return dmGrowBufCopy(dst, | |
172 dmGrowBufConstCreateFrom(&tmp, src->data + offs, len), enlarge); | |
152 } | 173 } |
153 | 174 |
154 | 175 |
155 static BOOL dmGrowBufRealloc(DMGrowBuf *buf, const size_t nsize, const BOOL clear) | 176 static BOOL dmGrowBufRealloc(DMGrowBuf *buf, const size_t nsize, const BOOL clear) |
156 { | 177 { |