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;
}
struct dirent de;
dirent* dummy;
while (readdir_r(handle, &de, &dummy) == 0)
struct dirent* de;
while ((de = readdir(handle)))
{
if (dummy == nullptr) break;
lt::string_view p(de.d_name);
lt::string_view p(de->d_name);
if (filter_fun(p))
ret.push_back(p.to_string());
}

View File

@ -109,11 +109,8 @@ namespace libtorrent {
WIN32_FIND_DATAW m_fd;
#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 terminating 0
ino_t m_inode;
std::string m_name;
#endif
bool m_done;
};

View File

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