Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/hyprutils/os/FileDescriptor.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#pragma once

#include <fcntl.h>

#ifndef F_DUPFD_CLOEXEC
#define F_DUPFD_CLOEXEC F_DUPFD
#endif

namespace Hyprutils {
namespace OS {
class CFileDescriptor {
Expand Down
9 changes: 8 additions & 1 deletion src/os/FileDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ CFileDescriptor CFileDescriptor::duplicate(int flags) const {
if (m_fd == -1)
return {};

return CFileDescriptor{fcntl(m_fd, flags, 0)};
int new_fd;
#ifdef F_DUPFD_CLOEXEC
new_fd = fcntl(m_fd, flags, 0);
#else
new_fd = fcntl(m_fd, flags | FD_CLOEXEC, 0);
#endif

return CFileDescriptor{new_fd};
}

bool CFileDescriptor::isClosed() const {
Expand Down