Replace fmt::error_code to std::error_code
This commit is contained in:
parent
2165bef4ca
commit
2a9b314627
@ -118,17 +118,6 @@ template <typename Char> class basic_cstring_view {
|
||||
using cstring_view = basic_cstring_view<char>;
|
||||
using wcstring_view = basic_cstring_view<wchar_t>;
|
||||
|
||||
// An error code.
|
||||
class error_code {
|
||||
private:
|
||||
int value_;
|
||||
|
||||
public:
|
||||
explicit error_code(int value = 0) FMT_NOEXCEPT : value_(value) {}
|
||||
|
||||
int get() const FMT_NOEXCEPT { return value_; }
|
||||
};
|
||||
|
||||
template <typename Char> struct formatter<std::error_code, Char> {
|
||||
template <typename ParseContext>
|
||||
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||
@ -351,7 +340,7 @@ class file {
|
||||
|
||||
// Makes fd be the copy of this file descriptor, closing fd first if
|
||||
// necessary.
|
||||
FMT_API void dup2(int fd, error_code& ec) FMT_NOEXCEPT;
|
||||
FMT_API void dup2(int fd, std::error_code& ec) FMT_NOEXCEPT;
|
||||
|
||||
// Creates a pipe setting up read_end and write_end file objects for reading
|
||||
// and writing respectively.
|
||||
|
@ -255,10 +255,10 @@ void file::dup2(int fd) {
|
||||
}
|
||||
}
|
||||
|
||||
void file::dup2(int fd, error_code& ec) FMT_NOEXCEPT {
|
||||
void file::dup2(int fd, std::error_code& ec) FMT_NOEXCEPT {
|
||||
int result = 0;
|
||||
FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd)));
|
||||
if (result == -1) ec = error_code(errno);
|
||||
if (result == -1) ec = std::error_code(errno, std::generic_category());
|
||||
}
|
||||
|
||||
void file::pipe(file& read_end, file& write_end) {
|
||||
|
@ -311,7 +311,6 @@ TEST(gtest_extra_test, expect_system_error_streaming) {
|
||||
#if FMT_USE_FCNTL
|
||||
|
||||
using fmt::buffered_file;
|
||||
using fmt::error_code;
|
||||
using fmt::file;
|
||||
|
||||
TEST(output_redirect_test, scoped_redirect) {
|
||||
|
@ -19,7 +19,6 @@
|
||||
#endif
|
||||
|
||||
using fmt::buffered_file;
|
||||
using fmt::error_code;
|
||||
using testing::HasSubstr;
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -69,11 +68,6 @@ TEST(util_test, utf16_to_utf8_convert) {
|
||||
u.convert(fmt::wstring_view(L"foo", INT_MAX + 1u)));
|
||||
}
|
||||
|
||||
TEST(os_test, error_code) {
|
||||
EXPECT_EQ(error_code().get(), 0);
|
||||
EXPECT_EQ(error_code(42).get(), 42);
|
||||
}
|
||||
|
||||
TEST(os_test, format_std_error_code) {
|
||||
EXPECT_EQ("generic:42",
|
||||
fmt::format(FMT_STRING("{0}"),
|
||||
@ -527,18 +521,18 @@ TEST(file_test, dup2_error) {
|
||||
TEST(file_test, dup2_noexcept) {
|
||||
file f = open_file();
|
||||
file copy = open_file();
|
||||
error_code ec;
|
||||
std::error_code ec;
|
||||
f.dup2(copy.descriptor(), ec);
|
||||
EXPECT_EQ(ec.get(), 0);
|
||||
EXPECT_EQ(ec.value(), 0);
|
||||
EXPECT_NE(f.descriptor(), copy.descriptor());
|
||||
EXPECT_READ(copy, file_content);
|
||||
}
|
||||
|
||||
TEST(file_test, dup2_noexcept_error) {
|
||||
file f = open_file();
|
||||
error_code ec;
|
||||
std::error_code ec;
|
||||
SUPPRESS_ASSERT(f.dup2(-1, ec));
|
||||
EXPECT_EQ(EBADF, ec.get());
|
||||
EXPECT_EQ(EBADF, ec.value());
|
||||
}
|
||||
|
||||
TEST(file_test, pipe) {
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "util.h"
|
||||
|
||||
using fmt::buffered_file;
|
||||
using fmt::error_code;
|
||||
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
@ -367,13 +366,13 @@ TEST(file_test, dup2_retry) {
|
||||
TEST(file_test, dup2_no_except_retry) {
|
||||
int stdout_fd = FMT_POSIX(fileno(stdout));
|
||||
file f1 = file::dup(stdout_fd), f2 = file::dup(stdout_fd);
|
||||
error_code ec;
|
||||
std::error_code ec;
|
||||
dup2_count = 1;
|
||||
f1.dup2(f2.descriptor(), ec);
|
||||
# ifndef _WIN32
|
||||
EXPECT_EQ(4, dup2_count);
|
||||
# else
|
||||
EXPECT_EQ(EINTR, ec.get());
|
||||
EXPECT_EQ(EINTR, ec.value());
|
||||
# endif
|
||||
dup2_count = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user