diff options
author | Jeremy McNamara <jj@nufone.net> | 2004-01-14 06:35:01 +0000 |
---|---|---|
committer | Jeremy McNamara <jj@nufone.net> | 2004-01-14 06:35:01 +0000 |
commit | cf41cc2ec21d67fefb0a0e362312b7f0dd18f720 (patch) | |
tree | be59a9a808f8f08a11acfdd5435be61ca1ebea72 /astmm.c | |
parent | b3ab1cbe7305bec82074dcd9cdee1ec5c242ded5 (diff) |
add a vasprintf replacement. Bug #839
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2030 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'astmm.c')
-rwxr-xr-x | astmm.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -32,6 +32,7 @@ #define FUNC_REALLOC 3 #define FUNC_STRDUP 4 #define FUNC_STRNDUP 5 +#define FUNC_VASPRINTF 6 /* Undefine all our macros */ #undef malloc @@ -40,6 +41,7 @@ #undef strdup #undef strndup #undef free +#undef vasprintf static FILE *mmlog; @@ -217,6 +219,24 @@ char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const return ptr; } +int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func) +{ + int n, size = strlen(fmt) + 1; + if ((*strp = __ast_alloc_region(size, FUNC_VASPRINTF, file, lineno, func)) == NULL) + return -1; + for (;;) { + n = vsnprintf(*strp, size, fmt, ap); + if (n > -1 && n < size) + return n; + if (n > -1) /* glibc 2.1 */ + size = n+1; + else /* glibc 2.0 */ + size *= 2; + if ((*strp = __ast_realloc(*strp, size, file, lineno, func)) == NULL) + return -1; + } +} + static int handle_show_memory(int fd, int argc, char *argv[]) { char *fn = NULL; |