mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-05-13 05:40:40 +01:00
FileDescriptor: provide fallback if F_DUPFD_CLOEXEC is undefined
This commit is contained in:
parent
7248194a2c
commit
7fb8303fe9
2 changed files with 13 additions and 1 deletions
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue