1 #include "filesystem.hpp"
14 using Stat = struct _stat;
15 int do_stat(const char *path, Stat &info) {
16 return _stat(path, &info);
18 bool is_dir(const Stat &info) {
19 return (info.st_mode & _S_IFDIR) != 0;
21 bool is_file(const Stat &info) {
22 return (info.st_mode & _S_IFEG) != 0;
25 using Stat = struct stat;
26 int do_stat(const char *path, Stat &info) {
27 return stat(path, &info);
29 bool is_dir(const Stat &info) {
30 return S_ISDIR(info.st_mode);
32 bool is_file(const Stat &info) {
33 return S_ISREG(info.st_mode);
36 std::time_t get_mtime(const Stat &info) {
38 return info.st_mtimespec.tv_sec;
45 bool is_dir(const char *path) {
47 if (do_stat(path, info) != 0) {
53 bool is_file(const char *path) {
55 if (do_stat(path, info) != 0) {
61 std::time_t file_mtime(const char *path) {
63 if (do_stat(path, info) != 0) {
66 return get_mtime(info);
70 bool make_dir(const char *path) {
72 int ret = _mkdir(path);
74 int ret = mkdir(path, 0777);
80 bool make_dirs(const std::string &path) {
91 auto pos = path.find_last_of("\\/");
93 auto pos = path.find_last_of('/');
95 if (pos == std::string::npos) {
98 if (pos == path.length() - 1) {
99 // trailing separator, would make final make_dir fail
101 pos = path.find_last_of("\\/", pos - 1);
103 pos = path.find_last_of('/', pos - 1);
105 if (pos == std::string::npos) {
109 if (!make_dirs(path.substr(0, pos))) {
114 return make_dir(path);
117 // something's there, check if it's a dir and we're good
121 // whatever else went wrong, it can't be good