mirror of
https://github.com/fmtlib/fmt.git
synced 2026-04-30 19:09:22 +08:00
Minor cleanup
This commit is contained in:
parent
e8244777ee
commit
4968433a6a
36
src/os.cc
36
src/os.cc
@ -61,6 +61,7 @@
|
||||
|
||||
namespace {
|
||||
#ifdef _WIN32
|
||||
|
||||
// Return type of read and write functions.
|
||||
using rwresult = int;
|
||||
|
||||
@ -69,20 +70,6 @@ using rwresult = int;
|
||||
inline unsigned convert_rwcount(size_t count) {
|
||||
return count <= UINT_MAX ? static_cast<unsigned>(count) : UINT_MAX;
|
||||
}
|
||||
#elif FMT_USE_FCNTL
|
||||
// Return type of read and write functions.
|
||||
using rwresult = ssize_t;
|
||||
|
||||
inline auto convert_rwcount(size_t count) -> size_t { return count; }
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
#ifdef _WIN32
|
||||
namespace detail {
|
||||
|
||||
namespace {
|
||||
|
||||
class system_message {
|
||||
system_message(const system_message&) = delete;
|
||||
@ -111,8 +98,8 @@ class system_message {
|
||||
}
|
||||
~system_message() { LocalFree(message_); }
|
||||
explicit operator bool() const noexcept { return result_ != 0; }
|
||||
operator basic_string_view<wchar_t>() const noexcept {
|
||||
return basic_string_view<wchar_t>(message_, result_);
|
||||
operator fmt::basic_string_view<wchar_t>() const noexcept {
|
||||
return fmt::basic_string_view<wchar_t>(message_, result_);
|
||||
}
|
||||
};
|
||||
|
||||
@ -122,7 +109,7 @@ class utf8_system_category final : public std::error_category {
|
||||
std::string message(int error_code) const override {
|
||||
auto&& msg = system_message(error_code);
|
||||
if (msg) {
|
||||
auto utf8_message = to_utf8<wchar_t>();
|
||||
auto utf8_message = fmt::detail::to_utf8<wchar_t>();
|
||||
if (utf8_message.convert(msg)) {
|
||||
return utf8_message.str();
|
||||
}
|
||||
@ -131,12 +118,22 @@ class utf8_system_category final : public std::error_category {
|
||||
}
|
||||
};
|
||||
|
||||
#elif FMT_USE_FCNTL
|
||||
|
||||
// Return type of read and write functions.
|
||||
using rwresult = ssize_t;
|
||||
|
||||
inline auto convert_rwcount(size_t count) -> size_t { return count; }
|
||||
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
} // namespace detail
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
FMT_API const std::error_category& system_category() noexcept {
|
||||
static const detail::utf8_system_category category;
|
||||
static const utf8_system_category category;
|
||||
return category;
|
||||
}
|
||||
|
||||
@ -166,6 +163,7 @@ void detail::format_windows_error(detail::buffer<char>& out, int error_code,
|
||||
void report_windows_error(int error_code, const char* message) noexcept {
|
||||
do_report_error(detail::format_windows_error, error_code, message);
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
buffered_file::~buffered_file() noexcept {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user