diff --git a/simplecpp.cpp b/simplecpp.cpp index ae64121..6f1d501 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #if __cplusplus >= 201103L #ifdef SIMPLECPP_WINDOWS #include @@ -40,6 +41,12 @@ #include #include +#ifdef _WIN32 +using mode_t = unsigned short; +#else +#include +#endif + #ifdef SIMPLECPP_WINDOWS #include #undef ERROR @@ -3880,6 +3887,24 @@ std::string simplecpp::getCppStdString(const std::string &std) return getCppStdString(getCppStd(std)); } +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 f5c6959..d6b27ab 100755 --- a/simplecpp.h +++ b/simplecpp.h @@ -389,6 +389,20 @@ namespace simplecpp { /** Returns the __cplusplus value for a given standard */ SIMPLECPP_LIB std::string getCppStdString(const std::string &std); SIMPLECPP_LIB std::string getCppStdString(cppstd_t 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)