From: kibak.yoon Date: Fri, 8 Sep 2017 08:02:52 +0000 (+0900) Subject: sensor: hal: tm1: change readdir_r to readdir X-Git-Tag: submit/tizen_4.0/20170908.103818^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=abe3a8255ec8f34eedfa17497ae9053ed90ff01e;p=platform%2Fadaptation%2Ftm1%2Fsensor-hal-tm1.git sensor: hal: tm1: 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: I48fd42a49d68d94b1baa4591df32958f28227363 Signed-off-by: kibak.yoon --- diff --git a/src/util.cpp b/src/util.cpp index 345b8b4..e725c3a 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,9 +149,7 @@ 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) { @@ -167,23 +157,15 @@ static bool get_input_method(const string &key, int &method, string &device_num) 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; diff --git a/src/util.h b/src/util.h index d799b22..2f9daab 100644 --- a/src/util.h +++ b/src/util.h @@ -15,8 +15,8 @@ * */ -#ifndef _SENSOR_UTIL_H_ -#define _SENSOR_UTIL_H_ +#ifndef __SENSOR_UTIL_H__ +#define __SENSOR_UTIL_H__ #include #include @@ -64,4 +64,5 @@ namespace util { bool set_node_value(const std::string &node_path, int value); bool set_node_value(const std::string &node_path, unsigned long long value); } -#endif /*_SENSOR_UTIL_H_*/ + +#endif /* __SENSOR_UTIL_H__ */