2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2002-07-20 01:57:11 +05:30
|
|
|
/*
|
2005-09-29 21:48:57 +05:30
|
|
|
Copyright (C) 2002,2005 Vladimir Oleynik <dzo@simtreas.ru>
|
2002-07-20 01:57:11 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2002-09-12 20:22:26 +05:30
|
|
|
#include "libbb.h"
|
2002-07-20 01:57:11 +05:30
|
|
|
|
2005-09-29 21:48:57 +05:30
|
|
|
char *bb_xasprintf(const char *format, ...)
|
2002-07-20 01:57:11 +05:30
|
|
|
{
|
2003-03-19 14:43:01 +05:30
|
|
|
va_list p;
|
|
|
|
int r;
|
2005-09-29 21:48:57 +05:30
|
|
|
char *string_ptr;
|
2004-03-15 13:59:22 +05:30
|
|
|
|
2006-03-10 03:51:20 +05:30
|
|
|
#ifdef HAVE_GNU_EXTENSIONS
|
2003-03-19 14:43:01 +05:30
|
|
|
va_start(p, format);
|
2005-09-29 21:48:57 +05:30
|
|
|
r = vasprintf(&string_ptr, format, p);
|
2003-03-19 14:43:01 +05:30
|
|
|
va_end(p);
|
2006-03-10 03:51:20 +05:30
|
|
|
#else
|
|
|
|
va_start(p, format);
|
|
|
|
r = vsnprintf(NULL, 0, format, p);
|
|
|
|
va_end(p);
|
|
|
|
string_ptr = xmalloc(r+1);
|
|
|
|
va_start(p, format);
|
|
|
|
r = vsnprintf(string_ptr, r+1, format, p);
|
|
|
|
va_end(p);
|
|
|
|
#endif
|
2002-07-20 01:57:11 +05:30
|
|
|
|
2003-03-19 14:43:01 +05:30
|
|
|
if (r < 0) {
|
|
|
|
bb_perror_msg_and_die("bb_xasprintf");
|
|
|
|
}
|
2005-09-29 21:48:57 +05:30
|
|
|
return string_ptr;
|
2002-07-20 01:57:11 +05:30
|
|
|
}
|