From 396c5dd3af39a45bf0e9edb37b9754f040de808d Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Sat, 22 Jul 2017 19:44:44 -0700 Subject: [PATCH] remove use of deprecated function readdir_r Ports 140b8ace onto RC_1_1 branch --- examples/client_test.cpp | 9 +++------ include/libtorrent/file.hpp | 7 ++----- src/file.cpp | 22 ++++++++++------------ 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index bb486806f..db53a4524 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -762,13 +762,10 @@ std::vector list_dir(std::string path return ret; } - struct dirent de; - dirent* dummy; - while (readdir_r(handle, &de, &dummy) == 0) + struct dirent* de; + while ((de = readdir(handle))) { - if (dummy == 0) break; - - std::string p = de.d_name; + std::string p = de->d_name; if (filter_fun(p)) ret.push_back(p); } diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index e597ce1c6..486d4f6ca 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -193,11 +193,8 @@ namespace libtorrent #endif #else DIR* m_handle; - // the dirent struct contains a zero-sized - // array at the end, it will end up referring - // to the m_name field - struct dirent m_dirent; - char m_name[TORRENT_MAX_PATH + 1]; // +1 to make room for null + ino_t m_inode; + std::string m_name; #endif bool m_done; }; diff --git a/src/file.cpp b/src/file.cpp index 0db8f56eb..1b3a88150 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1185,9 +1185,6 @@ namespace libtorrent } #else - memset(&m_dirent, 0, sizeof(dirent)); - m_name[0] = 0; - // the path passed to opendir() may not // end with a / std::string p = path; @@ -1219,11 +1216,7 @@ namespace libtorrent boost::uint64_t directory::inode() const { -#ifdef TORRENT_WINDOWS return m_inode; -#else - return m_dirent.d_ino; -#endif } std::string directory::file() const @@ -1235,7 +1228,7 @@ namespace libtorrent return convert_from_native(m_fd.cFileName); #endif #else - return convert_from_native(m_dirent.d_name); + return convert_from_native(m_name); #endif } @@ -1257,13 +1250,18 @@ namespace libtorrent } ++m_inode; #else - dirent* dummy; - if (readdir_r(m_handle, &m_dirent, &dummy) != 0) + struct dirent* de; + errno = 0; + if ((de = ::readdir(m_handle))) { - ec.assign(errno, system_category()); + m_inode = de->d_ino; + m_name = de->d_name; + } + else + { + if (errno) ec.assign(errno, system_category()); m_done = true; } - if (dummy == 0) m_done = true; #endif }