diff --git a/FAQ.md b/FAQ.md index 7c999f22f..04871ba7d 100644 --- a/FAQ.md +++ b/FAQ.md @@ -490,8 +490,6 @@ group](https://groups.google.com/group/libphonenumber-discuss): * PR [#1090](https://github.com/googlei18n/libphonenumber/pull/1090) / [#824](https://github.com/googlei18n/libphonenumber/issues/824) to "Replace POSIX directory operations by Boost Filesystem" -* [#1307](https://github.com/googlei18n/libphonenumber/issues/1307) to use - readdir instead of readdir_r * [#1555](https://github.com/googlei18n/libphonenumber/issues/1555) to allow Windows to build cpp library with pthreads for multi-threading diff --git a/pending_code_changes.txt b/pending_code_changes.txt index 8b1378917..412f1bd82 100644 --- a/pending_code_changes.txt +++ b/pending_code_changes.txt @@ -1 +1,2 @@ - +Build changes: + - C++ geocoding build tools now use readdir, since readdir_r is deprecated. diff --git a/tools/cpp/src/cpp-build/generate_geocoding_data.cc b/tools/cpp/src/cpp-build/generate_geocoding_data.cc index 823b7d4e5..021cf5c81 100644 --- a/tools/cpp/src/cpp-build/generate_geocoding_data.cc +++ b/tools/cpp/src/cpp-build/generate_geocoding_data.cc @@ -17,6 +17,7 @@ #include "cpp-build/generate_geocoding_data.h" #include +#include #include #include #include @@ -102,20 +103,24 @@ 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; + // Set errno to 0 to be able to check if an error occurs during the + // readdir() call. NULL is the return value when the end of the directory + // stream is reached or when an error occurs, and the errno check is the + // only thing that helps us distinguish between the two cases. See + // documentation at + // http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html + errno = 0; + entry = readdir(dir); + if (entry == NULL) { + return errno == 0; } - if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0) { + 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; } @@ -125,7 +130,7 @@ 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)); } }