mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
33 lines
673 B
C
33 lines
673 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);
|
|
va_end(measure_args);
|
|
|
|
if (0 <= needed)
|
|
{
|
|
result = malloc(needed + 1);
|
|
va_list args;
|
|
va_start(args, format);
|
|
int count = vsnprintf(result, needed + 1, format, args);
|
|
va_end(args);
|
|
|
|
if ((count < 0) || (needed < count))
|
|
{
|
|
free(result);
|
|
result = NULL;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|