Remove obsolete strbuf function

This commit is contained in:
Linus Dierheimer
2022-06-08 17:14:11 +02:00
parent 63041aa24b
commit 22a8cfdcfe
3 changed files with 11 additions and 31 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ void ffAppendFDContent(int fd, FFstrbuf* buffer)
(uint32_t) readed == free
) {
buffer->length += (uint32_t) readed;
ffStrbufEnsureCapacity(buffer, (buffer->allocated * 2) - 1); // -1 for null terminator
ffStrbufEnsureFree(buffer, buffer->allocated - 1); // Doubles capacity every round. -1 for the null byte.
free = ffStrbufGetFree(buffer);
}
+10 -29
View File
@@ -29,31 +29,12 @@ void ffStrbufInitCopy(FFstrbuf* strbuf, const FFstrbuf* src)
ffStrbufAppend(strbuf, src);
}
static void setCapacity(FFstrbuf* strbuf, uint32_t capacity)
uint32_t ffStrbufGetFree(const FFstrbuf* strbuf)
{
if(strbuf->allocated == 0)
{
strbuf->chars = malloc(sizeof(*strbuf->chars) * capacity);
strbuf->chars[0] = '\0';
}
else
strbuf->chars = realloc(strbuf->chars, sizeof(*strbuf->chars) * capacity);
return 0;
strbuf->allocated = capacity;
}
void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t capacity)
{
if(strbuf->allocated > capacity || capacity == 0)
return;
if(capacity == UINT32_MAX)
{
fputs("Warning: ffStrbufEnsureCapacity called with UINT32_MAX. Highest allowed value is UINT32_MAX - 1. Exiting.\n", stderr);
exit(812);
}
setCapacity(strbuf, capacity + 1); // + 1 for the null byte
return strbuf->allocated - strbuf->length - 1; // - 1 for the null byte
}
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
@@ -68,15 +49,15 @@ void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
while((strbuf->length + free + 1) > allocate) // + 1 for the null byte
allocate *= 2;
setCapacity(strbuf, allocate);
}
uint32_t ffStrbufGetFree(const FFstrbuf* strbuf)
{
if(strbuf->allocated == 0)
return 0;
{
strbuf->chars = malloc(sizeof(*strbuf->chars) * allocate);
strbuf->chars[0] = '\0';
}
else
strbuf->chars = realloc(strbuf->chars, sizeof(*strbuf->chars) * allocate);
return strbuf->allocated - strbuf->length - 1; // - 1 for the null byte
strbuf->allocated = allocate;
}
void ffStrbufClear(FFstrbuf* strbuf)
-1
View File
@@ -23,7 +23,6 @@ void ffStrbufInit(FFstrbuf* strbuf);
void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate);
void ffStrbufInitCopy(FFstrbuf* strbuf, const FFstrbuf* src);
void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t capacity);
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free);
uint32_t ffStrbufGetFree(const FFstrbuf* strbuf);