Skip to content

Commit 76dba36

Browse files
committed
Replace boost dependency with simple mkdir -p implementation
1 parent 3f87bb2 commit 76dba36

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/util/file_util.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ Date: January 2012
4545
#include <cstring>
4646
#endif
4747

48-
#ifdef USE_BOOST
49-
#include <boost/filesystem.hpp>
50-
#endif
51-
5248
#include "file_util.h"
5349

5450

@@ -238,18 +234,26 @@ std::string fileutl_remove_extension(std::string const &filename)
238234
void fileutl_create_directory(std::string const &pathname)
239235
{
240236
# if defined(WIN32)
241-
std::system((std::string("mkdir \"") + pathname + "\"").c_str());
242-
# elif defined(__linux__) || defined(__APPLE__)
243-
#ifdef USE_BOOST
244-
boost::filesystem::create_directories(pathname);
237+
char path_sep='\\';
245238
#else
246-
auto ignore = std::system(
247-
(std::string("mkdir -p \"") + pathname + "\"").c_str());
248-
(void)ignore;
239+
char path_sep='/';
249240
#endif
250-
# else
251-
# error "Unsuported platform."
252-
# endif
241+
std::size_t search_from=0;
242+
while(search_from!=std::string::npos)
243+
{
244+
// Search from after the previous path separator, incidentally
245+
// skipping trying to create '/' if an absolute path is given
246+
search_from=pathname.find(path_sep, search_from+1);
247+
std::string truncated_pathname=pathname.substr(0, search_from);
248+
#if defined(WIN32)
249+
_mkdir(truncated_pathname.c_str());
250+
#else
251+
mkdir(truncated_pathname.c_str(), 0777);
252+
#endif
253+
// Ignore return-- regardless of why we can't create a
254+
// path prefix, we might as well keep trying down to more
255+
// specific paths.
256+
}
253257
}
254258

255259
std::string fileutl_concatenate_file_paths(

0 commit comments

Comments
 (0)