File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030#include < stack>
3131#include < stdexcept>
3232#include < string>
33+ #include < sys/stat.h>
3334#if __cplusplus >= 201103L
3435#ifdef SIMPLECPP_WINDOWS
3536#include < mutex>
3940#include < utility>
4041#include < vector>
4142
43+ #ifdef _WIN32
44+ using mode_t = unsigned short ;
45+ #else
46+ #include < sys/types.h>
47+ #endif
48+
4249#ifdef SIMPLECPP_WINDOWS
4350#include < windows.h>
4451#undef ERROR
@@ -3835,6 +3842,24 @@ std::string simplecpp::getCppStdString(const std::string &std)
38353842 return " " ;
38363843}
38373844
3845+ static mode_t file_type (const std::string &path)
3846+ {
3847+ struct stat file_stat;
3848+ if (stat (path.c_str (), &file_stat) == -1 )
3849+ return 0 ;
3850+ return file_stat.st_mode & S_IFMT;
3851+ }
3852+
3853+ bool simplecpp::isFile (const std::string &path)
3854+ {
3855+ return file_type (path) == S_IFREG;
3856+ }
3857+
3858+ bool simplecpp::isDirectory (const std::string &path)
3859+ {
3860+ return file_type (path) == S_IFDIR;
3861+ }
3862+
38383863#if (__cplusplus < 201103L) && !defined(__APPLE__)
38393864#undef nullptr
38403865#endif
Original file line number Diff line number Diff line change @@ -373,6 +373,20 @@ namespace simplecpp {
373373
374374 /* * Returns the __cplusplus value for a given standard */
375375 SIMPLECPP_LIB std::string getCppStdString (const std::string &std);
376+
377+ /* *
378+ * @brief Checks if given path is a file
379+ * @param path Path to be checked
380+ * @return true if given path is a file
381+ */
382+ SIMPLECPP_LIB bool isFile (const std::string &path);
383+
384+ /* *
385+ * @brief Checks if a given path is a directory
386+ * @param path Path to be checked
387+ * @return true if given path is a directory
388+ */
389+ SIMPLECPP_LIB bool isDirectory (const std::string &path);
376390}
377391
378392#if defined(_MSC_VER)
You can’t perform that action at this time.
0 commit comments