From 73feb7426777af256bb7c8b04e408b4676d024a2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 12 Sep 2017 12:22:00 +0900 Subject: [PATCH] sensor: hal: emul: change readdir_r to readdir - it should be changed because readdir_r() is deprecated function - there is no thread issue because it guarantees that it runs in one thread. Change-Id: Ie5a7694936c6d1f8093e8cd5513dfb236c173ea7 Signed-off-by: kibak.yoon --- src/util.cpp | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 86d572d..a75ff25 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -15,15 +15,17 @@ * */ +#include + #include #include #include #include #include -#include -#include #include +#include "sensor_log.h" + using std::ifstream; using std::ofstream; using std::fstream; @@ -35,30 +37,20 @@ static bool get_event_num(const string &input_path, string &event_num) { const string event_prefix = PREFIX_EVENT; DIR *dir = NULL; - struct dirent dir_entry; - struct dirent *result = NULL; + struct dirent *entry; std::string node_name; - int error; bool find = false; dir = opendir(input_path.c_str()); - if (!dir) { - ERR("Failed to open dir: %s", input_path.c_str()); - return false; - } + retvm_if(!dir, false, "Failed to open directory[%s]", input_path.c_str()); int prefix_size = event_prefix.size(); while (true) { - error = readdir_r(dir, &dir_entry, &result); - - if (error != 0) - continue; - - if (result == NULL) - break; + entry = readdir(dir); + if (!entry) break; - node_name = std::string(dir_entry.d_name); + node_name = std::string(entry->d_name); if (node_name.compare(0, prefix_size, event_prefix) != 0) continue; @@ -157,32 +149,22 @@ static bool get_input_method(const string &key, int &method, string &device_num) std::string name_node, name; std::string d_name; DIR *dir = NULL; - struct dirent dir_entry; - struct dirent *result = NULL; - int error; + struct dirent *entry; bool find = false; for (int i = 0; i < input_info_len; ++i) { prefix_size = input_info[i].prefix.size(); dir = opendir(input_info[i].dir_path.c_str()); - if (!dir) { - ERR("Failed to open dir: %s", input_info[i].dir_path.c_str()); - return false; - } + retvm_if(!dir, false, "Failed to open directory[%s]", input_info[i].dir_path.c_str()); find = false; while (true) { - error = readdir_r(dir, &dir_entry, &result); - - if (error != 0) - continue; - - if (result == NULL) - break; + entry = readdir(dir); + if (!entry) break; - d_name = std::string(dir_entry.d_name); + d_name = std::string(entry->d_name); if (d_name.compare(0, prefix_size, input_info[i].prefix) != 0) continue; -- 2.7.4