diff src/dmgrowbuf.c @ 1458:b2dd6a72d162

Adjust semantics of growbuf and add new function.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 10 May 2018 21:00:59 +0300
parents a957b318fbe2
children 1155f4bc4afc
line wrap: on
line diff
--- a/src/dmgrowbuf.c	Thu May 10 19:58:52 2018 +0300
+++ b/src/dmgrowbuf.c	Thu May 10 21:00:59 2018 +0300
@@ -7,7 +7,18 @@
 #include "dmgrowbuf.h"
 
 
-int dmGrowBufInit(DMGrowBuf *buf, const size_t initial, const size_t mingrow)
+int dmGrowBufInit(DMGrowBuf *buf)
+{
+    if (buf == NULL)
+        return DMERR_NULLPTR;
+
+    memset(buf, 0, sizeof(DMGrowBuf));
+
+    return DMERR_OK;
+}
+
+
+int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow)
 {
     if (buf == NULL)
         return DMERR_NULLPTR;
@@ -24,14 +35,16 @@
 }
 
 
-int dmGrowBufAlloc(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow)
+int dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow)
 {
     int res;
+    if (pbuf == NULL)
+        return DMERR_NULLPTR;
 
     if ((*pbuf = dmMalloc0(sizeof(DMGrowBuf))) == NULL)
         return DMERR_MALLOC;
 
-    if ((res = dmGrowBufInit(*pbuf, initial, mingrow)) != DMERR_OK)
+    if ((res = dmGrowBufAlloc(*pbuf, initial, mingrow)) != DMERR_OK)
     {
         dmGrowBufFree(*pbuf);
         return res;