summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-01-08 13:09:53 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-01-08 13:09:53 -0600
commitafd71988ef74e331a0ac24c53f85175aee082a43 (patch)
tree6d03373a184fb0159c98768f8e6572b4383a51f8 /include
parentc4811dd1b73b37b0916803097237acd31f1df98b (diff)
downloadmts-io-sysfs-afd71988ef74e331a0ac24c53f85175aee082a43.tar.gz
mts-io-sysfs-afd71988ef74e331a0ac24c53f85175aee082a43.tar.bz2
mts-io-sysfs-afd71988ef74e331a0ac24c53f85175aee082a43.zip
Added error checking file read and stat
Diffstat (limited to 'include')
-rw-r--r--include/Utility/Utility.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/include/Utility/Utility.h b/include/Utility/Utility.h
index 062e422..0c1f16c 100644
--- a/include/Utility/Utility.h
+++ b/include/Utility/Utility.h
@@ -48,9 +48,12 @@ inline void exitHandler(int code) {
}
inline mode_t fileType(std::string file) {
- struct stat buf;
- stat (file.c_str(), &buf);
- return buf.st_mode & S_IFMT;
+ struct stat buf = { .st_dev = 0 };
+ if (stat (file.c_str(), &buf) == 0) {
+ return buf.st_mode & S_IFMT;
+ } else {
+ return -1;
+ }
}
#endif /* UTILITIES_H_ */