From 17bcd4e2ab4ea5b9d407e83bb2a30e62e69f170e Mon Sep 17 00:00:00 2001 From: Frederic Bouvier Date: Mon, 19 Jul 2010 22:36:01 +0200 Subject: [PATCH 1/2] Add a new function alias for MSVC: strcasecmp -> stricmp --- simgear/compiler.h | 1 + 1 file changed, 1 insertion(+) diff --git a/simgear/compiler.h b/simgear/compiler.h index 939d9f31..e29a20e3 100644 --- a/simgear/compiler.h +++ b/simgear/compiler.h @@ -67,6 +67,7 @@ # define vsnprintf _vsnprintf # endif # define copysign _copysign +# define strcasecmp stricmp # pragma warning(disable: 4786) // identifier was truncated to '255' characters # pragma warning(disable: 4244) // conversion from double to float From 63cbd4deb0dfa95662a480b922c2c5e1cfc58c27 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 21 Jul 2010 22:08:06 +0100 Subject: [PATCH 2/2] On Unix, check for symlinks from readdir(), and look through them (using stat()) to discern target type. --- simgear/misc/sg_dir.cxx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/simgear/misc/sg_dir.cxx b/simgear/misc/sg_dir.cxx index 74b493ed..92e5af6f 100644 --- a/simgear/misc/sg_dir.cxx +++ b/simgear/misc/sg_dir.cxx @@ -29,6 +29,8 @@ # include #endif +#include + #include #include @@ -110,8 +112,26 @@ PathList Dir::children(int types, const std::string& nameFilter) const if (!(types & INCLUDE_HIDDEN) && (entry->d_name[0] == '.')) { continue; } - - if (entry->d_type == DT_DIR) { + + int type = entry->d_type; + if (type == DT_LNK) { + // find symlink target type using stat() + struct stat s; + if (stat(file(entry->d_name).c_str(), &s)) { + continue; // stat() failed + } + + if (S_ISDIR(s.st_mode)) { + type = DT_DIR; + } else if (S_ISREG(s.st_mode)) { + type = DT_REG; + } else { + // symlink to block/fifo/char file, ignore + continue; + } + } // of symlink look-through + + if (type == DT_DIR) { if (!(types & TYPE_DIR)) { continue; } @@ -121,7 +141,7 @@ PathList Dir::children(int types, const std::string& nameFilter) const continue; } } - } else if (entry->d_type == DT_REG) { + } else if (type == DT_REG) { if (!(types & TYPE_FILE)) { continue; }