summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/Directory.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-08-04 14:16:34 (GMT)
committerBrad King <brad.king@kitware.com>2014-08-04 14:16:34 (GMT)
commit60c783676c91ff1ded2ed5e6fd50d0f9664032e5 (patch)
tree02f4932329dbe4777918ce1d9f94307be9c3e414 /Source/kwsys/Directory.cxx
parentba60ff99ed2ea35f8b8c24bc566b6f60d51fce53 (diff)
parent158c6d1cffe863fde284d4e5eeeb8129d40ce0e9 (diff)
downloadCMake-60c783676c91ff1ded2ed5e6fd50d0f9664032e5.zip
CMake-60c783676c91ff1ded2ed5e6fd50d0f9664032e5.tar.gz
CMake-60c783676c91ff1ded2ed5e6fd50d0f9664032e5.tar.bz2
Merge branch 'upstream-kwsys' into update-kwsys
Diffstat (limited to 'Source/kwsys/Directory.cxx')
-rw-r--r--Source/kwsys/Directory.cxx41
1 files changed, 16 insertions, 25 deletions
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx
index b305fd7..741bcba 100644
--- a/Source/kwsys/Directory.cxx
+++ b/Source/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,24 +112,24 @@ bool Directory::Load(const char* name)
intptr_t srchHandle;
#endif
char* buf;
- size_t n = strlen(name);
- if ( name[n - 1] == '/' || 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];
- if ( strchr(name, '\\') )
+ if ( name.find('\\') != name.npos )
{
- sprintf(buf, "%s\\*", name);
+ sprintf(buf, "%s\\*", name.c_str());
}
else
{
- sprintf(buf, "%s/*", name);
+ sprintf(buf, "%s/*", name.c_str());
}
}
struct _wfinddata_t data; // data of current file
@@ -153,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;
@@ -161,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
@@ -215,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)
{
@@ -239,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) )