split belle_sip_snprintf in 2 functions (belle_sip_snprintf and...

split belle_sip_snprintf in 2 functions (belle_sip_snprintf and belle_sip_snprintf_valist) to enable usage with a va_list too
parent e4616ba4
......@@ -157,6 +157,7 @@ BELLESIP_EXPORT void belle_sip_set_log_handler(belle_sip_log_function_t func);
BELLESIP_EXPORT char * BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_strdup_printf(const char *fmt,...);
BELLESIP_EXPORT belle_sip_error_code BELLE_SIP_CHECK_FORMAT_ARGS(4,5) belle_sip_snprintf(char *buff, size_t buff_size, size_t *offset, const char *fmt, ...);
BELLESIP_EXPORT belle_sip_error_code belle_sip_snprintf_valist(char *buff, size_t buff_size, size_t *offset, const char *fmt, va_list args);
BELLESIP_EXPORT void belle_sip_set_log_level(int level);
......
......@@ -111,10 +111,18 @@ char *belle_sip_strdup_printf(const char *fmt,...){
}
belle_sip_error_code belle_sip_snprintf(char *buff, size_t buff_size, size_t *offset, const char *fmt, ...) {
int ret;
belle_sip_error_code error = BELLE_SIP_OK;
belle_sip_error_code ret;
va_list args;
va_start(args, fmt);
ret = belle_sip_snprintf_valist(buff, buff_size, offset, fmt, args);
va_end(args);
return ret;
}
belle_sip_error_code belle_sip_snprintf_valist(char *buff, size_t buff_size, size_t *offset, const char *fmt, va_list args) {
int ret;
belle_sip_error_code error = BELLE_SIP_OK;
ret = vsnprintf(buff + *offset, buff_size - *offset, fmt, args);
if ((ret < 0)
|| (ret >= (buff_size - *offset))) {
......@@ -123,7 +131,6 @@ belle_sip_error_code belle_sip_snprintf(char *buff, size_t buff_size, size_t *of
} else {
*offset += ret;
}
va_end(args);
return error;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment