remove use of deprecated function readdir_r

This commit is contained in:
Steven Siloti 2017-07-22 19:44:44 -07:00 committed by Arvid Norberg
parent c4eb4c8b5f
commit 140b8ace8d
3 changed files with 15 additions and 23 deletions

View File

@ -682,13 +682,10 @@ std::vector<std::string> list_dir(std::string path
return ret; return ret;
} }
struct dirent de; struct dirent* de;
dirent* dummy; while ((de = readdir(handle)))
while (readdir_r(handle, &de, &dummy) == 0)
{ {
if (dummy == nullptr) break; lt::string_view p(de->d_name);
lt::string_view p(de.d_name);
if (filter_fun(p)) if (filter_fun(p))
ret.push_back(p.to_string()); ret.push_back(p.to_string());
} }

View File

@ -109,11 +109,8 @@ namespace libtorrent {
WIN32_FIND_DATAW m_fd; WIN32_FIND_DATAW m_fd;
#else #else
DIR* m_handle; DIR* m_handle;
// the dirent struct contains a zero-sized ino_t m_inode;
// array at the end, it will end up referring std::string m_name;
// to the m_name field
struct dirent m_dirent;
char m_name[TORRENT_MAX_PATH + 1]; // +1 to make room for terminating 0
#endif #endif
bool m_done; bool m_done;
}; };

View File

@ -363,9 +363,6 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
} }
#else #else
std::memset(&m_dirent, 0, sizeof(dirent));
m_name[0] = 0;
m_handle = ::opendir(f.c_str()); m_handle = ::opendir(f.c_str());
if (m_handle == nullptr) if (m_handle == nullptr)
{ {
@ -390,11 +387,7 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
std::uint64_t directory::inode() const std::uint64_t directory::inode() const
{ {
#ifdef TORRENT_WINDOWS
return m_inode; return m_inode;
#else
return m_dirent.d_ino;
#endif
} }
std::string directory::file() const std::string directory::file() const
@ -402,7 +395,7 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
return convert_from_native_path(m_fd.cFileName); return convert_from_native_path(m_fd.cFileName);
#else #else
return convert_from_native(m_dirent.d_name); return convert_from_native(m_name);
#endif #endif
} }
@ -419,13 +412,18 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
} }
++m_inode; ++m_inode;
#else #else
dirent* dummy; struct dirent* de;
if (readdir_r(m_handle, &m_dirent, &dummy) != 0) 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; m_done = true;
} }
if (dummy == nullptr) m_done = true;
#endif #endif
} }