Skip to content

Instantly share code, notes, and snippets.

@Cactus64k
Created January 21, 2017 20:06
Show Gist options
  • Save Cactus64k/bc4f63ca99ab3a747397651f72895467 to your computer and use it in GitHub Desktop.
Save Cactus64k/bc4f63ca99ab3a747397651f72895467 to your computer and use it in GitHub Desktop.
void strcat_realloc(char** buff, char* str, intmax_t str_len, intmax_t* buff_size, intmax_t* buff_pos)
{
assert(buff != NULL);
assert(str != NULL);
assert(buff_size != NULL);
assert(buff_pos != NULL);
if(*buff_size - *buff_pos - 1 > str_len)
{
strcat(*buff, str);
*buff_pos = *buff_pos + str_len;
}
else
{
*buff_size = *buff_size * 2;
*buff = realloc(*buff, *buff_size);
strcat_realloc(buff, str, str_len, buff_size, buff_pos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment