MCPcopy Create free account
hub / github.com/apple/foundationdb / vsformat

Function vsformat

flow/flow.cpp:242–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242int vsformat(std::string& outputString, const char* form, va_list args) {
243 char buf[200];
244
245 va_list args2;
246 va_copy(args2, args);
247 int size = vsnprintf(buf, sizeof(buf), form, args2);
248 va_end(args2);
249
250 if (size >= 0 && size < sizeof(buf)) {
251 outputString = std::string(buf, size);
252 return size;
253 }
254
255#ifdef _WIN32
256 // Microsoft's non-standard vsnprintf doesn't return a correct size, but just an error, so determine the necessary
257 // size
258 va_copy(args2, args);
259 size = _vscprintf(form, args2);
260 va_end(args2);
261#endif
262
263 if (size < 0) {
264 return -1;
265 }
266
267 CODE_PROBE(true, "large format result");
268
269 outputString.resize(size + 1);
270 size = vsnprintf(&outputString[0], outputString.size(), form, args);
271 if (size < 0 || size >= outputString.size()) {
272 return -1;
273 }
274
275 outputString.resize(size);
276 return size;
277}
278
279std::string format(const char* form, ...) {
280 va_list args;

Callers 2

Trace.cppFile · 0.85
formatFunction · 0.85

Calls 2

resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected