Mercurial > hg > dmlib
diff src/dmgrowbuf.c @ 2586:9807ae37ad69
Require stdbool.h, we require C11 now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 08 Dec 2022 15:59:22 +0200 |
parents | c6ee41fd98dd |
children |
line wrap: on
line diff
--- a/src/dmgrowbuf.c Thu Dec 08 15:56:36 2022 +0200 +++ b/src/dmgrowbuf.c Thu Dec 08 15:59:22 2022 +0200 @@ -42,8 +42,8 @@ buf->offs = 0; buf->size = initial; buf->mingrow = mingrow; - buf->backwards = FALSE; - buf->is_const = FALSE; + buf->backwards = false; + buf->is_const = false; // Allocate the data if ((buf->data = dmMalloc0(initial)) == NULL) @@ -100,7 +100,7 @@ memset(dst->data + src->size, 0, enlarge); // And reset some struct information - dst->is_const = FALSE; + dst->is_const = false; return dst; } @@ -116,7 +116,7 @@ dst, src, src->data, src->size, src->len, src->offs); memcpy(dst, src, sizeof(DMGrowBuf)); - dst->is_const = TRUE; + dst->is_const = true; return dst; } @@ -132,7 +132,7 @@ dst->data = data; dst->len = dst->size = len; - dst->is_const = TRUE; + dst->is_const = true; return dst; } @@ -173,7 +173,7 @@ } -static BOOL dmGrowBufRealloc(DMGrowBuf *buf, const size_t nsize, const BOOL clear) +static bool dmGrowBufRealloc(DMGrowBuf *buf, const size_t nsize, const bool clear) { DM_DBG("dmGrowBufRealloc(%p):\n" " size=%" DM_PRIu_SIZE_T ", nsize=%" DM_PRIu_SIZE_T @@ -181,14 +181,14 @@ buf, buf->size, nsize, buf->offs); if (buf->is_const) - return FALSE; + return false; // Can't be smaller than current size! if (nsize < buf->size) - return FALSE; + return false; if ((buf->data = dmRealloc(buf->data, nsize)) == NULL) - return FALSE; + return false; // For buffers growing backwards, we must move the // current data to the end of the buffer .. @@ -211,7 +211,7 @@ buf->size = nsize; - return TRUE; + return true; } @@ -220,12 +220,12 @@ // if there is not enough space for at least that amount compared to // current buffer "len". // -BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount) +bool dmGrowBufGrow(DMGrowBuf *buf, const size_t amount) { size_t grow = (amount > buf->mingrow) ? amount : buf->mingrow; if (buf->is_const) - return FALSE; + return false; if (buf->data == NULL || (buf->backwards && amount >= buf->offs) || @@ -234,12 +234,12 @@ DM_DBG("dmGrowBufGrow(%p, amount=%" DM_PRIu_SIZE_T "): grow=%" DM_PRIu_SIZE_T "\n", buf, amount, grow); - if (!dmGrowBufRealloc(buf, buf->size + grow, TRUE)) - return FALSE; + if (!dmGrowBufRealloc(buf, buf->size + grow, true)) + return false; } buf->len += amount; - return TRUE; + return true; } @@ -247,31 +247,31 @@ // Grow the buffer if "nsize" is larger than the current buffer size. // Buffer is enlarged to nsize + mingrow. // -BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize) +bool dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize) { if (buf->is_const) - return FALSE; + return false; if (buf->data == NULL || nsize > buf->size) { - if (!dmGrowBufRealloc(buf, nsize + buf->mingrow, TRUE)) - return FALSE; + if (!dmGrowBufRealloc(buf, nsize + buf->mingrow, true)) + return false; } if (nsize > buf->len) buf->len = nsize; - return TRUE; + return true; } -BOOL dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len) +bool dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len) { if (data == NULL) - return FALSE; + return false; if (!dmGrowBufGrow(buf, len)) - return FALSE; + return false; if (buf->backwards) { @@ -292,25 +292,25 @@ buf->offs += len; } - return TRUE; + return true; } -BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value) +bool dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value) { if (!dmGrowBufGrow(buf, sizeof(Uint8))) - return FALSE; + return false; if (buf->backwards) buf->data[--buf->offs] = value; else buf->data[buf->offs++] = value; - return TRUE; + return true; } -BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val) +bool dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val) { if (buf->literal && buf->backwards) { @@ -327,7 +327,7 @@ } -BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val) +bool dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val) { if (buf->literal && buf->backwards) { @@ -344,7 +344,7 @@ } -BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val) +bool dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val) { if (buf->literal && buf->backwards) { @@ -365,7 +365,7 @@ } -BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val) +bool dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val) { if (buf->literal && buf->backwards) { @@ -386,22 +386,22 @@ } -BOOL dmGrowBufGetU8(DMGrowBuf *buf, Uint8 *value) +bool dmGrowBufGetU8(DMGrowBuf *buf, Uint8 *value) { if (buf->backwards) { if (buf->offs > 0) *value = buf->data[--buf->offs]; else - return FALSE; + return false; } else { if (buf->offs < buf->len) *value = buf->data[buf->offs++]; else - return FALSE; + return false; } - return TRUE; + return true; }