summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-06-28 22:29:54 (GMT)
committerBrad King <brad.king@kitware.com>2013-06-28 22:29:54 (GMT)
commit4e5cb398ae392079031ae6a880569349c29770a6 (patch)
tree55b13e53e2368e0425602fb8527936accc50ac9a /Source/kwsys/SystemTools.cxx
parent78fdbbcb4130eedc2cb48ec9e67fad5c2beffb0e (diff)
parentdaaf6283f5c0e8b7ea7ee93f983ad56d4498788d (diff)
downloadCMake-4e5cb398ae392079031ae6a880569349c29770a6.zip
CMake-4e5cb398ae392079031ae6a880569349c29770a6.tar.gz
CMake-4e5cb398ae392079031ae6a880569349c29770a6.tar.bz2
Merge branch 'master' into vs12-generator
Resolve conflicts in Tests/Preprocess/CMakeLists.txt by keeping the side from 'master'.
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r--Source/kwsys/SystemTools.cxx83
1 files changed, 64 insertions, 19 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 22bf193..4d5af5e 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -605,7 +605,7 @@ bool SystemTools::MakeDirectory(const char* path)
}
if(SystemTools::FileExists(path))
{
- return true;
+ return SystemTools::FileIsDirectory(path);
}
kwsys_stl::string dir = path;
if(dir.size() == 0)
@@ -1124,22 +1124,58 @@ bool SystemTools::Touch(const char* filename, bool create)
}
return false;
}
-#ifdef _MSC_VER
-#define utime _utime
-#define utimbuf _utimbuf
-#endif
- struct stat fromStat;
- if(stat(filename, &fromStat) < 0)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ HANDLE h = CreateFile(filename, FILE_WRITE_ATTRIBUTES,
+ FILE_SHARE_WRITE, 0, OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS, 0);
+ if(!h)
+ {
+ return false;
+ }
+ FILETIME mtime;
+ GetSystemTimeAsFileTime(&mtime);
+ if(!SetFileTime(h, 0, 0, &mtime))
{
+ CloseHandle(h);
return false;
}
- struct utimbuf buf;
- buf.actime = fromStat.st_atime;
- buf.modtime = static_cast<time_t>(SystemTools::GetTime());
- if(utime(filename, &buf) < 0)
+ CloseHandle(h);
+#elif KWSYS_CXX_HAS_UTIMENSAT
+ struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
+ if(utimensat(AT_FDCWD, filename, times, 0) < 0)
{
return false;
}
+#else
+ struct stat st;
+ if(stat(filename, &st) < 0)
+ {
+ return false;
+ }
+ struct timeval mtime;
+ gettimeofday(&mtime, 0);
+# if KWSYS_CXX_HAS_UTIMES
+ struct timeval times[2] =
+ {
+# if KWSYS_STAT_HAS_ST_MTIM
+ {st.st_atim.tv_sec, st.st_atim.tv_nsec/1000}, /* tv_sec, tv_usec */
+# else
+ {st.st_atime, 0},
+# endif
+ mtime
+ };
+ if(utimes(filename, times) < 0)
+ {
+ return false;
+ }
+# else
+ struct utimbuf times = {st.st_atime, mtime.tv_sec};
+ if(utime(filename, &times) < 0)
+ {
+ return false;
+ }
+# endif
+#endif
return true;
}
@@ -2741,15 +2777,24 @@ bool SystemTools::FileIsDirectory(const char* name)
return false;
}
- // Remove any trailing slash from the name.
- char buffer[KWSYS_SYSTEMTOOLS_MAXPATH];
+ // Remove any trailing slash from the name except in a root component.
+ char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH];
+ std::string string_buffer;
size_t last = length-1;
if(last > 0 && (name[last] == '/' || name[last] == '\\')
- && strcmp(name, "/") !=0)
+ && strcmp(name, "/") !=0 && name[last-1] != ':')
{
- memcpy(buffer, name, last);
- buffer[last] = 0;
- name = buffer;
+ if(last < sizeof(local_buffer))
+ {
+ memcpy(local_buffer, name, last);
+ local_buffer[last] = 0;
+ name = local_buffer;
+ }
+ else
+ {
+ string_buffer.append(name, last);
+ name = string_buffer.c_str();
+ }
}
// Now check the file node type.
@@ -3040,7 +3085,7 @@ SystemToolsAppendComponents(
{
if(*i == "..")
{
- if(out_components.begin() != out_components.end())
+ if(out_components.size() > 1)
{
out_components.erase(out_components.end()-1, out_components.end());
}
@@ -4002,7 +4047,7 @@ void SystemTools::SplitProgramFromArgs(const char* path,
args = dir.substr(spacePos, dir.size()-spacePos);
return;
}
- // Now try and find the the program in the path
+ // Now try and find the program in the path
findProg = SystemTools::FindProgram(tryProg.c_str(), e);
if(findProg.size())
{