From baede61f4f5ac478c086a3d428cf5238e33c17c6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 24 Aug 2010 15:56:33 +0900 Subject: [PATCH] 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. --- include/QF/dstring.h | 9 +++++++-- libs/util/dstring.c | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/QF/dstring.h b/include/QF/dstring.h index 682b2a3a5..2e78a38dc 100644 --- a/include/QF/dstring.h +++ b/include/QF/dstring.h @@ -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. diff --git a/libs/util/dstring.c b/libs/util/dstring.c index a9c1df348..efa7b191b 100644 --- a/libs/util/dstring.c +++ b/libs/util/dstring.c @@ -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) {