aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-11-24 10:31:17 +0100
committerMartin Ridgers <[email protected]>2021-11-24 15:56:26 +0100
commitdbee0fb9296d53f6f9ae6085f087781931b40f1d (patch)
tree1ee3be80841c6189da252127f4b37fa474ad7d5f /zencore/filesystem.cpp
parentMerged main (diff)
downloadzen-dbee0fb9296d53f6f9ae6085f087781931b40f1d.tar.xz
zen-dbee0fb9296d53f6f9ae6085f087781931b40f1d.zip
Added POSIX's close-on-exec flag to files that Zen opens
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index ca8d32b6b..f18d9cc0b 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -417,7 +417,7 @@ CloneFile(std::filesystem::path FromPath, std::filesystem::path ToPath)
};
// The 'from' file
- int FromFd = open(FromPath.c_str(), O_RDONLY);
+ int FromFd = open(FromPath.c_str(), O_RDONLY|O_CLOEXEC);
if (FromFd < 0)
{
return false;
@@ -425,7 +425,7 @@ CloneFile(std::filesystem::path FromPath, std::filesystem::path ToPath)
ScopedFd $From = { FromFd };
// The 'to' file
- int ToFd = open(ToPath.c_str(), O_WRONLY|O_CREAT|O_EXCL, 0666);
+ int ToFd = open(ToPath.c_str(), O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0666);
if (ToFd < 0)
{
return false;
@@ -480,7 +480,7 @@ CopyFile(std::filesystem::path FromPath, std::filesystem::path ToPath, const Cop
struct ScopedFd { ~ScopedFd() { close(Fd); } int Fd; };
// From file
- int FromFd = open(FromPath.c_str(), O_RDONLY);
+ int FromFd = open(FromPath.c_str(), O_RDONLY|O_CLOEXEC);
if (FromFd < 0)
{
ThrowLastError("failed to open file {}"_format(FromPath));
@@ -488,7 +488,7 @@ CopyFile(std::filesystem::path FromPath, std::filesystem::path ToPath, const Cop
ScopedFd $From = { FromFd };
// To file
- int ToFd = open(ToPath.c_str(), O_WRONLY|O_CREAT|O_EXCL);
+ int ToFd = open(ToPath.c_str(), O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC);
if (ToFd < 0)
{
ThrowLastError("failed to create file {}"_format(ToPath));
@@ -691,7 +691,7 @@ ScanFile(std::filesystem::path Path, const uint64_t ChunkSize, std::function<voi
ProcessFunc(ReadBuffer.data(), dwBytesRead);
}
#else
- int Fd = open(Path.c_str(), O_RDONLY);
+ int Fd = open(Path.c_str(), O_RDONLY|O_CLOEXEC);
if (Fd < 0)
{
return false;
@@ -967,7 +967,7 @@ TEST_CASE("filesystem")
Handle = CreateFileW(BinPath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
CHECK(Handle != INVALID_HANDLE_VALUE);
# else
- int Fd = open(BinPath.c_str(), O_RDONLY);
+ int Fd = open(BinPath.c_str(), O_RDONLY|O_CLOEXEC);
CHECK(Fd >= 0);
Handle = (void*)uintptr_t(Fd);
# endif