FileDescriptor: provide fallback if F_DUPFD_CLOEXEC is undefined

This commit is contained in:
Sergey Fedorov 2025-04-01 03:25:02 +08:00
parent 7248194a2c
commit 7fb8303fe9
2 changed files with 13 additions and 1 deletions

View file

@ -1,6 +1,11 @@
#pragma once #pragma once
#include <fcntl.h> #include <fcntl.h>
#ifndef F_DUPFD_CLOEXEC
#define F_DUPFD_CLOEXEC F_DUPFD
#endif
namespace Hyprutils { namespace Hyprutils {
namespace OS { namespace OS {
class CFileDescriptor { class CFileDescriptor {

View file

@ -55,7 +55,14 @@ CFileDescriptor CFileDescriptor::duplicate(int flags) const {
if (m_fd == -1) if (m_fd == -1)
return {}; 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 { bool CFileDescriptor::isClosed() const {