blob: d073d77670e4318b1f8ab37865786ed4c65a1bf3 [file] [log] [blame]
Patrick Williams3667cf32015-10-20 22:39:11 -05001#ifndef __SYSFS_H
2#define __SYSFS_H
3
4#include <fstream>
5#include <string>
6
7template <typename T>
8void read_sysfs(const std::string& path, T& val)
9{
10 std::ifstream s(path);
11 s >> val;
12}
13
14template <typename T>
15void write_sysfs(const std::string& path, const T& val)
16{
17 std::ofstream s(path);
18 s << val;
19}
20
21const 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