diff --git a/simplecpp.cpp b/simplecpp.cpp index 156665f..66859d3 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #if __cplusplus >= 201103L #ifdef SIMPLECPP_WINDOWS #include @@ -39,6 +40,12 @@ #include #include +#ifdef _WIN32 +using mode_t = unsigned short; +#else +#include +#endif + #ifdef SIMPLECPP_WINDOWS #include #undef ERROR @@ -3838,6 +3845,24 @@ std::string simplecpp::getCppStdString(const std::string &std) return ""; } +static mode_t file_type(const std::string &path) +{ + struct stat file_stat; + if (stat(path.c_str(), &file_stat) == -1) + return 0; + return file_stat.st_mode & S_IFMT; +} + +bool simplecpp::isFile(const std::string &path) +{ + return file_type(path) == S_IFREG; +} + +bool simplecpp::isDirectory(const std::string &path) +{ + return file_type(path) == S_IFDIR; +} + #if (__cplusplus < 201103L) && !defined(__APPLE__) #undef nullptr #endif diff --git a/simplecpp.h b/simplecpp.h index 398024d..c2938be 100755 --- a/simplecpp.h +++ b/simplecpp.h @@ -373,6 +373,20 @@ namespace simplecpp { /** Returns the __cplusplus value for a given standard */ SIMPLECPP_LIB std::string getCppStdString(const std::string &std); + + /** + * @brief Checks if given path is a file + * @param path Path to be checked + * @return true if given path is a file + */ + SIMPLECPP_LIB bool isFile(const std::string &path); + + /** + * @brief Checks if a given path is a directory + * @param path Path to be checked + * @return true if given path is a directory + */ + SIMPLECPP_LIB bool isDirectory(const std::string &path); } #if defined(_MSC_VER)