diff options
author | Kent Williams <norman-k-williams@uiowa.edu> | 2003-04-10 17:41:15 (GMT) |
---|---|---|
committer | Kent Williams <norman-k-williams@uiowa.edu> | 2003-04-10 17:41:15 (GMT) |
commit | 756653cbb86194b010271eadd392ad96d6b2f853 (patch) | |
tree | 949dff005ddad22f66d3f669c70ca79fd3256298 /Source/kwsys/SystemTools.cxx | |
parent | 5e9b2b94da2ba7a71d6d5b24492b272b05041d09 (diff) | |
download | CMake-756653cbb86194b010271eadd392ad96d6b2f853.zip CMake-756653cbb86194b010271eadd392ad96d6b2f853.tar.gz CMake-756653cbb86194b010271eadd392ad96d6b2f853.tar.bz2 |
Removed platform-specific functions from Code/IO/itkIOCommon, fixed code to use kwsys/SystemTools
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index ae0bb1f..aec5b27 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -1016,6 +1016,29 @@ bool SystemTools::CopyFileAlways(const char* source, const char* destination) return true; } +// return size of file; also returns zero if no file exists +unsigned long SystemTools::FileLength(const char* filename) +{ + struct stat fs; + if (stat(filename, &fs) != 0) + { + return 0; + } + else + { + return fs.st_size; + } +} + +int SystemTools::Strucmp(const char *s1, const char *s2) +{ +#ifdef _WIN32 + return _stricmp(s1,s2); +#else + return strcasecmp(s1,s2); +#endif +} + // return true if the file exists long int SystemTools::ModifiedTime(const char* filename) { @@ -1042,6 +1065,45 @@ bool SystemTools::RemoveFile(const char* source) return unlink(source) != 0 ? false : true; } +char *SystemTools +::RealPath(const char *path, char *resolved_path) +{ +#if defined(_WIN32) + char pathpart[itk::IOCommon::ITK_MAXPATHLEN]; + strcpy(pathpart,path); + char fnamepart[itk::IOCommon::ITK_MAXPATHLEN]; + char *slash; + + if((slash = strrchr(pathpart,'/')) == NULL) + { + slash = strrchr(pathpart,'\\'); + } + + if(slash == NULL) // no path part, so just use current dir. + { + Getcwd(pathpart,sizeof(pathpart)); + strcpy(fnamepart,path); + } + else // change directory to path part, getcwd to find OS resolved path + { + *slash = '\0'; + strcpy(fnamepart,slash+1); + + char savedir[itk::IOCommon::ITK_MAXPATHLEN]; + Getcwd(savedir,sizeof(savedir)); + Chdir(pathpart); + Getcwd(pathpart,sizeof(pathpart)); + Chdir(savedir); + } + strcpy(resolved_path,pathpart); + strcat(resolved_path,"/"); + strcat(resolved_path,fnamepart); + return resolved_path; +#else + return realpath(path,resolved_path); +#endif +} + /** * Find the file the given name. Searches the given path and then * the system search path. Returns the full path to the file if it is |