parent
f52e0923bc
commit
625a6af459
@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int asprintf(char **strp, char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
int count = vasprintf(strp, format, args);
|
||||
|
||||
va_end(args);
|
||||
return count;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int vasprintf(char **strp, char const *format, va_list args1)
|
||||
{
|
||||
va_list args2;
|
||||
va_copy(args2, args1);
|
||||
|
||||
int count = vsnprintf(NULL, 0, format, args1);
|
||||
va_end(args1);
|
||||
|
||||
char *str = malloc(count + 1);
|
||||
if(str) count = vsnprintf(str, count + 1, format, args2);
|
||||
va_end(args2);
|
||||
|
||||
if(!str) return -1;
|
||||
*strp = str;
|
||||
return count;
|
||||
}
|
Loading…
Reference in new issue