From: mquinson Date: Wed, 1 Oct 2008 14:53:05 +0000 (+0000) Subject: New functions: X-Git-Tag: v3.3~158 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/42e0ae9b892d0eeeeef780bb4e762833ba916985 New functions: - xbt_strbuff_from() to build a buffer with provided content - xbt_strbuff_free_container() to destroy only the container without messing with the contained data git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5951 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/xbt/strbuff.h b/include/xbt/strbuff.h index 388bbe1dd3..63be41de36 100644 --- a/include/xbt/strbuff.h +++ b/include/xbt/strbuff.h @@ -28,7 +28,9 @@ typedef struct { XBT_PUBLIC(void) xbt_strbuff_empty(xbt_strbuff_t b); XBT_PUBLIC(xbt_strbuff_t) xbt_strbuff_new(void); +XBT_PUBLIC(xbt_strbuff_t) xbt_strbuff_new_from(void); XBT_PUBLIC(void) xbt_strbuff_free(xbt_strbuff_t b); +XBT_PUBLIC(void) xbt_strbuff_free_container(xbt_strbuff_t b); XBT_PUBLIC(void) xbt_strbuff_append(xbt_strbuff_t b, const char *toadd); XBT_PUBLIC(void) xbt_strbuff_chomp(xbt_strbuff_t b); XBT_PUBLIC(void) xbt_strbuff_trim(xbt_strbuff_t b); diff --git a/src/xbt/xbt_strbuff.c b/src/xbt/xbt_strbuff.c index 4fc131e6b7..e12022a697 100644 --- a/src/xbt/xbt_strbuff.c +++ b/src/xbt/xbt_strbuff.c @@ -35,6 +35,21 @@ xbt_strbuff_t xbt_strbuff_new(void) { xbt_strbuff_empty(res); return res; } +/** @brief creates a new string buffer containing the provided string + * + * Beware, we store the ctn directly, not a copy of it + */ +xbt_strbuff_t xbt_strbuff_from(char *ctn) { + xbt_strbuff_t res=malloc(sizeof(s_xbt_strbuff_t)); + res->data=ctn; + res->used=res->size=strlen(ctn); + return res; +} +/** @brief frees only the container without touching to the contained string */ +void xbt_strbuff_free_container(xbt_strbuff_t b) { + free(b); +} +/** @brief frees the buffer and its content */ void xbt_strbuff_free(xbt_strbuff_t b) { if (b) { if (b->data)