Skip to content

Commit

Permalink
Remove dependency on windows.h (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernd5 authored Sep 26, 2020
1 parent c156093 commit 253d631
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@
#endif

#ifdef _WIN32
# if defined(FMT_BIG_WIN) || defined(NOMINMAX)
# include <windows.h>
# include <io.h>
FMT_BEGIN_NAMESPACE
namespace details {

# if !defined(__LP64__)
using DWORD = unsigned long;
# else
# define NOMINMAX
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef WIN32_LEAN_AND_MEAN
# undef NOMINMAX
using DWORD = unsigned int;
# endif
# include <io.h>
// WriteConsoleW should not become visible in global namespace
extern "C" {
int __stdcall WriteConsoleW(void* hConsoleOutput, const void* lpBuffer,
DWORD nNumberOfCharsToWrite,
DWORD* lpNumberOfCharsWritten, void* lpReserved);
}
} // namespace details
FMT_END_NAMESPACE
#endif

// Dummy implementations of strerror_r and strerror_s called if corresponding
Expand Down Expand Up @@ -2897,10 +2904,10 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) {
auto fd = _fileno(f);
if (_isatty(fd)) {
detail::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size()));
auto written = DWORD();
if (!WriteConsoleW(reinterpret_cast<HANDLE>(_get_osfhandle(fd)),
u16.c_str(), static_cast<DWORD>(u16.size()), &written,
nullptr)) {
auto written = details::DWORD();
if (!details::WriteConsoleW(
reinterpret_cast<void*>(_get_osfhandle(fd)), u16.c_str(),
static_cast<details::DWORD>(u16.size()), &written, nullptr)) {
FMT_THROW(format_error("failed to write to console"));
}
return;
Expand Down

0 comments on commit 253d631

Please sign in to comment.