summaryrefslogtreecommitdiffstats
path: root/src/kwsys/Directory.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-09-24 19:59:12 (GMT)
committerBrad King <brad.king@kitware.com>2014-09-24 19:59:12 (GMT)
commit3c3738fef1b80f2ba22846f6ce71b5bfe943a985 (patch)
tree81a51c2ada580d419bcdbf2c3f3d0588efc603fe /src/kwsys/Directory.cxx
parent9655989a63e3dc3d6cf8ee32a1f3123f6cf85daf (diff)
parentc1f1673904ecad648f17979ef9743cbde749fc66 (diff)
downloadCastXML-3c3738fef1b80f2ba22846f6ce71b5bfe943a985.zip
CastXML-3c3738fef1b80f2ba22846f6ce71b5bfe943a985.tar.gz
CastXML-3c3738fef1b80f2ba22846f6ce71b5bfe943a985.tar.bz2
Merge branch 'upstream-kwsys' into src/kwsys/ subtree
Diffstat (limited to 'src/kwsys/Directory.cxx')
-rw-r--r--src/kwsys/Directory.cxx46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/kwsys/Directory.cxx b/src/kwsys/Directory.cxx
index d54e607..741bcba 100644
--- a/src/kwsys/Directory.cxx
+++ b/src/kwsys/Directory.cxx
@@ -103,7 +103,7 @@ void Directory::Clear()
namespace KWSYS_NAMESPACE
{
-bool Directory::Load(const char* name)
+bool Directory::Load(const kwsys_stl::string& name)
{
this->Clear();
#if _MSC_VER < 1300
@@ -112,16 +112,25 @@ bool Directory::Load(const char* name)
intptr_t srchHandle;
#endif
char* buf;
- size_t n = strlen(name);
- if ( name[n - 1] == '/' )
+ size_t n = name.size();
+ if ( *name.rbegin() == '/' || *name.rbegin() == '\\' )
{
buf = new char[n + 1 + 1];
- sprintf(buf, "%s*", name);
+ sprintf(buf, "%s*", name.c_str());
}
else
{
+ // Make sure the slashes in the wildcard suffix are consistent with the
+ // rest of the path
buf = new char[n + 2 + 1];
- sprintf(buf, "%s/*", name);
+ if ( name.find('\\') != name.npos )
+ {
+ sprintf(buf, "%s\\*", name.c_str());
+ }
+ else
+ {
+ sprintf(buf, "%s/*", name.c_str());
+ }
}
struct _wfinddata_t data; // data of current file
@@ -144,7 +153,7 @@ bool Directory::Load(const char* name)
return _findclose(srchHandle) != -1;
}
-unsigned long Directory::GetNumberOfFilesInDirectory(const char* name)
+unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name)
{
#if _MSC_VER < 1300
long srchHandle;
@@ -152,16 +161,16 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const char* name)
intptr_t srchHandle;
#endif
char* buf;
- size_t n = strlen(name);
- if ( name[n - 1] == '/' )
+ size_t n = name.size();
+ if ( *name.rbegin() == '/' )
{
buf = new char[n + 1 + 1];
- sprintf(buf, "%s*", name);
+ sprintf(buf, "%s*", name.c_str());
}
else
{
buf = new char[n + 2 + 1];
- sprintf(buf, "%s/*", name);
+ sprintf(buf, "%s/*", name.c_str());
}
struct _wfinddata_t data; // data of current file
@@ -206,15 +215,11 @@ p=1992&sid=f16167f51964f1a68fe5041b8eb213b6
namespace KWSYS_NAMESPACE
{
-bool Directory::Load(const char* name)
+bool Directory::Load(const kwsys_stl::string& name)
{
this->Clear();
- if (!name)
- {
- return 0;
- }
- DIR* dir = opendir(name);
+ DIR* dir = opendir(name.c_str());
if (!dir)
{
@@ -230,14 +235,9 @@ bool Directory::Load(const char* name)
return 1;
}
-unsigned long Directory::GetNumberOfFilesInDirectory(const char* name)
+unsigned long Directory::GetNumberOfFilesInDirectory(const kwsys_stl::string& name)
{
- DIR* dir = opendir(name);
-
- if (!dir)
- {
- return 0;
- }
+ DIR* dir = opendir(name.c_str());
unsigned long count = 0;
for (dirent* d = readdir(dir); d; d = readdir(dir) )