#At file:///home/msvensson/mysql/6.4/
3021 Magnus Svensson 2008-10-28
WL#4350 Make DirIterator work also on systems that does not have dirent.d_type
modified:
storage/ndb/src/mgmsrv/DirIterator.cpp
=== modified file 'storage/ndb/src/mgmsrv/DirIterator.cpp'
--- a/storage/ndb/src/mgmsrv/DirIterator.cpp 2008-10-24 12:41:10 +0000
+++ b/storage/ndb/src/mgmsrv/DirIterator.cpp 2008-10-28 13:50:47 +0000
@@ -20,9 +20,30 @@
#include <dirent.h>
+#ifndef _DIRENT_HAVE_D_TYPE
+#include <sys/stat.h>
+#endif
+
class DirIteratorImpl {
DIR* m_dirp;
+ bool is_regular_file(struct dirent* dp) const {
+#ifdef _DIRENT_HAVE_D_TYPE
+ /*
+ Using dirent's d_type field to determine if
+ it's a regular file
+ */
+ return (dp->d_type == DT_REG);
+#else
+ /* Using stat to read more info about the file */
+ struct stat buf;
+ if (stat(dp->d_name, &buf))
+ return false; // 'stat' failed
+
+ return S_ISREG(buf.st_mode);
+#endif
+ }
+
public:
DirIteratorImpl():
m_dirp(NULL) {};
@@ -41,7 +62,7 @@ public:
const char* next_file(void){
struct dirent* dp;
while ((dp = readdir(m_dirp)) != NULL &&
- dp->d_type != DT_REG)
+ !is_regular_file(dp))
;
return dp ? dp->d_name : NULL;
}
| Thread |
|---|
| • bzr commit into mysql-5.1 branch (msvensson:3021) WL#4350 | Magnus Svensson | 28 Oct |