hyprutils/include/hyprutils/os/FileDescriptor.hpp
Tom Englund 2e21319c8e
os: implent a new FileDescriptor class (#21)
makes you able to RAII the filedescriptor making it somewhat easier to
not leak.
2024-11-21 15:26:34 +00:00

39 lines
1.2 KiB
C++

#pragma once
#include <fcntl.h>
namespace Hyprutils {
namespace OS {
class CFileDescriptor {
public:
CFileDescriptor() = default;
explicit CFileDescriptor(int const fd);
CFileDescriptor(CFileDescriptor&&);
CFileDescriptor& operator=(CFileDescriptor&&);
~CFileDescriptor();
CFileDescriptor(const CFileDescriptor&) = delete;
CFileDescriptor& operator=(const CFileDescriptor&) = delete;
bool operator==(const CFileDescriptor& rhs) const {
return m_fd == rhs.m_fd;
}
bool isValid() const;
int get() const;
int getFlags() const;
bool setFlags(int flags);
int take();
void reset();
CFileDescriptor duplicate(int flags = F_DUPFD_CLOEXEC) const;
bool isReadable() const;
bool isClosed() const;
static bool isReadable(int fd);
static bool isClosed(int fd);
private:
int m_fd = -1;
};
};
};