blob: 7943211ca24f216052c871466bef6adec78ad026 [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
Brad Bishop03476f12016-12-19 13:09:12 -050032
33// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4