mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
36 lines
807 B
C
36 lines
807 B
C
|
#include "webfuse/core/string.h"
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
char * wf_create_string(char const * format, ...)
|
||
|
{
|
||
|
char * result = NULL;
|
||
|
|
||
|
va_list measure_args;
|
||
|
va_start(measure_args, format);
|
||
|
char buffer;
|
||
|
int needed = vsnprintf(&buffer, 1, format, measure_args); /* Flawfinder: ignore */
|
||
|
va_end(measure_args);
|
||
|
|
||
|
if (0 <= needed)
|
||
|
{
|
||
|
result = malloc(needed + 1);
|
||
|
if (NULL != result)
|
||
|
{
|
||
|
va_list args;
|
||
|
va_start(args, format);
|
||
|
int count = vsnprintf(result, needed + 1, format, args); /* Flawfinder: ignore */
|
||
|
va_end(args);
|
||
|
|
||
|
if ((count < 0) || (needed < count))
|
||
|
{
|
||
|
free(result);
|
||
|
result = NULL;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|