diff options
author | Tilghman Lesher <tilghman@meg.abyt.es> | 2008-11-19 01:02:45 +0000 |
---|---|---|
committer | Tilghman Lesher <tilghman@meg.abyt.es> | 2008-11-19 01:02:45 +0000 |
commit | afb571ba8fbc46cbe6c6d22421e32a13e66a6cbf (patch) | |
tree | 60217ccc3d23a25a5ad3269a0866e94d93a78a52 /main | |
parent | 07a22680ee54082a5a109d0c8b2fda5ea17ca9d8 (diff) |
Starting with a change to ensure that ast_verbose() preserves ABI compatibility
in 1.6.1 (as compared to 1.6.0 and versions of 1.4), this change also
deprecates the use of Asterisk with FreeBSD 4, given the central use of va_copy
in core functions. va_copy() is C99, anyway, and we already require C99 for
other purposes, so this isn't really a big change anyway. This change also
simplifies some of the core ast_str_* functions.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@157639 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r-- | main/logger.c | 24 | ||||
-rw-r--r-- | main/utils.c | 64 |
2 files changed, 56 insertions, 32 deletions
diff --git a/main/logger.c b/main/logger.c index 4e3a2b73c..b4f4c4dd0 100644 --- a/main/logger.c +++ b/main/logger.c @@ -1232,12 +1232,11 @@ void ast_backtrace(void) #endif } -void __ast_verbose(const char *file, int line, const char *func, const char *fmt, ...) +void __ast_verbose_ap(const char *file, int line, const char *func, const char *fmt, va_list ap) { struct logmsg *logmsg = NULL; struct ast_str *buf = NULL; int res = 0; - va_list ap; if (!(buf = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE))) return; @@ -1261,9 +1260,7 @@ void __ast_verbose(const char *file, int line, const char *func, const char *fmt } /* Build string */ - va_start(ap, fmt); res = ast_str_set_va(&buf, 0, fmt, ap); - va_end(ap); /* If the build failed then we can drop this allocated message */ if (res == AST_DYNSTR_BUILD_FAILED) @@ -1291,6 +1288,25 @@ void __ast_verbose(const char *file, int line, const char *func, const char *fmt } } +void __ast_verbose(const char *file, int line, const char *func, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + __ast_verbose_ap(file, line, func, fmt, ap); + va_end(ap); +} + +/* No new code should use this directly, but we have the ABI for backwards compat */ +#undef ast_verbose +void ast_verbose(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +void ast_verbose(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + __ast_verbose_ap("", 0, "", fmt, ap); + va_end(ap); +} + int ast_register_verbose(void (*v)(const char *string)) { struct verb *verb; diff --git a/main/utils.c b/main/utils.c index 9a7a3acd4..0101d93ed 100644 --- a/main/utils.c +++ b/main/utils.c @@ -1667,37 +1667,45 @@ int __ast_str_helper(struct ast_str **buf, size_t max_len, { int res, need; int offset = (append && (*buf)->len) ? (*buf)->used : 0; + va_list aq; - if (max_len < 0) - max_len = (*buf)->len; /* don't exceed the allocated space */ - /* - * Ask vsnprintf how much space we need. Remember that vsnprintf - * does not count the final '\0' so we must add 1. - */ - res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, ap); - - need = res + offset + 1; - /* - * If there is not enough space and we are below the max length, - * reallocate the buffer and return a message telling to retry. - */ - if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) { - if (max_len && max_len < need) /* truncate as needed */ - need = max_len; - else if (max_len == 0) /* if unbounded, give more room for next time */ - need += 16 + need/4; - if (0) /* debugging */ - ast_verbose("extend from %d to %d\n", (int)(*buf)->len, need); - if (ast_str_make_space(buf, need)) { - ast_verbose("failed to extend from %d to %d\n", (int)(*buf)->len, need); - return AST_DYNSTR_BUILD_FAILED; + do { + if (max_len < 0) { + max_len = (*buf)->len; /* don't exceed the allocated space */ } - (*buf)->str[offset] = '\0'; /* Truncate the partial write. */ + /* + * Ask vsnprintf how much space we need. Remember that vsnprintf + * does not count the final '\0' so we must add 1. + */ + va_copy(aq, ap); + res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, aq); + + need = res + offset + 1; + /* + * If there is not enough space and we are below the max length, + * reallocate the buffer and return a message telling to retry. + */ + if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) { + if (max_len && max_len < need) { /* truncate as needed */ + need = max_len; + } else if (max_len == 0) { /* if unbounded, give more room for next time */ + need += 16 + need / 4; + } + if (0) { /* debugging */ + ast_verbose("extend from %d to %d\n", (int)(*buf)->len, need); + } + if (ast_str_make_space(buf, need)) { + ast_verbose("failed to extend from %d to %d\n", (int)(*buf)->len, need); + return AST_DYNSTR_BUILD_FAILED; + } + (*buf)->str[offset] = '\0'; /* Truncate the partial write. */ - /* va_end() and va_start() must be done before calling - * vsnprintf() again. */ - return AST_DYNSTR_BUILD_RETRY; - } + /* Restart va_copy before calling vsnprintf() again. */ + va_end(aq); + continue; + } + break; + } while (1); /* update space used, keep in mind the truncation */ (*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset; |