Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 1 | #ifndef __SYSFS_H |
| 2 | #define __SYSFS_H |
| 3 | |
| 4 | #include <fstream> |
| 5 | #include <string> |
| 6 | |
| 7 | template <typename T> |
| 8 | void read_sysfs(const std::string& path, T& val) |
| 9 | { |
| 10 | std::ifstream s(path); |
| 11 | s >> val; |
| 12 | } |
| 13 | |
| 14 | template <typename T> |
| 15 | void write_sysfs(const std::string& path, const T& val) |
| 16 | { |
| 17 | std::ofstream s(path); |
| 18 | s << val; |
| 19 | } |
| 20 | |
| 21 | const std::string make_sysfs_path(const std::string& path, |
| 22 | const std::string& type, |
| 23 | const std::string& id, |
| 24 | const std::string& entry) |
| 25 | { |
| 26 | using namespace std::literals; |
| 27 | |
| 28 | return path + "/"s + type + id + "_"s + entry; |
| 29 | } |
| 30 | |
| 31 | #endif |
Brad Bishop | 03476f1 | 2016-12-19 13:09:12 -0500 | [diff] [blame^] | 32 | |
| 33 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |