cfs/src/perfutil/Util.cc
/// A safe version of vprintf.
A safe version of vprintf.
A safe version of vprintf .
string
vformat(const char* format, va_list ap) {
  string s;
  int bufSize = 1024;
  while (true) {
    char buf[bufSize];
    va_list aq;
    __va_copy(aq, ap);
    int r = vsnprintf(buf, bufSize, format, aq);
    assert(r >= 0);  
    if (r < bufSize) {
      s = buf;
      break;
    }
    bufSize = r + 1;
  }
  return s;
}
string vformat ( const char * format , va_list ap ) { string s ; int bufSize = 1024 ; while ( true ) { char buf [ bufSize ] ; va_list aq ; __va_copy ( aq , ap ) ; int r = vsnprintf ( buf , bufSize , format , aq ) ; assert ( r >= 0 ) ; if ( r < bufSize ) { s = buf ; break ; } bufSize = r + 1 ; } return s ; }
A safe version of vprintf.
A safe version of vprintf .
// We're not really sure how big of a buffer will be necessary. // Try 1K, if not the return value will tell us how much is necessary. // vsnprintf trashes the va_list, so copy it first // old glibc versions returned -1