summaryrefslogtreecommitdiffstats
path: root/utility.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'utility.hpp')
-rw-r--r--utility.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/utility.hpp b/utility.hpp
index b37987d..05fe60c 100644
--- a/utility.hpp
+++ b/utility.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <sdbusplus/bus.hpp>
+#include <unistd.h>
namespace phosphor
{
@@ -9,6 +10,37 @@ namespace fan
namespace util
{
+class FileDescriptor
+{
+ public:
+ FileDescriptor() = delete;
+ FileDescriptor(const FileDescriptor&) = delete;
+ FileDescriptor(FileDescriptor&&) = default;
+ FileDescriptor& operator=(const FileDescriptor&) = delete;
+ FileDescriptor& operator=(FileDescriptor&&) = default;
+
+ FileDescriptor(int fd) : fd(fd)
+ {
+ }
+
+ ~FileDescriptor()
+ {
+ if (fd != -1)
+ {
+ close(fd);
+ }
+ }
+
+ bool is_open()
+ {
+ return fd != -1;
+ }
+
+ private:
+ int fd = -1;
+
+};
+
/**
* @brief Get the inventory service name from the mapper object
*
OpenPOWER on IntegriCloud