mprintf.c 491 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <config.h>

#include <stdio.h>
#include <stdarg.h>

#include "mprintf.h"

// TODO: check for asprintf in configure and
// write a replacement for such situations.

char * mprintf(const char *fmt,...) {
	char *p;
	int r;
	va_list va;

	va_start(va,fmt);
	r = vasprintf(&p,fmt,va);
	va_end(va);
	if( r < 0 )
		return NULL;
	else
		return p;
}

char * vmprintf(const char *fmt,va_list va) {
	char *p;
	int r;

	r = vasprintf(&p,fmt,va);
	if( r < 0 )
		return NULL;
	else
		return p;
}