diff options
author | Luigi Rizzo <rizzo@icir.org> | 2006-12-16 09:33:31 +0000 |
---|---|---|
committer | Luigi Rizzo <rizzo@icir.org> | 2006-12-16 09:33:31 +0000 |
commit | 20b382cfff4a276156d1bac863ae3b6cc9d2a384 (patch) | |
tree | 27d106a85ab51a1a3fce3af1cf043e890d86ca07 /include/asterisk/strings.h | |
parent | b2bd05ee839d4b91730f9b65bd95706b582f2ae5 (diff) |
replace ast_build_string() with ast_str_*() functions.
This makes the code easier to follow and saves some
copies to intermediate buffers.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48515 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r-- | include/asterisk/strings.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 7bfd385a4..832a964ca 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -336,6 +336,27 @@ struct ast_str * attribute_malloc ast_str_create(size_t init_len), } ) +/*! + * Make space in a new string (e.g. to read in data from a file) + */ +AST_INLINE_API( +int ast_str_make_space(struct ast_str **buf, size_t new_len), +{ + if (new_len <= (*buf)->len) + return 0; /* success */ + if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC) + return -1; /* cannot extend */ + *buf = ast_realloc(*buf, new_len + sizeof(struct ast_str)); + if (*buf == NULL) /* XXX watch out, we leak memory here */ + return -1; + if ((*buf)->ts != DS_MALLOC) + pthread_setspecific((*buf)->ts->key, *buf); + + (*buf)->len = new_len; + return 0; +} +) + #define ast_str_alloca(init_len) \ ({ \ struct ast_str *buf; \ |