From 8bd59ec936966cb339d999abc80703548c4e27ad Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 24 Jul 2019 16:44:29 -1000 Subject: [PATCH] Use fputws for outputting wide strings Also adds fwide byte/wide orientation checking to verify streams are able to receive the character type in question. On Windows, the fwide calls are no-ops that pass through the second arg and optimize out the if statement entirely. --- include/fmt/format-inl.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index f6fa29ab..bdafd5bb 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -19,6 +19,7 @@ #include #include // for std::ptrdiff_t #include // for std::memmove +#include #if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) # include #endif @@ -977,7 +978,10 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) { FMT_FUNC void vprint(std::FILE* f, wstring_view format_str, wformat_args args) { wmemory_buffer buffer; internal::vformat_to(buffer, format_str, args); - internal::fwrite_fully(buffer.data(), sizeof(wchar_t), buffer.size(), f); + buffer.push_back(L'\0'); + if (std::fputws(buffer.data(), f) == -1) { + FMT_THROW(system_error(errno, "cannot write to file")); + } } FMT_FUNC void vprint(string_view format_str, format_args args) {