summaryrefslogtreecommitdiff
path: root/src/FileDescriptor.hpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-03-04 23:29:39 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-03-04 23:29:39 +0800
commit09d899230c3d31bd405cc3407c6c372ab9091e98 (patch)
treec6a34436ec3d1a3e99dde3b97dea820d85dc37b9 /src/FileDescriptor.hpp
parentbf95e496e2f03fcffb9c6043307f13c99a18d8d0 (diff)
refactor!: python -> c++
Diffstat (limited to 'src/FileDescriptor.hpp')
-rw-r--r--src/FileDescriptor.hpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/FileDescriptor.hpp b/src/FileDescriptor.hpp
new file mode 100644
index 0000000..59fb7e9
--- /dev/null
+++ b/src/FileDescriptor.hpp
@@ -0,0 +1,39 @@
+#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;
+};
+}; // namespace OS
+}; // namespace Hyprutils