mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-01 03:34:45 +02:00
Replace fmt::error_code to std::error_code
This commit is contained in:
committed by
Victor Zverovich
parent
2165bef4ca
commit
2a9b314627
@@ -118,17 +118,6 @@ template <typename Char> class basic_cstring_view {
|
|||||||
using cstring_view = basic_cstring_view<char>;
|
using cstring_view = basic_cstring_view<char>;
|
||||||
using wcstring_view = basic_cstring_view<wchar_t>;
|
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 Char> struct formatter<std::error_code, Char> {
|
||||||
template <typename ParseContext>
|
template <typename ParseContext>
|
||||||
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
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
|
// Makes fd be the copy of this file descriptor, closing fd first if
|
||||||
// necessary.
|
// 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
|
// Creates a pipe setting up read_end and write_end file objects for reading
|
||||||
// and writing respectively.
|
// 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;
|
int result = 0;
|
||||||
FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd)));
|
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) {
|
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
|
#if FMT_USE_FCNTL
|
||||||
|
|
||||||
using fmt::buffered_file;
|
using fmt::buffered_file;
|
||||||
using fmt::error_code;
|
|
||||||
using fmt::file;
|
using fmt::file;
|
||||||
|
|
||||||
TEST(output_redirect_test, scoped_redirect) {
|
TEST(output_redirect_test, scoped_redirect) {
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
using fmt::buffered_file;
|
using fmt::buffered_file;
|
||||||
using fmt::error_code;
|
|
||||||
using testing::HasSubstr;
|
using testing::HasSubstr;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -69,11 +68,6 @@ TEST(util_test, utf16_to_utf8_convert) {
|
|||||||
u.convert(fmt::wstring_view(L"foo", INT_MAX + 1u)));
|
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) {
|
TEST(os_test, format_std_error_code) {
|
||||||
EXPECT_EQ("generic:42",
|
EXPECT_EQ("generic:42",
|
||||||
fmt::format(FMT_STRING("{0}"),
|
fmt::format(FMT_STRING("{0}"),
|
||||||
@@ -527,18 +521,18 @@ TEST(file_test, dup2_error) {
|
|||||||
TEST(file_test, dup2_noexcept) {
|
TEST(file_test, dup2_noexcept) {
|
||||||
file f = open_file();
|
file f = open_file();
|
||||||
file copy = open_file();
|
file copy = open_file();
|
||||||
error_code ec;
|
std::error_code ec;
|
||||||
f.dup2(copy.descriptor(), ec);
|
f.dup2(copy.descriptor(), ec);
|
||||||
EXPECT_EQ(ec.get(), 0);
|
EXPECT_EQ(ec.value(), 0);
|
||||||
EXPECT_NE(f.descriptor(), copy.descriptor());
|
EXPECT_NE(f.descriptor(), copy.descriptor());
|
||||||
EXPECT_READ(copy, file_content);
|
EXPECT_READ(copy, file_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(file_test, dup2_noexcept_error) {
|
TEST(file_test, dup2_noexcept_error) {
|
||||||
file f = open_file();
|
file f = open_file();
|
||||||
error_code ec;
|
std::error_code ec;
|
||||||
SUPPRESS_ASSERT(f.dup2(-1, ec));
|
SUPPRESS_ASSERT(f.dup2(-1, ec));
|
||||||
EXPECT_EQ(EBADF, ec.get());
|
EXPECT_EQ(EBADF, ec.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(file_test, pipe) {
|
TEST(file_test, pipe) {
|
||||||
|
@@ -30,7 +30,6 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using fmt::buffered_file;
|
using fmt::buffered_file;
|
||||||
using fmt::error_code;
|
|
||||||
|
|
||||||
using testing::_;
|
using testing::_;
|
||||||
using testing::Return;
|
using testing::Return;
|
||||||
@@ -367,13 +366,13 @@ TEST(file_test, dup2_retry) {
|
|||||||
TEST(file_test, dup2_no_except_retry) {
|
TEST(file_test, dup2_no_except_retry) {
|
||||||
int stdout_fd = FMT_POSIX(fileno(stdout));
|
int stdout_fd = FMT_POSIX(fileno(stdout));
|
||||||
file f1 = file::dup(stdout_fd), f2 = file::dup(stdout_fd);
|
file f1 = file::dup(stdout_fd), f2 = file::dup(stdout_fd);
|
||||||
error_code ec;
|
std::error_code ec;
|
||||||
dup2_count = 1;
|
dup2_count = 1;
|
||||||
f1.dup2(f2.descriptor(), ec);
|
f1.dup2(f2.descriptor(), ec);
|
||||||
# ifndef _WIN32
|
# ifndef _WIN32
|
||||||
EXPECT_EQ(4, dup2_count);
|
EXPECT_EQ(4, dup2_count);
|
||||||
# else
|
# else
|
||||||
EXPECT_EQ(EINTR, ec.get());
|
EXPECT_EQ(EINTR, ec.value());
|
||||||
# endif
|
# endif
|
||||||
dup2_count = 0;
|
dup2_count = 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user