Merge pull request #2512 from spnethw/tmppanel_fix_menu_from_file_list_crash
[far2l.git] / utils / src / StrPrintf.cpp
blob0b81a2539445c2ede23241abad8617e05f762bdf
1 #include <utils.h>
3 std::string StrPrintfV(const char *format, va_list args)
5 std::string out(15, '#'); // 15 is maximum number of characters when SSO still being used
7 va_list args_copy;
8 va_copy(args_copy, args);
9 int rv = vsnprintf(&out[0], out.size(), format, args_copy);
10 va_end(args_copy);
12 if (rv >= 0 && rv < (int)out.size()) {
13 out.resize(rv);
14 return out;
17 out.resize(rv + 1);
18 rv = vsnprintf(&out[0], out.size(), format, args);
20 if (rv >= 0 && rv < (int)out.size()) {
21 out.resize(rv);
22 return out;
25 out = "Bad format string: ";
26 out+= format;
27 return out;
30 std::string StrPrintf(const char *format, ...)
32 va_list args;
33 va_start(args, format);
35 const std::string &out = StrPrintfV(format, args);
37 va_end(args);
39 return out;