1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Add bufSizeAlloc().

This commit is contained in:
David Steele 2020-10-07 16:34:13 -04:00
parent c8a94d9eb6
commit 39aca3269c
2 changed files with 10 additions and 1 deletions

View File

@ -81,6 +81,14 @@ bufSize(const Buffer *this)
return ((const BufferConst *)this)->size;
}
// Allocated buffer size. This may be different from bufSize() if a limit has been set.
__attribute__((always_inline)) static inline size_t
bufSizeAlloc(const Buffer *this)
{
ASSERT_INLINE(this != NULL);
return ((const BufferConst *)this)->sizeAlloc;
}
// Amount of the buffer actually used. This will be updated automatically when possible but if the buffer is modified by using
// bufPtr() then the user is responsible for updating used.
__attribute__((always_inline)) static inline size_t

View File

@ -11,7 +11,7 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// *****************************************************************************************************************************
if (testBegin("bufNew(), bufNewC, bufNewUseC, bufMove(), bufSize(), bufPtr(), and bufFree()"))
if (testBegin("bufNew(), bufNewC, bufNewUseC, bufMove(), bufSize(), bufSizeAlloc(), bufPtr(), and bufFree()"))
{
Buffer *buffer = NULL;
@ -24,6 +24,7 @@ testRun(void)
TEST_RESULT_PTR(bufPtr(buffer), buffer->buffer, "buffer pointer");
TEST_RESULT_UINT(bufSize(buffer), 256, "buffer size");
TEST_RESULT_UINT(bufSizeAlloc(buffer), 256, "buffer allocation size");
TEST_ASSIGN(buffer, bufNewC("TEST-STR", sizeof("TEST-STR") - 1), "new buffer from string");
TEST_RESULT_BOOL(memcmp(bufPtr(buffer), "TEST-STR", 8) == 0, true, "check buffer");