Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
StringPrintf.cxx
1
36
37std::string StringPrintf(const char *format, ...)
38{
39#ifdef __FreeRTOS__
40 static const int kBufSize = 64;
41#else
42 static const int kBufSize = 1000;
43#endif
44 char buffer[kBufSize];
45 va_list ap;
46
47 va_start(ap, format);
48 int n = vsnprintf(buffer, kBufSize, format, ap);
49 va_end(ap);
50 HASSERT(n >= 0);
51 if (n < kBufSize)
52 {
53 return string(buffer, n);
54 }
55 string ret(n + 1, 0);
56 va_start(ap, format);
57 n = vsnprintf(&ret[0], ret.size(), format, ap);
58 va_end(ap);
59 HASSERT(n >= 0);
60 ret.resize(n);
61 return ret;
62}
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138