#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.