SparseExtra: Read MatrixMarketIterator folders with readdir64 on glibc libeigen/eigen!3667 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
diff --git a/contrib/Eigen/src/SparseExtra/MatrixMarketIterator.h b/contrib/Eigen/src/SparseExtra/MatrixMarketIterator.h index a936e97..38e07f6 100644 --- a/contrib/Eigen/src/SparseExtra/MatrixMarketIterator.h +++ b/contrib/Eigen/src/SparseExtra/MatrixMarketIterator.h
@@ -174,10 +174,20 @@ return false; } + // With a 32-bit off_t, glibc's readdir() fails with EOVERFLOW on an inode number or a directory offset above 32 bits, + // which a 64-bit kernel hands out for ext4 and XFS, and the folder then looks empty. readdir64() has no such limit. +#if defined(__GLIBC__) && defined(__USE_LARGEFILE64) + using DirEntry = struct dirent64; + static DirEntry* ReadDir(DIR* dir) { return readdir64(dir); } +#else + using DirEntry = struct dirent; + static DirEntry* ReadDir(DIR* dir) { return readdir(dir); } +#endif + void Getnextvalidmatrix() { m_isvalid = false; // Here, we return with the next valid matrix in the folder - while ((m_curs_id = readdir(m_folder_id)) != nullptr) { + while ((m_curs_id = ReadDir(m_folder_id)) != nullptr) { m_isvalid = false; std::string curfile; curfile = m_folder + "/" + m_curs_id->d_name; @@ -222,7 +232,7 @@ bool m_hasrefX; // A reference solution is provided std::string m_folder; DIR* m_folder_id; - struct dirent* m_curs_id; + DirEntry* m_curs_id; }; } // end namespace Eigen