New function: dstring_strdup

I got tired of always doing dstring_newstr/dstring_copy, so I thought it
was time to wrap it. dstring_strdup is the dstring equivalent of strdup.
This commit is contained in:
Bill Currie 2010-08-24 15:56:33 +09:00
parent fcdd046333
commit baede61f4f
2 changed files with 15 additions and 2 deletions

View File

@ -57,8 +57,8 @@ extern dstring_mem_t dstring_default_mem;
/** Create a new dstring. size and truesize start at 0 and no string buffer
is allocated.
*/
dstring_t *_dstring_new(dstring_mem_t *mem);
dstring_t *dstring_new(void);
dstring_t *_dstring_new (dstring_mem_t *mem);
dstring_t *dstring_new (void);
//@}
/** Delete a dstring. Both the string buffer and dstring object are freed.
*/
@ -111,6 +111,11 @@ char *dstring_freeze (dstring_t *dstr);
dstring_t *_dstring_newstr (dstring_mem_t *mem);
dstring_t *dstring_newstr (void);
//@}
/** Create a new dstring from a string. Similar to strdup().
\param str the string to copy
\return inititialized dstring
*/
dstring_t *dstring_strdup (const char *str);
/** Open up a hole in the string buffer. The contents of the opened hole
are undefined. The size of the opened hole will be 1 bigger than specified
allowing for a null terminator.

View File

@ -217,6 +217,14 @@ dstring_newstr (void)
return _dstring_newstr (&dstring_default_mem);
}
VISIBLE dstring_t *
dstring_strdup (const char *str)
{
dstring_t *dstr = dstring_new ();
dstring_copystr (dstr, str);
return dstr;
}
VISIBLE char *
dstring_reservestr (dstring_t *dstr, unsigned len)
{