Added the useful dstring_freeze function to convert a dstring to a

finalized, plain C string.
This commit is contained in:
Brian Koropoff 2003-04-13 05:48:28 +00:00
parent 23278d0706
commit 63c3038ad8
2 changed files with 11 additions and 2 deletions

View file

@ -48,6 +48,7 @@ void dstring_snip (dstring_t *dstr, unsigned int pos, unsigned int len);
void dstring_clear (dstring_t *dstr);
void dstring_replace (dstring_t *dstr, unsigned int pos, unsigned int rlen,
const char *data, unsigned int len);
char *dstring_freeze (dstring_t *dstr);
// String-specific functions
dstring_t *dstring_newstr (void);

View file

@ -126,6 +126,14 @@ dstring_replace (dstring_t *dstr, unsigned int pos, unsigned int rlen,
memcpy (dstr->str + pos, data, len);
}
char *
dstring_freeze (dstring_t *dstr)
{
char *str = realloc (dstr->str, dstr->size);
free (dstr);
return str;
}
dstring_t *
dstring_newstr (void)
{