diff 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
line wrap: on
line diff
--- a/src/dmgrowbuf.c	Thu Jul 04 10:51:02 2019 +0300
+++ b/src/dmgrowbuf.c	Thu Jul 04 10:54:16 2019 +0300
@@ -144,6 +144,15 @@
 }
 
 
+DMGrowBuf * dmGrowBufConstCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len)
+{
+    if (src->len < offs + len)
+        return NULL;
+
+    return dmGrowBufConstCreateFrom(dst, src->data + offs, len);
+}
+
+
 DMGrowBuf * dmGrowBufCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t enlarge)
 {
     DMGrowBuf tmp;
@@ -152,6 +161,18 @@
 }
 
 
+DMGrowBuf * dmGrowBufCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len, const size_t enlarge)
+{
+    DMGrowBuf tmp;
+
+    if (src->len < offs + len)
+        return NULL;
+
+    return dmGrowBufCopy(dst,
+        dmGrowBufConstCreateFrom(&tmp, src->data + offs, len), enlarge);
+}
+
+
 static BOOL dmGrowBufRealloc(DMGrowBuf *buf, const size_t nsize, const BOOL clear)
 {
     DM_DBG("dmGrowBufRealloc(%p):\n"