diff options
Diffstat (limited to 'src/sys/sys.cc')
-rw-r--r-- | src/sys/sys.cc | 33 |
1 files changed, 32 insertions, 1 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; |