comparison 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
comparison
equal deleted inserted replaced
1457:dcff9ac95d3f 1458:b2dd6a72d162
5 * (C) Copyright 2018 Tecnic Software productions (TNSP) 5 * (C) Copyright 2018 Tecnic Software productions (TNSP)
6 */ 6 */
7 #include "dmgrowbuf.h" 7 #include "dmgrowbuf.h"
8 8
9 9
10 int dmGrowBufInit(DMGrowBuf *buf, const size_t initial, const size_t mingrow) 10 int dmGrowBufInit(DMGrowBuf *buf)
11 {
12 if (buf == NULL)
13 return DMERR_NULLPTR;
14
15 memset(buf, 0, sizeof(DMGrowBuf));
16
17 return DMERR_OK;
18 }
19
20
21 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow)
11 { 22 {
12 if (buf == NULL) 23 if (buf == NULL)
13 return DMERR_NULLPTR; 24 return DMERR_NULLPTR;
14 25
15 buf->len = 0; 26 buf->len = 0;
22 33
23 return DMERR_OK; 34 return DMERR_OK;
24 } 35 }
25 36
26 37
27 int dmGrowBufAlloc(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow) 38 int dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow)
28 { 39 {
29 int res; 40 int res;
41 if (pbuf == NULL)
42 return DMERR_NULLPTR;
30 43
31 if ((*pbuf = dmMalloc0(sizeof(DMGrowBuf))) == NULL) 44 if ((*pbuf = dmMalloc0(sizeof(DMGrowBuf))) == NULL)
32 return DMERR_MALLOC; 45 return DMERR_MALLOC;
33 46
34 if ((res = dmGrowBufInit(*pbuf, initial, mingrow)) != DMERR_OK) 47 if ((res = dmGrowBufAlloc(*pbuf, initial, mingrow)) != DMERR_OK)
35 { 48 {
36 dmGrowBufFree(*pbuf); 49 dmGrowBufFree(*pbuf);
37 return res; 50 return res;
38 } 51 }
39 52