summaryrefslogtreecommitdiffstats
path: root/Directory.cxx
diff options
context:
space:
mode:
authorKWSys Robot <kwrobot@kitware.com>2014-08-04 12:59:12 (GMT)
committerBrad King <brad.king@kitware.com>2014-08-04 14:16:30 (GMT)
commit158c6d1cffe863fde284d4e5eeeb8129d40ce0e9 (patch)
treecfcd285d4d397ad9570f5ee25d3139b89cfa190c /Directory.cxx
parentd4d1b7f7d1d6592f12a6692dfb8068aa495bd454 (diff)
downloadCMake-158c6d1cffe863fde284d4e5eeeb8129d40ce0e9.zip
CMake-158c6d1cffe863fde284d4e5eeeb8129d40ce0e9.tar.gz
CMake-158c6d1cffe863fde284d4e5eeeb8129d40ce0e9.tar.bz2
KWSys 2014-08-04 (e787837a)
Extract upstream KWSys using the following shell commands. $ git archive --prefix=upstream-kwsys/ e787837a | tar x $ git shortlog --no-merges --abbrev=8 --format='%h %s' 65b36ede..e787837a Ben Boeckel (4): 9927862c SystemTools: more string replacements b3d598b0 strings: remove unnecessary c_str calls ffe94132 SystemTools: use char instead of const char* f29fec7c Directory: accept strings in methods Rashad M (1): e787837a SharedForward: Cast away const to call execvp on MinGW 64-bit Change-Id: I96437b332971670cfcd953717c5563e9ba0f2b99
Diffstat (limited to 'Directory.cxx')
-rw-r--r--Directory.cxx41
1 files changed, 16 insertions, 25 deletions
diff --git a/Directory.cxx b/Directory.cxx
index b305fd7..741bcba 100644
--- a/Directory.cxx
+++ b/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) )