00001 #include "FormString.hh"
00002 #include <stdarg.h>
00003 #include <iostream>
00004
00005 using namespace Logging;
00006
00007 std::string Logging::FormString(const char* fmt, ...)
00008 {
00009 static int sBufSize = 10;
00010 static char* sBuffer = new char[sBufSize];
00011
00012 va_list ap;
00013 va_start(ap,fmt);
00014 int res = vsnprintf(sBuffer, sBufSize, fmt, ap);
00015 va_end(ap);
00016 if(res > sBufSize) {
00017 sBufSize = res+20;
00018 std::cerr << "Increasing buffer size to " << sBufSize << std::endl;
00019 delete [] sBuffer;
00020 sBuffer = new char[sBufSize];
00021
00022
00023 va_list ap2;
00024 va_start(ap2,fmt);
00025 int res = vsnprintf(sBuffer, sBufSize, fmt, ap2);
00026 res = 0;
00027 va_end(ap2);
00028 }
00029
00030 return std::string(sBuffer);
00031 }