SynopsisReallocate a block of memory. Prototype#include "uemf.h" void *brealloc(B_ARGS_DEC, void* mp, int newsize); Parameters
DescriptionThe GoAhead equivalent of realloc. Note: Allows NULL pointers. Will just do a balloc on the size if that is the case. Return ValueReturn pointer to newly allocated block. If the realloc fails, NULL is returned and the previous buffer is preserved. Example
/***********************************************************************/
/*
* Add a character to a string buffer
*/
static void put_char(strbuf_t *buf, char_t c)
{
if (buf->count >= buf->size) {
if (! (buf->flags & STR_REALLOC)) {
return;
}
buf->size += STR_INC;
if (buf->size > buf->max && buf->size > STR_INC) {
a_assert(buf->size <= buf->max);
buf->size -= STR_INC;
return;
}
if (buf->s == NULL) {
buf->s = balloc(B_L, buf->size * sizeof(char_t));
} else {
buf->s = brealloc(B_L, buf->s, buf->size * sizeof(char_t));
}
}
buf->s[buf->count] = c;
++buf->count;
}
Stability ClassificationStable. See Also |