blob: 5b05dbf66fcaa50dc322a4cf02007a9a66733df3 [file] [log] [blame]
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Wed, 18 May 2022 10:21:49 -0700
Subject: [PATCH 1/2] Don't throw on write failure
---
include/fmt/format-inl.h | 4 +---
include/fmt/xchar.h | 3 +--
src/os.cc | 4 +---
3 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h
index dac2d437a41ab7b0b4e72895212b5a972ada73a9..af6ba74d618f29c77339e8a82906cccd26a2efa4 100644
--- a/include/fmt/format-inl.h
+++ b/include/fmt/format-inl.h
@@ -75,9 +75,7 @@ FMT_FUNC void report_error(format_func func, int error_code,
// A wrapper around fwrite that throws on error.
inline void fwrite_fully(const void* ptr, size_t size, size_t count,
FILE* stream) {
- size_t written = std::fwrite(ptr, size, count, stream);
- if (written < count)
- FMT_THROW(system_error(errno, FMT_STRING("cannot write to file")));
+ std::fwrite(ptr, size, count, stream);
}
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h
index 625ec36922e9bcc44a76b3c40792cb08ede63813..0f79c1720a4c855bb7088381e93af08eae56d66c 100644
--- a/include/fmt/xchar.h
+++ b/include/fmt/xchar.h
@@ -220,8 +220,7 @@ inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) {
auto buf = wmemory_buffer();
detail::vformat_to(buf, fmt, args);
buf.push_back(L'\0');
- if (std::fputws(buf.data(), f) == -1)
- FMT_THROW(system_error(errno, FMT_STRING("cannot write to file")));
+ std::fputws(buf.data(), f);
}
inline void vprint(wstring_view fmt, wformat_args args) {
diff --git a/src/os.cc b/src/os.cc
index bca410e945e0347d349e06179906a43b38b56a5c..d7ded50f9870a885d1ce1835fecc4f740858127a 100644
--- a/src/os.cc
+++ b/src/os.cc
@@ -258,9 +258,7 @@ long long file::size() const {
std::size_t file::read(void* buffer, std::size_t count) {
rwresult result = 0;
FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count))));
- if (result < 0)
- FMT_THROW(system_error(errno, FMT_STRING("cannot read from file")));
- return detail::to_unsigned(result);
+ return count;
}
std::size_t file::write(const void* buffer, std::size_t count) {