#include #include #include "util.h" //#define PRINTF_PRECISE //set to 1 to make sure print is never truncated (twice as slow on strings >100chars) #define PRINTF_BUFFER 100 //does nothing if PRINTF_PRECISE is defined int printf(const char *template, ...) __attribute__((format (printf, 1, 2))); int printf(const char *template, ...){ //printl("printf called\n"); #ifdef PRINTF_PRECISE char *buf; #else char buf[PRINTF_BUFFER]; #endif va_list ap; int chars; va_start(ap, template); #ifdef PRINTF_PRECISE buf=malloc(100); if(buf==NULL) return -1; chars=vsnprintf(buf, 100, template, ap); if(chars>100){ buf=realloc(chars); if(buf==NULL) return -1; va_start(ap, template); chars=vsnprintf(buf, chars, template, ap); } printl(buf); free(buf); #else chars=vsnprintf(buf, PRINTF_BUFFER, template, ap); printl(buf); #endif va_end (ap); }