1 //===----------------------------------------------------------------------===////
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===////
9 #ifndef FILESYSTEM_FORMAT_STRING_H
10 #define FILESYSTEM_FORMAT_STRING_H
20 #if defined(_LIBCPP_WIN32API)
21 # define PATHSTR(x) (L##x)
22 # define PATH_CSTR_FMT "\"%ls\""
24 # define PATHSTR(x) (x)
25 # define PATH_CSTR_FMT "\"%s\""
28 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
32 inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__
, 1, 0) string
vformat_string(const char* msg
, va_list ap
) {
37 int ret
= ::vsnprintf(buf
.data(), buf
.size(), msg
, apcopy
);
41 if (static_cast<size_t>(ret
) < buf
.size()) {
42 result
.assign(buf
.data(), static_cast<size_t>(ret
));
44 // we did not provide a long enough buffer on our first attempt. The
45 // return value is the number of bytes (excluding the null byte) that are
46 // needed for formatting.
47 size_t size_with_null
= static_cast<size_t>(ret
) + 1;
48 result
.__resize_default_init(size_with_null
- 1);
49 ret
= ::vsnprintf(&result
[0], size_with_null
, msg
, ap
);
50 _LIBCPP_ASSERT_UNCATEGORIZED(static_cast<size_t>(ret
) == (size_with_null
- 1), "TODO");
55 inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__
, 1, 2) string
format_string(const char* msg
, ...) {
59 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
61 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
62 ret
= detail::vformat_string(msg
, ap
);
63 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
68 #endif // _LIBCPP_HAS_NO_EXCEPTIONS
73 } // end namespace detail
75 _LIBCPP_END_NAMESPACE_FILESYSTEM
77 #endif // FILESYSTEM_FORMAT_STRING_H