提交 dbdc0c03 authored 作者: Mathieu Rene's avatar Mathieu Rene

add switch_core_vsprintf

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15737 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 578466fd
...@@ -551,6 +551,15 @@ SWITCH_DECLARE(char *) switch_core_perform_strdup(_In_ switch_memory_pool_t *poo ...@@ -551,6 +551,15 @@ SWITCH_DECLARE(char *) switch_core_perform_strdup(_In_ switch_memory_pool_t *poo
*/ */
SWITCH_DECLARE(char *) switch_core_session_sprintf(_In_ switch_core_session_t *session, _In_z_ _Printf_format_string_ const char *fmt, ...); SWITCH_DECLARE(char *) switch_core_session_sprintf(_In_ switch_core_session_t *session, _In_z_ _Printf_format_string_ const char *fmt, ...);
/*!
\brief printf-style style printing routine. The data is output to a string allocated from the session
\param session a session to use for allocation
\param fmt The format of the string
\param ap The arguments to use while printing the data
\return The new string
*/
SWITCH_DECLARE(char *) switch_core_session_vsprintf(switch_core_session_t *session, const char *fmt, va_list ap);
/*! /*!
\brief printf-style style printing routine. The data is output to a string allocated from the pool \brief printf-style style printing routine. The data is output to a string allocated from the pool
\param pool a pool to use for allocation \param pool a pool to use for allocation
...@@ -560,6 +569,15 @@ SWITCH_DECLARE(char *) switch_core_session_sprintf(_In_ switch_core_session_t *s ...@@ -560,6 +569,15 @@ SWITCH_DECLARE(char *) switch_core_session_sprintf(_In_ switch_core_session_t *s
*/ */
SWITCH_DECLARE(char *) switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt, ...); SWITCH_DECLARE(char *) switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt, ...);
/*!
\brief printf-style style printing routine. The data is output to a string allocated from the pool
\param pool a pool to use for allocation
\param fmt The format of the string
\param ap The arguments to use while printing the data
\return The new string
*/
SWITCH_DECLARE(char *) switch_core_vsprintf(switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt, va_list ap);
/*! /*!
\brief Retrieve the memory pool from a session \brief Retrieve the memory pool from a session
\param session the session to retrieve the pool from \param session the session to retrieve the pool from
......
...@@ -171,32 +171,20 @@ SWITCH_DECLARE(char *) switch_core_session_sprintf(switch_core_session_t *sessio ...@@ -171,32 +171,20 @@ SWITCH_DECLARE(char *) switch_core_session_sprintf(switch_core_session_t *sessio
va_list ap; va_list ap;
char *result = NULL; char *result = NULL;
#ifdef LOCK_MORE
#ifdef USE_MEM_LOCK
switch_mutex_lock(memory_manager.mem_lock);
#endif
#endif
switch_assert(session != NULL);
switch_assert(session->pool != NULL);
va_start(ap, fmt); va_start(ap, fmt);
result = switch_core_vsprintf(session->pool, fmt, ap);
result = apr_pvsprintf(session->pool, fmt, ap);
switch_assert(result != NULL);
va_end(ap); va_end(ap);
#ifdef LOCK_MORE
#ifdef USE_MEM_LOCK
switch_mutex_unlock(memory_manager.mem_lock);
#endif
#endif
return result; return result;
} }
SWITCH_DECLARE(char *) switch_core_sprintf(switch_memory_pool_t *pool, const char *fmt, ...) SWITCH_DECLARE(char *) switch_core_session_vsprintf(switch_core_session_t *session, const char *fmt, va_list ap)
{
return switch_core_vsprintf(session->pool, fmt, ap);
}
SWITCH_DECLARE(char *) switch_core_vsprintf(switch_memory_pool_t *pool, const char *fmt, va_list ap)
{ {
va_list ap;
char *result = NULL; char *result = NULL;
switch_assert(pool != NULL); switch_assert(pool != NULL);
...@@ -207,11 +195,8 @@ SWITCH_DECLARE(char *) switch_core_sprintf(switch_memory_pool_t *pool, const cha ...@@ -207,11 +195,8 @@ SWITCH_DECLARE(char *) switch_core_sprintf(switch_memory_pool_t *pool, const cha
#endif #endif
#endif #endif
va_start(ap, fmt);
result = apr_pvsprintf(pool, fmt, ap); result = apr_pvsprintf(pool, fmt, ap);
switch_assert(result != NULL); switch_assert(result != NULL);
va_end(ap);
#ifdef LOCK_MORE #ifdef LOCK_MORE
#ifdef USE_MEM_LOCK #ifdef USE_MEM_LOCK
...@@ -222,6 +207,17 @@ SWITCH_DECLARE(char *) switch_core_sprintf(switch_memory_pool_t *pool, const cha ...@@ -222,6 +207,17 @@ SWITCH_DECLARE(char *) switch_core_sprintf(switch_memory_pool_t *pool, const cha
return result; return result;
} }
SWITCH_DECLARE(char *) switch_core_sprintf(switch_memory_pool_t *pool, const char *fmt, ...)
{
va_list ap;
char *result;
va_start(ap, fmt);
result = switch_core_vsprintf(pool, fmt, ap);
va_end(ap);
return result;
}
SWITCH_DECLARE(char *) switch_core_perform_session_strdup(switch_core_session_t *session, const char *todup, const char *file, const char *func, int line) SWITCH_DECLARE(char *) switch_core_perform_session_strdup(switch_core_session_t *session, const char *todup, const char *file, const char *func, int line)
{ {
char *duped = NULL; char *duped = NULL;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论