diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-01-05 20:50:49 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-01-17 20:26:10 -0500 |
commit | ab795a1de48e6a37d86732778effe9e7424461d2 (patch) | |
tree | 4973e7885eec1797f8f017b877a10a475b8fe717 | |
parent | ca08512b45ba90cbba007900a1fb584107371a7f (diff) | |
download | phosphor-hwmon-ab795a1de48e6a37d86732778effe9e7424461d2.tar.gz phosphor-hwmon-ab795a1de48e6a37d86732778effe9e7424461d2.zip |
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>
-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 |