Add optional bool *ok parameter to read_sysfs(), allowing the caller to
determine if the function returned 0 because the sysfs attribute
actually had value 0 or if the sysfs attribute didn't exist at all.

This is used by a following commit.

Signed-off-by: Anssi Hannula <[email protected]>
---
 lib.cpp |    9 +++++++--
 lib.h   |    2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib.cpp b/lib.cpp
index 3c411c9..391d0ab 100644
--- a/lib.cpp
+++ b/lib.cpp
@@ -173,16 +173,21 @@ void write_sysfs(const string &filename, const string 
&value)
        file.close();
 }
 
-int read_sysfs(const string &filename)
+int read_sysfs(const string &filename, bool *ok)
 {
        ifstream file;
        int i;
 
        file.open(filename.c_str(), ios::in);
-       if (!file)
+       if (!file) {
+               if (ok)
+                       *ok = false;
                return 0;
+       }
        file >> i;
        file.close();
+       if (ok)
+               *ok = true;
        return i;
 }
 
diff --git a/lib.h b/lib.h
index 0a62163..bd35aaf 100644
--- a/lib.h
+++ b/lib.h
@@ -57,7 +57,7 @@ public:
 using namespace std;
 
 extern void write_sysfs(const string &filename, const string &value);
-extern int read_sysfs(const string &filename);
+extern int read_sysfs(const string &filename, bool *ok = NULL);
 extern string read_sysfs_string(const string &filename);
 extern string read_sysfs_string(const char *format, const char *param);
 
-- 
1.7.7.2

_______________________________________________
Power mailing list
[email protected]
https://bughost.org/mailman/listinfo/power

Reply via email to