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