mirror of https://github.com/FreeRDP/FreeRDP
[winpr,str] add winpr_vasprintf
This commit is contained in:
parent
7d02a97a88
commit
f1ddc19806
|
@ -40,6 +40,7 @@ extern "C"
|
|||
const char* separator);
|
||||
|
||||
WINPR_API int winpr_asprintf(char** s, size_t* slen, const char* templ, ...);
|
||||
WINPR_API int winpr_vasprintf(char** s, size_t* slen, const char* templ, va_list ap);
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
|
|
|
@ -180,12 +180,21 @@ int winpr_asprintf(char** s, size_t* slen, WINPR_FORMAT_ARG const char* templ, .
|
|||
{
|
||||
va_list ap;
|
||||
|
||||
WINPR_ASSERT(s);
|
||||
WINPR_ASSERT(slen);
|
||||
va_start(ap, templ);
|
||||
int rc = winpr_vasprintf(s, slen, templ, ap);
|
||||
va_end(ap);
|
||||
return rc;
|
||||
}
|
||||
|
||||
WINPR_ATTR_FORMAT_ARG(3, 0)
|
||||
int winpr_vasprintf(char** s, size_t* slen, WINPR_FORMAT_ARG const char* templ, va_list oap)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
*s = NULL;
|
||||
*slen = 0;
|
||||
|
||||
va_start(ap, templ);
|
||||
va_copy(ap, oap);
|
||||
const int length = vsnprintf(NULL, 0, templ, ap);
|
||||
va_end(ap);
|
||||
if (length < 0)
|
||||
|
@ -195,7 +204,7 @@ int winpr_asprintf(char** s, size_t* slen, WINPR_FORMAT_ARG const char* templ, .
|
|||
if (!str)
|
||||
return -1;
|
||||
|
||||
va_start(ap, templ);
|
||||
va_copy(ap, oap);
|
||||
const int plen = vsprintf(str, templ, ap);
|
||||
va_end(ap);
|
||||
|
||||
|
|
Loading…
Reference in New Issue