mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-11 20:03:11 +00:00
[dstring] Implement reserve
In the end, I'm not sure when I'll use it, but at least the expected semantics are there.
This commit is contained in:
parent
ebaa557d2a
commit
4329537b1b
2 changed files with 18 additions and 0 deletions
|
@ -66,6 +66,10 @@ void dstring_delete (dstring_t *dstr);
|
|||
large enough to hold size bytes (rounded up to the next 1kB boundary)
|
||||
*/
|
||||
void dstring_adjust (dstring_t *dstr);
|
||||
/** Ensure the string buffer is large enough to hold the requested additional
|
||||
bytes (total size will be rounded up to the next 1kB boundary).
|
||||
*/
|
||||
void dstring_reserve (dstring_t *dstr, size_t delta);
|
||||
/** Open up a hole in the string buffer. The contents of the opened hole
|
||||
are undefined.
|
||||
\param dstr the dstring in which to open the hole.
|
||||
|
|
|
@ -103,6 +103,20 @@ dstring_adjust (dstring_t *dstr)
|
|||
}
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
dstring_reserve (dstring_t *dstr, size_t delta)
|
||||
{
|
||||
size_t newsize = dstr->size + delta;
|
||||
if (newsize > dstr->truesize) {
|
||||
dstr->truesize = (newsize + 1023) & ~1023;
|
||||
dstr->str = dstr->mem->realloc (dstr->mem->data, dstr->str,
|
||||
dstr->truesize);
|
||||
if (!dstr->str) {
|
||||
Sys_Error ("dstring_reserve: Failed to reallocate memory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VISIBLE char *
|
||||
dstring_open (dstring_t *dstr, size_t len)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue