Don't use windows.h if FMT_USE_WINDOWS_H is set to 0
This commit is contained in:
parent
9d09214e7a
commit
24c309fbfa
59
format.cc
59
format.cc
@ -35,10 +35,11 @@
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef __MINGW32__
|
||||
#if defined(_WIN32) && defined(__MINGW32__)
|
||||
# include <cstring>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if FMT_USE_WINDOWS_H
|
||||
# if defined(NOMINMAX) || defined(FMT_WIN_MINMAX)
|
||||
# include <windows.h>
|
||||
# else
|
||||
@ -488,7 +489,7 @@ FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) {
|
||||
static_cast<unsigned>(code), type)));
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#if FMT_USE_WINDOWS_H
|
||||
|
||||
FMT_FUNC fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) {
|
||||
int length = MultiByteToWideChar(
|
||||
@ -531,30 +532,6 @@ FMT_FUNC void fmt::WindowsError::init(
|
||||
base = std::runtime_error(w.str());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
FMT_FUNC void fmt::internal::format_system_error(
|
||||
fmt::Writer &out, int error_code,
|
||||
fmt::StringRef message) FMT_NOEXCEPT {
|
||||
FMT_TRY {
|
||||
MemoryBuffer<char, INLINE_BUFFER_SIZE> buffer;
|
||||
buffer.resize(INLINE_BUFFER_SIZE);
|
||||
for (;;) {
|
||||
char *system_message = &buffer[0];
|
||||
int result = safe_strerror(error_code, system_message, buffer.size());
|
||||
if (result == 0) {
|
||||
out << message << ": " << system_message;
|
||||
return;
|
||||
}
|
||||
if (result != ERANGE)
|
||||
break; // Can't get error message, report error code instead.
|
||||
buffer.resize(buffer.size() * 2);
|
||||
}
|
||||
} FMT_CATCH(...) {}
|
||||
format_error_code(out, error_code, message);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
FMT_FUNC void fmt::internal::format_windows_error(
|
||||
fmt::Writer &out, int error_code,
|
||||
fmt::StringRef message) FMT_NOEXCEPT {
|
||||
@ -583,7 +560,29 @@ FMT_FUNC void fmt::internal::format_windows_error(
|
||||
} FMT_CATCH(...) {}
|
||||
format_error_code(out, error_code, message);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // FMT_USE_WINDOWS_H
|
||||
|
||||
FMT_FUNC void fmt::internal::format_system_error(
|
||||
fmt::Writer &out, int error_code,
|
||||
fmt::StringRef message) FMT_NOEXCEPT {
|
||||
FMT_TRY {
|
||||
MemoryBuffer<char, INLINE_BUFFER_SIZE> buffer;
|
||||
buffer.resize(INLINE_BUFFER_SIZE);
|
||||
for (;;) {
|
||||
char *system_message = &buffer[0];
|
||||
int result = safe_strerror(error_code, system_message, buffer.size());
|
||||
if (result == 0) {
|
||||
out << message << ": " << system_message;
|
||||
return;
|
||||
}
|
||||
if (result != ERANGE)
|
||||
break; // Can't get error message, report error code instead.
|
||||
buffer.resize(buffer.size() * 2);
|
||||
}
|
||||
} FMT_CATCH(...) {}
|
||||
format_error_code(out, error_code, message);
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
void fmt::internal::ArgMap<Char>::init(const ArgList &args) {
|
||||
@ -1251,7 +1250,7 @@ FMT_FUNC void fmt::report_system_error(
|
||||
report_error(internal::format_system_error, error_code, message);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#if FMT_USE_WINDOWS_H
|
||||
FMT_FUNC void fmt::report_windows_error(
|
||||
int error_code, fmt::StringRef message) FMT_NOEXCEPT {
|
||||
report_error(internal::format_windows_error, error_code, message);
|
||||
|
20
format.h
20
format.h
@ -682,7 +682,15 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
|
||||
buffer[0] = Data::DIGITS[index];
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef _WIN32
|
||||
# define FMT_USE_WINDOWS_H 0
|
||||
#elif !defined(FMT_USE_WINDOWS_H)
|
||||
# define FMT_USE_WINDOWS_H 1
|
||||
#endif
|
||||
|
||||
// Define FMT_USE_WINDOWS_H to 0 to disable use of windows.h.
|
||||
// All the functionality that relies on it will be disabled too.
|
||||
#if FMT_USE_WINDOWS_H
|
||||
// A converter from UTF-8 to UTF-16.
|
||||
// It is only provided for Windows since other systems support UTF-8 natively.
|
||||
class UTF8ToUTF16 {
|
||||
@ -716,16 +724,14 @@ class UTF16ToUTF8 {
|
||||
// in case of memory allocation error.
|
||||
int convert(WStringRef s);
|
||||
};
|
||||
|
||||
void format_windows_error(fmt::Writer &out, int error_code,
|
||||
fmt::StringRef message) FMT_NOEXCEPT;
|
||||
#endif
|
||||
|
||||
void format_system_error(fmt::Writer &out, int error_code,
|
||||
fmt::StringRef message) FMT_NOEXCEPT;
|
||||
|
||||
#ifdef _WIN32
|
||||
void format_windows_error(fmt::Writer &out, int error_code,
|
||||
fmt::StringRef message) FMT_NOEXCEPT;
|
||||
#endif
|
||||
|
||||
// A formatting argument value.
|
||||
struct Value {
|
||||
template <typename Char>
|
||||
@ -2486,7 +2492,7 @@ void format(BasicFormatter<Char> &f, const Char *&format_str, const T &value) {
|
||||
// Can be used to report errors from destructors.
|
||||
void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT;
|
||||
|
||||
#ifdef _WIN32
|
||||
#if FMT_USE_WINDOWS_H
|
||||
|
||||
/** A Windows error. */
|
||||
class WindowsError : public SystemError {
|
||||
|
@ -89,4 +89,9 @@ if (FMT_PEDANTIC)
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/compile-test"
|
||||
--build-generator ${CMAKE_GENERATOR}
|
||||
--build-makeprogram ${CMAKE_MAKE_PROGRAM})
|
||||
|
||||
# Test that the library compiles without windows.h.
|
||||
add_library(no-windows-h-test ../format.cc)
|
||||
set_target_properties(no-windows-h-test
|
||||
PROPERTIES COMPILE_DEFINITIONS "FMT_USE_WINDOWS_H=0")
|
||||
endif ()
|
||||
|
Loading…
Reference in New Issue
Block a user