mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Hadrons: recursive mkdir function
This commit is contained in:
parent
ce7720e221
commit
b61292f735
@ -92,3 +92,54 @@ const std::string Hadrons::resultFileExt = "h5";
|
||||
#else
|
||||
const std::string Hadrons::resultFileExt = "xml";
|
||||
#endif
|
||||
|
||||
// recursive mkdir /////////////////////////////////////////////////////////////
|
||||
int Hadrons::mkdir(const std::string dirName)
|
||||
{
|
||||
if (access(dirName.c_str(), R_OK|W_OK|X_OK))
|
||||
{
|
||||
mode_t mode755;
|
||||
char tmp[MAX_PATH_LENGTH];
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
|
||||
mode755 = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s", dirName.c_str());
|
||||
len = strlen(tmp);
|
||||
if(tmp[len - 1] == '/')
|
||||
{
|
||||
tmp[len - 1] = 0;
|
||||
}
|
||||
for(p = tmp + 1; *p; p++)
|
||||
{
|
||||
if(*p == '/')
|
||||
{
|
||||
*p = 0;
|
||||
::mkdir(tmp, mode755);
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
|
||||
return ::mkdir(tmp, mode755);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Hadrons::basename(const std::string &s)
|
||||
{
|
||||
constexpr char sep = '/';
|
||||
size_t i = s.rfind(sep, s.length());
|
||||
|
||||
if (i != std::string::npos)
|
||||
{
|
||||
return s.substr(i+1, s.length() - i);
|
||||
}
|
||||
else
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
@ -187,8 +187,12 @@ typedef XmlWriter ResultWriter;
|
||||
#define RESULT_FILE_NAME(name) \
|
||||
name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt
|
||||
|
||||
// default Schur convention
|
||||
// recursive mkdir
|
||||
#define MAX_PATH_LENGTH 512u
|
||||
int mkdir(const std::string dirName);
|
||||
std::string basename(const std::string &s);
|
||||
|
||||
// default Schur convention
|
||||
#ifndef HADRONS_DEFAULT_SCHUR
|
||||
#define HADRONS_DEFAULT_SCHUR DiagTwo
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user