diff options
author | Luigi Rizzo <rizzo@icir.org> | 2006-12-15 23:10:42 +0000 |
---|---|---|
committer | Luigi Rizzo <rizzo@icir.org> | 2006-12-15 23:10:42 +0000 |
commit | 055abfe9d96e884c12dc41884e9472f41c5b8591 (patch) | |
tree | 67a2fe73762b64d378d6a34cb489de4ff4492a60 /main/utils.c | |
parent | 961754d4b12da98e84aa43992ebb2c578d94ca30 (diff) |
simplify the ast_dynamic_str_*.... routines by
renaming them to ast_str ... and putting the
struct ast_threadstorage pointer into the struct ast_str.
This makes the code a lot more readable.
At this point we can use these routines also to
replace ast_build_string().
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48510 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/utils.c')
-rw-r--r-- | main/utils.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/main/utils.c b/main/utils.c index 9e51dcde1..65d6d20d6 100644 --- a/main/utils.c +++ b/main/utils.c @@ -976,13 +976,13 @@ int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed) * core handler for dynamic strings. * This is not meant to be called directly, but rather through the * various wrapper macros - * ast_dynamic_str_set(...) - * ast_dynamic_str_append(...) - * ast_dynamic_str_thread_set(...) - * ast_dynamic_str_thread_append(...) + * ast_str_set(...) + * ast_str_append(...) + * ast_str_set_va(...) + * ast_str_append_va(...) */ -int __ast_dyn_str_helper(struct ast_dynamic_str **buf, size_t max_len, - struct ast_threadstorage *ts, int append, const char *fmt, va_list ap) +int __ast_str_helper(struct ast_str **buf, size_t max_len, + int append, const char *fmt, va_list ap) { int res, need; int offset = (append && (*buf)->len) ? (*buf)->used : 0; @@ -1005,17 +1005,17 @@ int __ast_dyn_str_helper(struct ast_dynamic_str **buf, size_t max_len, need = max_len; /* We can only realloc malloc'ed space. */ - if ((*buf)->type != DS_MALLOC) + if ((*buf)->ts == DS_ALLOCA || (*buf)->ts == DS_STATIC) return AST_DYNSTR_BUILD_FAILED; - *buf = ast_realloc(*buf, need + sizeof(struct ast_dynamic_str)); + *buf = ast_realloc(*buf, need + sizeof(struct ast_str)); if (*buf == NULL) /* XXX watch out, we leak memory here */ return AST_DYNSTR_BUILD_FAILED; (*buf)->len = need; (*buf)->str[offset] = '\0'; /* Truncate the partial write. */ - if (ts) - pthread_setspecific(ts->key, *buf); + if ((*buf)->ts != DS_ALLOCA) + pthread_setspecific((*buf)->ts->key, *buf); /* va_end() and va_start() must be done before calling * vsnprintf() again. */ |