Commit b721b6fd authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c0dd86b9
......@@ -72,24 +72,32 @@ error File::_errno(const char *op) {
// fmt::
namespace fmt {
string sprintf(const string &format, ...) {
string _vsprintf(const string &format, va_list argp) {
// based on https://stackoverflow.com/a/26221725/9456786
va_list ap;
va_start(ap, format);
size_t size = vsnprintf(NULL, 0, format.c_str(), ap);
va_end(ap);
va_list argp2;
va_copy(argp2, argp);
size_t size = vsnprintf(NULL, 0, format.c_str(), argp2);
va_end(argp2);
std::unique_ptr<char[]> buf( new char[size] );
va_start(ap, format);
vsnprintf(buf.get(), size, format.c_str(), ap);
va_end(ap);
vsnprintf(buf.get(), size, format.c_str(), argp);
return string(buf.get(), buf.get() + size - 1 ); // without trailing '\0'
}
string sprintf(const string &format, ...) {
va_list argp;
va_start(argp, format);
string str = fmt::_vsprintf(format, argp);
va_end(argp);
return str;
}
error errorf(const string &format, ...) {
error err;
err.err = fmt::sprintf(format, ...); // XXX
va_list argp;
va_start(argp, format);
err.err = fmt::sprintf(format, argp);
va_end(argp);
return err;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment