Commit 64b694a5 authored by Niels Möller's avatar Niels Möller

* src/argp/argp-test.c: Fixed asprintf implementation.

Rev: src/argp/argp-test.c:1.3
parent 23c4f27e
......@@ -42,12 +42,16 @@
#endif
#if !HAVE_ASPRINTF
int asprintf (char **result, const char *format, ...)
#include <stdarg.h>
static int
asprintf (char **result, const char *format, ...)
{
size_t size = 200;
char *p = NULL;
size_t size;
char *p;
do {
for (size = 200, p = NULL;; size *= 2)
{
va_list args;
int written;
......@@ -61,12 +65,15 @@ int asprintf (char **result, const char *format, ...)
p[size] = '\0';
va_start(args, format);
written = vsnprintf(format, size, args);
written = vsnprintf(p, format, size, args);
va_end(args);
} while (written < 0);
*result = p;
if (written >= 0)
{
*result = p;
return written;
}
}
}
#endif /* !HAVE_ASPRINTF */
......
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