#include "cpp-build/generate_geocoding_data.h"
+#include <errno.h>
#include <dirent.h>
#include <locale>
#include <sys/stat.h>
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;
}
} 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.
std::stringstream stream;
stream << s;
stream >> *n;
- return stream;
+ return true;
}
// Converts integer to string, returns true on success.
std::stringstream stream;
stream << n;
stream >> *s;
- return stream;
+ return true;
}
// Parses the prefix descriptions file at path, clears and fills the output
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.
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");
}