diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2007-12-04 21:03:19 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2007-12-04 21:03:19 (GMT) |
commit | 5050706ae393bf2c10a5279ddc23613775ad9b3b (patch) | |
tree | 8d16cccaf3509bd56e20d432d78b1e3400ea2e89 /Source/kwsys/SystemTools.cxx | |
parent | ab7f11a23941ffe69d6e9de3c3c35e4835424e5f (diff) | |
download | CMake-5050706ae393bf2c10a5279ddc23613775ad9b3b.zip CMake-5050706ae393bf2c10a5279ddc23613775ad9b3b.tar.gz CMake-5050706ae393bf2c10a5279ddc23613775ad9b3b.tar.bz2 |
ENH: add a touch -E command to cmake
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 28efd40..e9d72ed 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -50,6 +50,7 @@ // support for realpath call #ifndef _WIN32 +#include <utime.h> #include <limits.h> #include <sys/param.h> #include <sys/wait.h> @@ -75,6 +76,11 @@ # define HAVE_TTY_INFO 1 #endif +#ifdef _MSC_VER +#include <sys/utime.h> +#else +#include <utime.h> +#endif // This is a hack to prevent warnings about these functions being // declared but not referenced. @@ -836,6 +842,36 @@ bool SystemTools::FileExists(const char* filename) } } +bool SystemTools::Touch(const char* filename, bool create) +{ + if(create && !SystemTools::FileExists(filename)) + { + FILE* file = fopen(filename, "a+b"); + if(file) + { + fclose(file); + return true; + } + return false; + } +#ifdef _MSC_VER +#define utime _utime +#define utimbuf _utimbuf +#endif + struct stat fromStat; + if(stat(filename, &fromStat) < 0) + { + return false; + } + struct utimbuf buf; + buf.actime = fromStat.st_atime; + buf.modtime = SystemTools::GetTime(); + if(utime(filename, &buf) < 0) + { + return false; + } + return true; +} bool SystemTools::FileTimeCompare(const char* f1, const char* f2, int* result) |