--- smsdaemon/util.cpp 2008/06/15 16:05:14 79 +++ smsdaemon/util.cpp 2008/07/04 07:58:26 108 @@ -9,6 +9,7 @@ #include #include #include +#include #include "util.h" @@ -104,12 +105,34 @@ return retval; } + char my_toupper(char ch) + { + if (ch == 'æ') + return 'Æ'; + if (ch == 'ø') + return 'Ø'; + if (ch == 'å') + return 'Å'; + + return ::toupper(ch); + } + char my_tolower(char ch) + { + if (ch == 'Æ') + return 'æ'; + if (ch == 'Ø') + return 'ø'; + if (ch == 'Å') + return 'å'; + + return ::tolower(ch); + } string str_toupper(string str) { for (unsigned i=0; i0) + { + throw std::runtime_error("Command time out or document not found"); + } ifstream in( tempfile.c_str() ); @@ -280,7 +308,38 @@ int mTimeDiff(const timeval& then, const timeval& now) { - return uTimeDiff(then,now) / 1000; + return ( (now.tv_sec - then.tv_sec)*1000) + + ((now.tv_usec-then.tv_usec)/1000); + } + + + timeval GetTimeOfDay() + { + timeval now; + gettimeofday(&now,0); + return now; + } + + int my_system(const char* cmd, std::string* response) + { + FILE* p; + if ((p = popen(cmd,"r")) == NULL) + return (-1); + + if (response) + { + std::string output; + char buf[256]; + while(!feof(p)) + { + int len = fread(buf,1,255, p); + buf[len] = 0; + output += buf; + } + *response = output; + } + + return (pclose(p)); } }