* if (!fct2(err)) report(*err);
* if (!fct3(err)) report(*err);
* free(*err);
+ *
+ * memprintf relies on memvprintf. This last version can be called from any
+ * function with variadic arguments.
*/
+char *memvprintf(char **out, const char *format, va_list args)
+ __attribute__ ((format(printf, 2, 0)));
+
char *memprintf(char **out, const char *format, ...)
__attribute__ ((format(printf, 2, 3)));
* if (!fct2(err)) report(*err);
* if (!fct3(err)) report(*err);
* free(*err);
+ *
+ * memprintf relies on memvprintf. This last version can be called from any
+ * function with variadic arguments.
*/
-char *memprintf(char **out, const char *format, ...)
+char *memvprintf(char **out, const char *format, va_list orig_args)
{
va_list args;
char *ret = NULL;
* target buffer is NULL. We do this in a loop just in case
* intermediate evaluations get wrong.
*/
- va_start(args, format);
+ va_copy(args, orig_args);
needed = vsnprintf(ret, allocated, format, args);
va_end(args);
-
if (needed < allocated) {
/* Note: on Solaris 8, the first iteration always
* returns -1 if allocated is zero, so we force a
return ret;
}
+char *memprintf(char **out, const char *format, ...)
+{
+ va_list args;
+ char *ret = NULL;
+
+ va_start(args, format);
+ ret = memvprintf(out, format, args);
+ va_end(args);
+
+ return ret;
+}
+
/* Used to add <level> spaces before each line of <out>, unless there is only one line.
* The input argument is automatically freed and reassigned. The result will have to be
* freed by the caller. It also supports being passed a NULL which results in the same