diff options
-rw-r--r-- | mainloop.cpp | 12 | ||||
-rw-r--r-- | util.hpp | 22 |
2 files changed, 25 insertions, 9 deletions
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 @@ void MainLoop::run() } { - 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 |