summaryrefslogtreecommitdiffstats
path: root/SystemTools.cxx
diff options
context:
space:
mode:
authorKWSys Robot <kwrobot@kitware.com>2013-05-31 20:34:02 (GMT)
committerBrad King <brad.king@kitware.com>2013-06-03 14:23:16 (GMT)
commitd66f6f36baca6d314f1f17e11d90d52b5c9d7ec2 (patch)
treeffc8003ad90d02fcac170f922eccd4adbe55abae /SystemTools.cxx
parent927012979e54a69d9d49f188ce73f7b4ca2fb073 (diff)
downloadCMake-d66f6f36baca6d314f1f17e11d90d52b5c9d7ec2.zip
CMake-d66f6f36baca6d314f1f17e11d90d52b5c9d7ec2.tar.gz
CMake-d66f6f36baca6d314f1f17e11d90d52b5c9d7ec2.tar.bz2
KWSys 2013-05-31 (dccf7725)
Extract upstream KWSys using the following shell commands. $ git archive --prefix=upstream-kwsys/ dccf7725 | tar x $ git shortlog --no-merges --abbrev=8 --format='%h %s' 725e541e..dccf7725 Brad King (2): e3370418 SystemTools: Use COMPILE_DEFINITIONS to pass platform tests dccf7725 SystemTools: Touch with better than 1s resolution if possible Change-Id: Icdbcdf405e27b2d5dd30857c7c8679ed5096f252
Diffstat (limited to 'SystemTools.cxx')
-rw-r--r--SystemTools.cxx56
1 files changed, 46 insertions, 10 deletions
diff --git a/SystemTools.cxx b/SystemTools.cxx
index 158217e..652649f 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -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;
}