xref: /openbmc/phosphor-hwmon/sysfs.hpp (revision 03476f11)
16292aeedSMatthew Barth #ifndef __SYSFS_H
26292aeedSMatthew Barth #define __SYSFS_H
36292aeedSMatthew Barth 
46292aeedSMatthew Barth #include <fstream>
56292aeedSMatthew Barth #include <string>
66292aeedSMatthew Barth 
76292aeedSMatthew Barth template <typename T>
86292aeedSMatthew Barth void read_sysfs(const std::string& path, T& val)
96292aeedSMatthew Barth {
106292aeedSMatthew Barth     std::ifstream s(path);
116292aeedSMatthew Barth     s >> val;
126292aeedSMatthew Barth }
136292aeedSMatthew Barth 
146292aeedSMatthew Barth template <typename T>
156292aeedSMatthew Barth void write_sysfs(const std::string& path, const T& val)
166292aeedSMatthew Barth {
176292aeedSMatthew Barth     std::ofstream s(path);
186292aeedSMatthew Barth     s << val;
196292aeedSMatthew Barth }
206292aeedSMatthew Barth 
216292aeedSMatthew Barth const std::string make_sysfs_path(const std::string& path,
226292aeedSMatthew Barth                                   const std::string& type,
236292aeedSMatthew Barth                                   const std::string& id,
246292aeedSMatthew Barth                                   const std::string& entry)
256292aeedSMatthew Barth {
266292aeedSMatthew Barth     using namespace std::literals;
276292aeedSMatthew Barth 
286292aeedSMatthew Barth     return path + "/"s + type + id + "_"s + entry;
296292aeedSMatthew Barth }
306292aeedSMatthew Barth 
316292aeedSMatthew Barth #endif
32*03476f11SBrad Bishop 
33*03476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
34