From f5fd27fbd61df3477171517d7086a0050b8319c3 Mon Sep 17 00:00:00 2001 From: Anssi Hannula Date: Wed, 30 Nov 2011 16:45:03 +0200 Subject: [PATCH 1/5] lib: add 'ok' output parameter to read_sysfs() 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 --- 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