00001 #ifndef STRING_UTILITIES_CPP 00002 #define STRING_UTILITIES_CPP 00003 00004 //-------------------------------------------------------------------- 00005 // 00006 // This file is part of PEACE. 00007 // 00008 // PEACE is free software: you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation, either version 3 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // PEACE is distributed in the hope that it will be useful, but 00014 // WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with PEACE. If not, see <http://www.gnu.org/licenses/>. 00020 // 00021 // Miami University makes no representations or warranties about the 00022 // suitability of the software, either express or implied, including 00023 // but not limited to the implied warranties of merchantability, 00024 // fitness for a particular purpose, or non-infringement. Miami 00025 // University shall not be liable for any damages suffered by licensee 00026 // as a result of using, result of using, modifying or distributing 00027 // this software or its derivatives. 00028 // 00029 // By using or copying this Software, Licensee agrees to abide by the 00030 // intellectual property laws, and all other applicable laws of the 00031 // U.S., and the terms of GNU General Public License (version 3). 00032 // 00033 // Authors: Dhananjai M. Rao raodm@muohio.edu 00034 // 00035 //--------------------------------------------------------------------- 00036 00037 #include "Utilities.h" 00038 #include <sys/types.h> 00039 #include <sys/stat.h> 00040 #include <ctime> 00041 00042 char* 00043 getTimeStamp(const char *fileName, char *buffer) { 00044 if (fileName == NULL) { 00045 // Nothing further to be done here. 00046 return buffer; 00047 } 00048 // The follwing structure will contain the file information. 00049 int returnValue = 0; 00050 #ifdef _WINDOWS 00051 struct _stat fileInfo; 00052 returnValue = _stat(fileName, &fileInfo); 00053 #else 00054 struct stat fileInfo; 00055 // The only difference between windows and Linux is the extra "_" 00056 // at the beginning of stat() method. 00057 returnValue = stat(fileName, &fileInfo); 00058 #endif 00059 // Check to ensure there were no errors. If there were errors 00060 // exit immediately. 00061 if (returnValue == -1) { 00062 // O!o! there was an error. 00063 return buffer; 00064 } 00065 // Convert the last modification time to string and return it back 00066 // to the caller. 00067 return getTime(buffer, &fileInfo.st_mtime); 00068 } 00069 00070 char* getTime(char *buffer, const time_t *encodedTime) { 00071 if (buffer == NULL) { 00072 // Nothing more to do. 00073 return NULL; 00074 } 00075 // Get instant system time. 00076 time_t timeToConv = time(NULL); 00077 if (encodedTime != NULL) { 00078 // If we have a valid time supplied, then override system time. 00079 timeToConv = *encodedTime; 00080 } 00081 // Convert the time. 00082 ctime_s(buffer, 128, &timeToConv); 00083 // Return the buffer back to the caller 00084 return buffer; 00085 } 00086 00087 #endif 00088