mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-25 06:59:11 +08:00
Merge pull request #2305 from nUl1/fix-fopens
Fix fopen_s error reporting with PREVENT_CHILD_FD
This commit is contained in:
commit
b1478d98f0
@ -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));
|
const int fd = ::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644));
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
*fp = ::fdopen(fd, mode.c_str());
|
*fp = ::fdopen(fd, mode.c_str());
|
||||||
if (*fp == nullptr)
|
if (*fp == nullptr)
|
||||||
|
@ -154,3 +154,15 @@ TEST_CASE("file_event_handlers", "[file_helper]")
|
|||||||
REQUIRE(events == std::vector<flags>{flags::before_close, flags::after_close});
|
REQUIRE(events == std::vector<flags>{flags::before_close, flags::after_close});
|
||||||
REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n");
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user