Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dependency to windows.h #1900

Merged
merged 4 commits into from
Sep 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
bernd5 marked this conversation as resolved.
Show resolved Hide resolved
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