Fix fopen_s error reporting with PREVENT_CHILD_FD

This commit is contained in:
Andrey Bugaevskiy 2022-03-11 19:22:45 +00:00
parent 7f8a61e79d
commit 5ee969e4f6
2 changed files with 13 additions and 1 deletions

View File

@ -145,7 +145,7 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
const int fd = ::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644));
if (fd == -1)
{
return false;
return true;
}
*fp = ::fdopen(fd, mode.c_str());
if (*fp == nullptr)

View File

@ -154,3 +154,15 @@ TEST_CASE("file_event_handlers", "[file_helper]")
REQUIRE(events == std::vector<flags>{flags::before_close, flags::after_close});
REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n");
}
TEST_CASE("file_helper_open", "[file_helper]")
{
prepare_logdir();
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
file_helper helper;
helper.open(target_filename);
helper.close();
target_filename += SPDLOG_FILENAME_T("/invalid");
REQUIRE_THROWS_AS(helper.open(target_filename), spdlog::spdlog_ex);
}