diff --git a/SystemTools.cxx b/SystemTools.cxx index 0a22d638a90c65a38390f57d38a09f70c8e2c9fe..ecfa3319bcc5340d631301b1f0488df7b177922b 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -2371,104 +2371,6 @@ long int SystemTools::CreationTime(const std::string& filename) return ct; } -bool SystemTools::ConvertDateMacroString(const char* str, time_t* tmt) -{ - if (!str || !tmt || strlen(str) > 11) { - return false; - } - - struct tm tmt2; - - // __DATE__ - // The compilation date of the current source file. The date is a string - // literal of the form Mmm dd yyyy. The month name Mmm is the same as for - // dates generated by the library function asctime declared in TIME.H. - - // index: 012345678901 - // format: Mmm dd yyyy - // example: Dec 19 2003 - - static char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; - - char buffer[12]; - strcpy(buffer, str); - - buffer[3] = 0; - char* ptr = strstr(month_names, buffer); - if (!ptr) { - return false; - } - - int month = static_cast<int>((ptr - month_names) / 3); - int day = atoi(buffer + 4); - int year = atoi(buffer + 7); - - tmt2.tm_isdst = -1; - tmt2.tm_hour = 0; - tmt2.tm_min = 0; - tmt2.tm_sec = 0; - tmt2.tm_wday = 0; - tmt2.tm_yday = 0; - tmt2.tm_mday = day; - tmt2.tm_mon = month; - tmt2.tm_year = year - 1900; - - *tmt = mktime(&tmt2); - return true; -} - -bool SystemTools::ConvertTimeStampMacroString(const char* str, time_t* tmt) -{ - if (!str || !tmt || strlen(str) > 26) { - return false; - } - - struct tm tmt2; - - // __TIMESTAMP__ - // The date and time of the last modification of the current source file, - // expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy, - /// where Ddd is the abbreviated day of the week and Date is an integer - // from 1 to 31. - - // index: 0123456789 - // 0123456789 - // 0123456789 - // format: Ddd Mmm Date hh:mm:ss yyyy - // example: Fri Dec 19 14:34:58 2003 - - static char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; - - char buffer[27]; - strcpy(buffer, str); - - buffer[7] = 0; - char* ptr = strstr(month_names, buffer + 4); - if (!ptr) { - return false; - } - - int month = static_cast<int>((ptr - month_names) / 3); - int day = atoi(buffer + 8); - int hour = atoi(buffer + 11); - int min = atoi(buffer + 14); - int sec = atoi(buffer + 17); - int year = atoi(buffer + 20); - - tmt2.tm_isdst = -1; - tmt2.tm_hour = hour; - tmt2.tm_min = min; - tmt2.tm_sec = sec; - tmt2.tm_wday = 0; - tmt2.tm_yday = 0; - tmt2.tm_mday = day; - tmt2.tm_mon = month; - tmt2.tm_year = year - 1900; - - *tmt = mktime(&tmt2); - return true; -} - std::string SystemTools::GetLastSystemError() { int e = errno; diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index 41a60d3058e02eaa6cba6eb93b4e0bbb6e603797..35bc1b19ba7e10020f06de03d2a97c36fe4a18e5 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -205,13 +205,6 @@ public: */ static int Strucmp(const char* s1, const char* s2); - /** - * Convert a string in __DATE__ or __TIMESTAMP__ format into a time_t. - * Return false on error, true on success - */ - static bool ConvertDateMacroString(const char* str, time_t* tmt); - static bool ConvertTimeStampMacroString(const char* str, time_t* tmt); - /** * Split a string on its newlines into multiple lines * Return false only if the last line stored had no newline diff --git a/testSystemTools.cxx b/testSystemTools.cxx index 1871f5dd0d81767d9cab71863184000d92cfd7de..768eb4d12745ae46a9cb6e74e36d4c97c86d6f57 100644 --- a/testSystemTools.cxx +++ b/testSystemTools.cxx @@ -22,6 +22,7 @@ #include <iostream> #include <sstream> +#include <stdlib.h> /* free */ #include <string.h> /* strcmp */ #if defined(_WIN32) && !defined(__CYGWIN__) #include <io.h> /* _umask (MSVC) / umask (Borland) */ @@ -535,15 +536,14 @@ static bool CheckStringOperations() } delete[] cres; - char* cres2 = new char[strlen("Mary Had A Little Lamb.") + 1]; - strcpy(cres2, "Mary Had A Little Lamb."); + char* cres2 = strdup("Mary Had A Little Lamb."); kwsys::SystemTools::ReplaceChars(cres2, "aeiou", 'X'); if (strcmp(cres2, "MXry HXd A LXttlX LXmb.")) { std::cerr << "Problem with ReplaceChars " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; } - delete[] cres2; + free(cres2); if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.", "Mary ")) {