replace deprecated readdir_r to readdir 46/107146/2 accepted/tizen_5.0_unified accepted/tizen_common accepted/tizen_ivi accepted/tizen_mobile accepted/tizen_wearable tizen_5.0 accepted/tizen/4.0/unified/20170816.012258 accepted/tizen/4.0/unified/20170828.222713 accepted/tizen/5.0/unified/20181102.025854 accepted/tizen/common/20161227.192619 accepted/tizen/ivi/20161228.083430 accepted/tizen/mobile/20161228.083423 accepted/tizen/unified/20170309.040102 accepted/tizen/wearable/20161228.083427 submit/tizen/20161227.105527 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170828.100006 submit/tizen_5.0/20181101.000007 submit/tizen_unified/20170308.100414 tizen_4.0.IoT.p1_release tizen_4.0.IoT.p2_release tizen_4.0.m1_release tizen_4.0.m2_release
authorJeesun Kim <iamjs.kim@samsung.com>
Tue, 27 Dec 2016 02:23:31 +0000 (11:23 +0900)
committerJeesun Kim <iamjs.kim@samsung.com>
Tue, 27 Dec 2016 10:17:54 +0000 (19:17 +0900)
Change-Id: I823e34ddbbc8618dba82c761d037104b5589d907

tools/cpp/src/cpp-build/generate_geocoding_data.cc

index 693c30b..22ae38e 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "cpp-build/generate_geocoding_data.h"
 
+#include <errno.h>
 #include <dirent.h>
 #include <locale>
 #include <sys/stat.h>
@@ -101,20 +102,14 @@ bool ListDirectory(const string& path, vector<DirEntry>* entries) {
     return false;
   }
   AutoCloser<DIR> 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<DirEntry>* 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.