Skip to content

Commit

Permalink
Add an option to avoid wchar APIs on Windows
Browse files Browse the repository at this point in the history
With this, fmt can be used on Windows 98 and the Original Xbox with:

    set(FMT_OS OFF)

`FMT_WINDOWS_NO_WCHAR` is detected automatically in 2 cases:

1. Missing `<io.h>` on the original Xbox
2. A defined `WINVER` on properly configured Windows projects

In other cases, one can `add_definitions(FMT_WINDOWS_NO_WCHAR)`
in the fmt subproject.

Fixes fmtlib#3631
  • Loading branch information
glebm committed Sep 17, 2023
1 parent d498754 commit fbcabcf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@
# include <locale>
#endif

#include "core.h"

#ifdef _WIN32
#if !defined(FMT_WINDOWS_NO_WCHAR) && (!FMT_HAS_INCLUDE(<io.h>) || (defined(WINVER) && WINVER <= 0x0500 && !defined(_WIN32_WINNT)))
// A legacy Windows platform without wide char APIs, e.g. Windows 98, original Xbox.
#define FMT_WINDOWS_NO_WCHAR
#endif

#ifndef FMT_WINDOWS_NO_WCHAR
# include <io.h> // _isatty
#endif
#endif

#include "format.h"

Expand Down Expand Up @@ -1426,7 +1435,7 @@ FMT_FUNC std::string vformat(string_view fmt, format_args args) {
}

namespace detail {
#ifndef _WIN32
#if !defined(_WIN32) || defined(FMT_WINDOWS_NO_WCHAR)
FMT_FUNC bool write_console(std::FILE*, string_view) { return false; }
#else
using dword = conditional_t<sizeof(long) == 4, unsigned long, unsigned>;
Expand Down

0 comments on commit fbcabcf

Please sign in to comment.