{\r
va_list tmpList;\r
int size;\r
- char sbuf[1024];\r
- char *buf = sbuf;\r
\r
if(!fp || !format) return -1;\r
\r
va_copy(tmpList, args);\r
\r
- size = vsnprintf(sbuf, sizeof(sbuf), (char*)format, tmpList);\r
- \r
- if( size >= sizeof(sbuf) )\r
- {\r
- buf = (char*)malloc(size+1);\r
- if(!buf) {\r
- WRITE_STR(_stdout, "vfprintf ERROR: malloc() failed");\r
- return 0;\r
- }\r
- buf[size] = '\0';\r
- \r
- // Print\r
- vsnprintf(buf, size+1, (char*)format, args);\r
- }\r
+ size = vsnprintf(NULL, 0, (char*)format, tmpList);\r
+ char buf[size+1];\r
+ vsnprintf(buf, size+1, (char*)format, args);\r
\r
// Write to stream\r
write(fp->FD, buf, size);\r
{\r
#if 1\r
int size;\r
- char sbuf[1024];\r
- char *buf = sbuf;\r
va_list args;\r
\r
// Get final size\r
va_start(args, format);\r
- size = vsnprintf(sbuf, 1024, (char*)format, args);\r
+ size = vsnprintf(NULL, 0, (char*)format, args);\r
+ va_end(args);\r
+ char buf[size+1];\r
+ // Fill Buffer\r
+ va_start(args, format);\r
+ vsnprintf(buf, size+1, (char*)format, args);\r
va_end(args);\r
- \r
- if( size >= 1024 ) {\r
- // Allocate buffer\r
- buf = (char*)malloc(size+1);\r
- if(buf) {\r
- WRITE_STR(_stdout, "PRINTF ERROR: malloc() failed\n");\r
- return 0;\r
- }\r
- buf[size] = '\0';\r
- \r
- // Fill Buffer\r
- va_start(args, format);\r
- vsnprintf(buf, size+1, (char*)format, args);\r
- va_end(args);\r
- }\r
\r
// Send to stdout\r
write(_stdout, buf, size+1);\r