1 /* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <xbt/string.hpp>
7 #include <xbt/sysdep.h>
9 namespace simgrid::xbt {
11 std::string string_vprintf(const char *fmt, va_list ap)
16 int size = std::vsnprintf(nullptr, 0, fmt, ap2);
18 xbt_assert(size >= 0, "string_vprintf error");
20 // Allocate the string and format:
24 xbt_assert(std::vsnprintf(&res[0], size + 1, fmt, ap) == size, "string_vprintf error");
28 std::string string_printf(const char *fmt, ...)
34 res = string_vprintf(fmt, ap);
44 } // namespace simgrid::xbt