comparison src/dmgrowbuf.c @ 1509:15afe578f0ae

Add few comments to clarify things.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 May 2018 22:22:40 +0300
parents 97b8096f16dc
children 94eb6a8a7d56
comparison
equal deleted inserted replaced
1508:97b8096f16dc 1509:15afe578f0ae
28 buf->len = 0; 28 buf->len = 0;
29 buf->size = initial; 29 buf->size = initial;
30 buf->mingrow = mingrow; 30 buf->mingrow = mingrow;
31 buf->allocated = FALSE; 31 buf->allocated = FALSE;
32 32
33 // Allocate the data
33 if ((buf->data = dmMalloc0(initial)) == NULL) 34 if ((buf->data = dmMalloc0(initial)) == NULL)
34 return DMERR_MALLOC; 35 return DMERR_MALLOC;
35 36
36 return DMERR_OK; 37 return DMERR_OK;
37 } 38 }
70 dmFree(buf); 71 dmFree(buf);
71 } 72 }
72 } 73 }
73 74
74 75
76 //
77 // Grow the buffer by "amount" bytes, but at least by buf->mingrow,
78 // if there is not enough space for at least that amount compared to
79 // current buffer "len".
80 //
75 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount) 81 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount)
76 { 82 {
77 size_t grow = (amount > buf->mingrow) ? amount : buf->mingrow; 83 size_t grow = (amount > buf->mingrow) ? amount : buf->mingrow;
78 if (buf->data == NULL || buf->len + grow > buf->size) 84 if (buf->data == NULL || buf->len + grow > buf->size)
79 { 85 {
87 93
88 return TRUE; 94 return TRUE;
89 } 95 }
90 96
91 97
98 //
99 // Grow the buffer if "nsize" is larger than the current buffer size.
100 // Buffer is enlarged to nsize + mingrow.
101 //
92 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize) 102 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize)
93 { 103 {
94 if (buf->data == NULL || nsize > buf->size) 104 if (buf->data == NULL || nsize > buf->size)
95 { 105 {
96 size_t prev = buf->size; 106 size_t prev = buf->size;