Add util.hpp

First utility is a malloc deleter for use with smart pointers.

Change-Id: I78d1723608048cc64d81891d5aa6791eaf3343e5
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/mainloop.cpp b/mainloop.cpp
index 66e48a8..dfda21f 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -23,6 +23,7 @@
 #include "hwmon.hpp"
 #include "sysfs.hpp"
 #include "mainloop.hpp"
+#include "util.hpp"
 
 using namespace std::literals::chrono_literals;
 
@@ -151,15 +152,8 @@
     }
 
     {
-        struct Free
-        {
-            void operator()(char* ptr) const
-            {
-                free(ptr);
-            }
-        };
-
-        auto copy = std::unique_ptr<char, Free>(strdup(_path.c_str()));
+        auto copy = std::unique_ptr<char, phosphor::utility::Free<char>>(strdup(
+                        _path.c_str()));
         auto busname = std::string(_prefix) + '.' + basename(copy.get());
         _bus.request_name(busname.c_str());
     }
diff --git a/util.hpp b/util.hpp
new file mode 100644
index 0000000..39749ac
--- /dev/null
+++ b/util.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <cstdlib>
+
+namespace phosphor
+{
+namespace utility
+{
+/** @struct Free
+ *  @brief A malloc cleanup type for use with smart pointers.
+ */
+template <typename T>
+struct Free
+{
+    void operator()(T* ptr) const
+    {
+        free(ptr);
+    }
+};
+} // namespace utility
+} // namespace phosphor
+// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4