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 3 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
23 changes: 10 additions & 13 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@
#endif

#ifdef _WIN32
# if defined(FMT_BIG_WIN) || defined(NOMINMAX)
# include <windows.h>
# else
# define NOMINMAX
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef WIN32_LEAN_AND_MEAN
# undef NOMINMAX
# endif
# include <io.h>
FMT_BEGIN_NAMESPACE
bernd5 marked this conversation as resolved.
Show resolved Hide resolved
extern "C" {
int __stdcall WriteConsoleW(void* hConsoleOutput, const void* lpBuffer,
uint32_t nNumberOfCharsToWrite,
uint32_t* lpNumberOfCharsWritten, void* lpReserved);
}
FMT_END_NAMESPACE
#endif

// Dummy implementations of strerror_r and strerror_s called if corresponding
Expand Down Expand Up @@ -2897,10 +2895,9 @@ 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 = uint32_t();
if (!WriteConsoleW(reinterpret_cast<void*>(_get_osfhandle(fd)), u16.c_str(),
static_cast<uint32_t>(u16.size()), &written, nullptr)) {
FMT_THROW(format_error("failed to write to console"));
}
return;
Expand Down