diff --git a/src/core/qgsfileutils.cpp b/src/core/qgsfileutils.cpp index 4bea0223a4f4..a6718d63eca2 100644 --- a/src/core/qgsfileutils.cpp +++ b/src/core/qgsfileutils.cpp @@ -30,6 +30,7 @@ // For getrlimit() #include #include +#include #endif #ifdef _MSC_VER @@ -561,10 +562,21 @@ int QgsFileUtils::openedFileLimit() int QgsFileUtils::openedFileCount() { #ifdef Q_OS_LINUX - int res = static_cast( QDir( "/proc/self/fd" ).entryList().size() ); - if ( res == 0 ) - res = -1; - return res; + int fileCount = 0; + + DIR *dirp = opendir( "/proc/self/fd" ); + if ( !dirp ) + return -1; + + while ( struct dirent *entry = readdir( dirp ) ) + { + if ( entry->d_type == DT_REG ) + { + fileCount++; + } + } + closedir( dirp ); + return fileCount; #else return -1; #endif