mkdir and rmdir basic implementation

This commit is contained in:
vaclavt
2022-03-21 17:46:32 +01:00
parent 2856043feb
commit 2607a50986
8 changed files with 44 additions and 43 deletions

View File

@@ -1,6 +1,7 @@
#include "ml_io.h"
#include <cstring>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -65,12 +66,22 @@ bool is_path_dir(const std::string &path) {
return (bool) S_ISDIR(buf.st_mode);
}
int mk_path_dir(const std::string &path) {
return ::mkdir(path.c_str(), 0755);
bool mk_path_dir(const std::string &path) {
auto r = ::mkdir(path.c_str(), 0755);
if (r == -1) {
std::string err_msg = std::strerror(errno);
std::cerr << "mkdir failed: " << std::strerror(errno) << std::endl;
}
return r == 0;
}
int rm_path_dir(const std::string &path) {
return ::rmdir(path.c_str());
bool rm_path_dir(const std::string &path) {
auto r = ::rmdir(path.c_str());
if (r == -1) {
std::string err_msg = std::strerror(errno);
std::cerr << "rmdir failed: " << std::strerror(errno) << std::endl;
}
return r == 0;
}
MlValue exec_system_cmd(const std::string &cmd) {