Implement mkpath
This commit is contained in:
parent
bb0bd8f6a0
commit
d2047e43e0
@ -118,4 +118,6 @@ static inline std::string methodName(const std::string& prettyFunction)
|
|||||||
return prettyFunction.substr(begin,end) + "()";
|
return prettyFunction.substr(begin,end) + "()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mkpath(std::string path, int mode = 0777);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -9,6 +9,9 @@
|
|||||||
*
|
*
|
||||||
* @bug No known bugs
|
* @bug No known bugs
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
std::string scientific_format(double d, int width, int prec)
|
std::string scientific_format(double d, int width, int prec)
|
||||||
@ -69,3 +72,28 @@ bool arma_vector_close_to(arma::vec &a, arma::vec &b, double tol)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mkpath(std::string path, int mode)
|
||||||
|
{
|
||||||
|
std::string cur_dir;
|
||||||
|
std::string::size_type pos = -1;
|
||||||
|
struct stat buf;
|
||||||
|
|
||||||
|
if (path.back() != '/') {
|
||||||
|
path += '/';
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
pos++;
|
||||||
|
pos = path.find('/', pos);
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
cur_dir = path.substr(0, pos);
|
||||||
|
if (mkdir(cur_dir.c_str(), mode) != 0 && stat(cur_dir.c_str(), &buf) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user