2 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 #include "common/angleutils.h"
11 std::string FormatString(const char *fmt, va_list vararg)
13 static std::vector<char> buffer(512);
15 // Attempt to just print to the current buffer
16 int len = vsnprintf(&buffer[0], buffer.size(), fmt, vararg);
17 if (len < 0 || static_cast<size_t>(len) >= buffer.size())
19 // Buffer was not large enough, calculate the required size and resize the buffer
20 len = vsnprintf(NULL, 0, fmt, vararg);
21 buffer.resize(len + 1);
24 vsnprintf(&buffer[0], buffer.size(), fmt, vararg);
27 return std::string(buffer.data(), len);
30 std::string FormatString(const char *fmt, ...)
33 va_start(vararg, fmt);
34 std::string result = FormatString(fmt, vararg);