diff options
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/sys.cc | 33 | ||||
-rw-r--r-- | src/sys/sys.h | 5 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/sys/sys.cc b/src/sys/sys.cc index 59ed11d..01c9e3b 100644 --- a/src/sys/sys.cc +++ b/src/sys/sys.cc @@ -32,7 +32,38 @@ namespace sys { -bool isdirectory(const std::string &path) +bool file_exists(const std::string &filename) +{ +#ifdef _WIN32 + struct ::_stat path_stat; + memset(&path_stat, 0, sizeof(struct ::_stat)); + + if (::_stat(filename.c_str(), &path_stat) != 0) { + return false; + } + + if (path_stat.st_mode & _S_IFDIR) { + return false; + } + return true; +#else + struct stat path_stat; + memset(&path_stat, 0, sizeof(path_stat)); + + if (stat(filename.c_str(), &path_stat) != 0) { + return false; + } + + if (path_stat.st_mode & S_IFDIR) { + return false; + } + + return true; +#endif +} + + +bool directory_exists(const std::string &path) { #ifdef _WIN32 struct ::_stat path_stat; diff --git a/src/sys/sys.h b/src/sys/sys.h index 81eba94..5e41daa 100644 --- a/src/sys/sys.h +++ b/src/sys/sys.h @@ -22,7 +22,10 @@ namespace sys typedef void(* signalfunc)(int signum); /// returns true if a path exists and it is a directory -bool isdirectory(const std::string &path); +bool directory_exists(const std::string &path); + +/// returns true if a file exists +bool file_exists(const std::string &filename); /// create a directory void mkdir(const std::string &path); |