replace deprecated readdir_r to readdir
[platform/upstream/libphonenumber.git] / tools / cpp / src / cpp-build / generate_geocoding_data.cc
index d02a853..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.
@@ -141,7 +141,7 @@ bool StrToInt(const string& s, int32* n) {
   std::stringstream stream;
   stream << s;
   stream >> *n;
-  return stream;
+  return true;
 }
 
 // Converts integer to string, returns true on success.
@@ -149,7 +149,7 @@ bool IntToStr(int32 n, string* s) {
   std::stringstream stream;
   stream << n;
   stream >> *s;
-  return stream;
+  return true;
 }
 
 // Parses the prefix descriptions file at path, clears and fills the output
@@ -174,14 +174,9 @@ bool ParsePrefixes(const string& path, map<int32, string>* prefixes) {
       continue;
     }
     --end;
-    if (*end != '\n') {
-      if (!feof(input)) {
-        // A line without LF can only happen at the end of file.
-        return false;
-      }
-    } else {
-      // Consume the LF.
-      --end;
+    if (*end != '\n' && !feof(input)) {
+      // A line without LF can only happen at the end of file.
+      return false;
     }
 
     // Trim and check for comments.
@@ -284,7 +279,7 @@ void WriteCppHeader(const string& base_name, FILE* output) {
   fprintf(output, "#include \"phonenumbers/geocoding/%s.h\"\n",
           base_name.c_str());
   fprintf(output, "\n");
-  fprintf(output, "#include \"base/basictypes.h\"\n");
+  fprintf(output, "#include \"phonenumbers/base/basictypes.h\"\n");
   fprintf(output, "\n");
 }