From: Jeesun Kim Date: Tue, 27 Dec 2016 02:23:31 +0000 (+0900) Subject: replace deprecated readdir_r to readdir X-Git-Tag: accepted/tizen/4.0/unified/20170816.012258^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fupstream%2Flibphonenumber.git;a=commitdiff_plain;h=7b77dfa5183cd38a45eb1ef62337f5fcedc832cb replace deprecated readdir_r to readdir Change-Id: I823e34ddbbc8618dba82c761d037104b5589d907 --- diff --git a/tools/cpp/src/cpp-build/generate_geocoding_data.cc b/tools/cpp/src/cpp-build/generate_geocoding_data.cc index 693c30b..22ae38e 100644 --- a/tools/cpp/src/cpp-build/generate_geocoding_data.cc +++ b/tools/cpp/src/cpp-build/generate_geocoding_data.cc @@ -16,6 +16,7 @@ #include "cpp-build/generate_geocoding_data.h" +#include #include #include #include @@ -101,20 +102,14 @@ bool ListDirectory(const string& path, vector* entries) { return false; } AutoCloser dir_closer(&dir, closedir); - struct dirent entry, *dir_result; + struct dirent *entry; struct stat entry_stat; - while (true) { - const int res = readdir_r(dir, &entry, &dir_result); - if (res) { - return false; - } - if (dir_result == NULL) { - return true; - } - if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0) { + errno = 0; + while ((entry = readdir(dir))) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; } - const string entry_path = path + "/" + entry.d_name; + const string entry_path = path + "/" + entry->d_name; if (stat(entry_path.c_str(), &entry_stat)) { return false; } @@ -124,8 +119,13 @@ bool ListDirectory(const string& path, vector* entries) { } else if (!S_ISREG(entry_stat.st_mode)) { continue; } - entries->push_back(DirEntry(entry.d_name, kind)); + entries->push_back(DirEntry(entry->d_name, kind)); } + if (errno < 0) { + return false; + } + + return true; } // Returns true if s ends with suffix.