12 bool is_dir(const char *path) {
15 if (_stat(path, &info) != 0) {
18 return (info.st_mode & _S_IFDIR) != 0;
21 if (stat(path, &info) != 0) {
24 return S_ISDIR(info.st_mode);
28 bool is_file(const char *path) {
31 if (_stat(path, &info) != 0) {
34 return (info.st_mode & _S_IFREG) != 0;
37 if (stat(path, &info) != 0) {
40 return S_ISREG(info.st_mode);
45 bool make_dir(const char *path) {
47 int ret = _mkdir(path);
49 int ret = mkdir(path, 0777);
55 bool make_dirs(const std::string &path) {
66 auto pos = path.find_last_of("\\/");
68 auto pos = path.find_last_of('/');
70 if (pos == std::string::npos) {
73 if (pos == path.length() - 1) {
74 // trailing separator, would make final make_dir fail
76 pos = path.find_last_of("\\/", pos - 1);
78 pos = path.find_last_of('/', pos - 1);
80 if (pos == std::string::npos) {
84 if (!make_dirs(path.substr(0, pos))) {
89 return make_dir(path);
92 // something's there, check if it's a dir and we're good
96 // whatever else went wrong, it can't be good