44#if defined(TIMEMORY_UNIX)
48# include <sys/types.h>
49#elif defined(TIMEMORY_WINDOWS)
54#if !defined(TIMEMORY_DEFAULT_UMASK)
55# define TIMEMORY_DEFAULT_UMASK 0777
68 auto _pos = std::string::npos;
69 while((_pos = _path.find(_c)) != std::string::npos)
70 _path.replace(_pos, 1, _v);
77 auto _pos = std::string::npos;
78 while((_pos = _path.find(_c)) != std::string::npos)
79 _path.replace(_pos, strlen(_c), _v);
83#if defined(TIMEMORY_WINDOWS)
101 while(_path.find(
'/') != std::string::npos)
102 _path.replace(_path.find(
'/'), 1,
"\\");
106#elif defined(TIMEMORY_UNIX)
124 while(_path.find(
"\\\\") != std::string::npos)
125 _path.replace(_path.find(
"\\\\"), 2,
"/");
126 while(_path.find(
'\\') != std::string::npos)
127 _path.replace(_path.find(
'\\'), 1,
"/");
144#if defined(TIMEMORY_UNIX)
145 while(
_dir.find(
"\\\\") != std::string::npos)
146 _dir.replace(
_dir.find(
"\\\\"), 2,
"/");
147 while(
_dir.find(
'\\') != std::string::npos)
148 _dir.replace(
_dir.find(
'\\'), 1,
"/");
150 if(
_dir.length() == 0)
153 int ret = mkdir(
_dir.c_str(), umask);
159 std::stringstream _mdir{};
160 _mdir <<
"mkdir(" <<
_dir.c_str() <<
", " << umask <<
") returned: " << ret
162 std::stringstream _sdir{};
163 _sdir <<
"/bin/mkdir -p " <<
_dir;
167 std::cerr << _mdir.str() << _sdir.str() <<
" returned: " << ret
173#elif defined(TIMEMORY_WINDOWS)
175 while(
_dir.find(
'/') != std::string::npos)
176 _dir.replace(
_dir.find(
'/'), 1,
"\\");
178 if(
_dir.length() == 0)
181 int ret = _mkdir(
_dir.c_str());
187 std::stringstream _mdir{};
188 _mdir <<
"_mkdir(" <<
_dir.c_str() <<
") returned: " << ret <<
"\n";
189 std::stringstream _sdir{};
190 _sdir <<
"mkdir " <<
_dir;
194 std::cerr << _mdir.str() << _sdir.str() <<
" returned: " << ret
205template <
typename... Args>
211 auto _pos = _path.find_last_of(
'/');
212 if(_pos != std::string::npos)
214 _path = _path.substr(0, _pos);
215 _base = _base.substr(_pos + 1);
220 auto ret =
makedir(osrepr(_path));
225 _ofs.open(osrepr(_fpath), std::forward<Args>(
_args)...);
226 return (_ofs && _ofs.is_open() && _ofs.good());
#define TIMEMORY_DEFAULT_UMASK
int makedir(std::string _dir, int umask=0777)
bool open(std::ofstream &_ofs, std::string _fpath, Args &&... _args)
std::string & replace(std::string &_path, char _c, const char *_v)
std::string canonical(std::string _path)
const string_t const string_t & _dir
std::array< char *, 4 > _args
tim::mpl::apply< std::string > string
const std::string std::ostream * os
bool launch_process(const char *cmd, const std::string &extra="", std::ostream *os=nullptr)
void consume_parameters(ArgsT &&...)