diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-01-04 21:54:09 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-01-04 21:54:09 +0000 |
commit | b3aeb7784da69aa2b989aa63793cee3c52fecd0e (patch) | |
tree | 0db4074bf85b66c9959784a6b85951b548f8d773 /astmm.c | |
parent | 17a14c041a1c4dcc128fc90eb5b05becc145a6c0 (diff) |
add memory-pool based string field management for structures
convert chan_sip sip_pvt and sip_registry structures to use string fields
add 'const' qualifiers to a few API calls that don't modify their input strings
add an asprintf() wrapper to astmm
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7797 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'astmm.c')
-rw-r--r-- | astmm.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -1,7 +1,7 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 1999 - 2005, Digium, Inc. + * Copyright (C) 1999 - 2006, Digium, Inc. * * Mark Spencer <markster@digium.com> * @@ -47,6 +47,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define FUNC_STRDUP 4 #define FUNC_STRNDUP 5 #define FUNC_VASPRINTF 6 +#define FUNC_ASPRINTF 7 /* Undefine all our macros */ #undef malloc @@ -56,6 +57,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #undef strndup #undef free #undef vasprintf +#undef asprintf #define FENCE_MAGIC 0xdeadbeef @@ -253,6 +255,28 @@ char *__ast_strndup(const char *s, size_t n, const char *file, int lineno, const return ptr; } +int __ast_asprintf(const char *file, int lineno, const char *func, char **strp, const char *fmt, ...) +{ + int size; + va_list ap, ap2; + char s; + + *strp = NULL; + va_start(ap, fmt); + va_copy(ap2, ap); + size = vsnprintf(&s, 1, fmt, ap2); + va_end(ap2); + *strp = __ast_alloc_region(size + 1, FUNC_ASPRINTF, file, lineno, func); + if (!*strp) { + va_end(ap); + return -1; + } + vsnprintf(*strp, size + 1, fmt, ap); + va_end(ap); + + return size; +} + int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, int lineno, const char *func) { int size; @@ -264,8 +288,10 @@ int __ast_vasprintf(char **strp, const char *fmt, va_list ap, const char *file, size = vsnprintf(&s, 1, fmt, ap2); va_end(ap2); *strp = __ast_alloc_region(size + 1, FUNC_VASPRINTF, file, lineno, func); - if (!*strp) + if (!*strp) { + va_end(ap); return -1; + } vsnprintf(*strp, size + 1, fmt, ap); return size; |