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