File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 4242
4343#ifdef _WIN32
4444# include < direct.h>
45+ using mode_t = unsigned short ;
4546#else
4647# include < sys/stat.h>
48+ # include < sys/types.h>
4749#endif
4850
4951static bool isHex (const std::string &s)
@@ -3838,3 +3840,21 @@ std::string simplecpp::getCppStdString(const std::string &std)
38383840{
38393841 return getCppStdString (getCppStd (std));
38403842}
3843+
3844+ static mode_t file_type (const std::string &path)
3845+ {
3846+ struct stat file_stat;
3847+ if (stat (path.c_str (), &file_stat) == -1 )
3848+ return 0 ;
3849+ return file_stat.st_mode & S_IFMT;
3850+ }
3851+
3852+ bool simplecpp::isFile (const std::string &path)
3853+ {
3854+ return file_type (path) == S_IFREG;
3855+ }
3856+
3857+ bool simplecpp::isDirectory (const std::string &path)
3858+ {
3859+ return file_type (path) == S_IFDIR;
3860+ }
Original file line number Diff line number Diff line change @@ -353,6 +353,20 @@ namespace simplecpp {
353353 bool removeComments; /* * remove comment tokens from included files */
354354 };
355355
356+ /* *
357+ * @brief Checks if given path is a file
358+ * @param path Path to be checked
359+ * @return true if given path is a file
360+ */
361+ SIMPLECPP_LIB bool isFile (const std::string &path);
362+
363+ /* *
364+ * @brief Checks if a given path is a directory
365+ * @param path Path to be checked
366+ * @return true if given path is a directory
367+ */
368+ SIMPLECPP_LIB bool isDirectory (const std::string &path);
369+
356370 struct SIMPLECPP_LIB FileData {
357371 /* * The canonical filename associated with this data */
358372 std::string filename;
You can’t perform that action at this time.
0 commit comments