15 #define GCC_VERSION (__GNUC__ * 10000 \
16 + __GNUC_MINOR__ * 100 \
17 + __GNUC_PATCHLEVEL__)
18 # if GCC_VERSION <= 60200
19 # include <asm-generic/errno-base.h>
26 #include <sys/types.h>
95 if(
str.size() == 0lu || expression.size() == 0lu){
return false;}
98 const char *str_request =
str.c_str();
99 const char *str_regex = expression.c_str();
100 err = regcomp(&preg, str_regex, 0);
101 if(err != 0)
return false;
102 int match = regexec(&preg, str_request, 0, NULL, 0);
104 if(match == 0){
return true;}
127 char * curr_dir = getenv(
"PWD");
128 if(NULL == curr_dir){
129 printf(
"getListFileInCurrentDir : Could not get the working directory\n");
133 DIR * dp = opendir((
const char*)curr_dir);
135 printf(
"getListFileInCurrentDir : Could not open the working directory\n");
138 dirent * dptr = readdir(dp);
140 if(
isStringMatchRegex(std::string(dptr->d_name), expr)) listFile.push_back(std::string(dptr->d_name));
150 bool getListFileInDir(std::list<std::string> & listFile,
const std::string & dirName,
const std::string & expr){
152 DIR * dp = opendir(dirName.c_str());
157 dirent * dptr = readdir(dp);
159 if(
isStringMatchRegex(std::string(dptr->d_name), expr)) listFile.push_back(std::string(dptr->d_name));
160 std::cout <<
"getListFileInDir : '" << std::string(dptr->d_name) <<
"'"<< std::endl;
173 DIR * dp = opendir(dirName.c_str());
177 dirent * dptr = readdir(dp);
179 std::string fileName(dptr->d_name);
180 if(fileName !=
".." && fileName !=
"."){
181 listFile.push_back(fileName);
194 if(argc <= 0)
return;
195 for(
int i(0); i < argc; ++i){
196 listArgument.push_back(argv[i]);
205 char * curr_var = getenv(varName.c_str());
206 if(NULL == curr_var){
209 return std::string(curr_var);
219 bool phoenix_setenv(
const std::string & name,
const std::string & value,
int overwrite){
220 return setenv(name.c_str(), value.c_str(), overwrite) == 0;
228 return unsetenv(name.c_str()) == 0;
243 if(directoryName ==
"")
return false;
247 int res = mkdir(directoryName.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
248 return res == 0 || res == EEXIST;
257 if(stat(fileName.c_str(), &attr) == 0){
259 return attr.st_mtimespec.tv_sec;
261 return attr.st_mtim.tv_sec;
274 time_t
getFileInDirPerTime(std::vector<std::string> & vecFile,
const std::string & dirName, time_t mostRecentTime){
275 DIR * dp = opendir(dirName.c_str());
276 if(dp == NULL){
return mostRecentTime;}
277 dirent * dptr = readdir(dp);
279 if(dptr->d_type == DT_REG){
280 std::string pathName(dptr->d_name);
282 if(fileTime > mostRecentTime){
283 mostRecentTime = fileTime;
284 vecFile.push_back(pathName);
289 return mostRecentTime;
298 ssize_t nbChar = readlink(
"/proc/self/exe", buffer, 2048);
304 std::string outputBuf(
"");
305 for(ssize_t i(0l); i < nbChar; ++i){
306 outputBuf += buffer[i];
322 #ifdef CMAKE_INSTALL_PREFIX
323 return CMAKE_INSTALL_PREFIX
"/bin/";
342 if(command ==
""){
return "";}
343 FILE * fp = popen(command.c_str(),
"r");
345 std::cerr <<
"phoenix_popen : cannot get result of command '"<<command<<
"'" << std::endl;
350 return resultCommand;
360 if(command ==
""){
return -1;}
361 FILE * fp = popen(command.c_str(),
"r");
363 std::cerr <<
"phoenix_popen : cannot get result of command '"<<command<<
"'" << std::endl;
376 bool phoenix_popen(
const std::string & executionLogFile,
const std::string & command,
bool onlyLogOnFail){
377 std::string executionLog(
"");
380 std::cerr <<
"phoenix_popen : command '"<<command<<
"' failed. To get more information see log '"<<executionLogFile<<
"'" << std::endl;
382 if((onlyLogOnFail && !b) || !onlyLogOnFail){
384 std::cerr <<
"phoenix_popen : cannot create log file '"<<executionLogFile<<
"'" << std::endl;
396 bool b(chmod(fileName.c_str(), __mode) >= 0);
398 std::cerr <<
"phoenix_chmod : Cannot set mode of file '"<<fileName<<
"'" << std::endl;
414 void phoenix_find(std::vector<std::string> & vecFile,
const std::string & path){
423 std::vector<std::string> vecFile;
454 std::tm* now_tm = std::gmtime(¤tTime);
456 std::strftime(buf, 42,
"%Y/%m/%d : %X", now_tm);
465 std::tm* now_tm = std::gmtime(¤tTime);
467 std::strftime(buf, 42,
"%Y/%m/%d-%X", now_tm);