summaryrefslogtreecommitdiff
path: root/src/Device
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 /src/Device
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 'src/Device')
-rw-r--r--src/Device/Device.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp
index b806f06..21ad9e8 100644
--- a/src/Device/Device.cpp
+++ b/src/Device/Device.cpp
@@ -48,16 +48,13 @@ void Device::getSystemTreeJson(const char * dir_name) {
exitHandler(99);
}
while (1) {
- struct dirent * entry;
- const char * d_name;
- entry = readdir (d); // Gets subsequent entries from "d"
- if (!entry) { // If there are no more entries, exit
+ struct dirent * entry = readdir (d); // Gets subsequent entries from "d"
+ if (!entry) { // If there are no more entries, exit
break;
}
- d_name = entry->d_name; // Get file name
- if (!(entry->d_type & DT_DIR)) {
- std::string fileData;
- MTS::System::readFile(fullPath + "/" + std::string(d_name), fileData);
+ const char * d_name = entry->d_name; // Get file name
+ std::string fileData;
+ if (!(entry->d_type & DT_DIR) && (MTS::System::readFile(fullPath + "/" + std::string(d_name), fileData) == 0)) {
fileData = MTS::Text::trim(fileData);
if (strlen(dir_name) > 0) {
if (std::binary_search(apIdentifiers.begin(), apIdentifiers.end(), dir_name) && !regex_match(d_name, apFilters)) {