File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 30
30
#include < stack>
31
31
#include < stdexcept>
32
32
#include < string>
33
+ #include < sys/stat.h>
33
34
#if __cplusplus >= 201103L
34
35
#ifdef SIMPLECPP_WINDOWS
35
36
#include < mutex>
39
40
#include < utility>
40
41
#include < vector>
41
42
43
+ #ifdef _WIN32
44
+ using mode_t = unsigned short ;
45
+ #else
46
+ #include < sys/types.h>
47
+ #endif
48
+
42
49
#ifdef SIMPLECPP_WINDOWS
43
50
#include < windows.h>
44
51
#undef ERROR
@@ -3838,6 +3845,24 @@ std::string simplecpp::getCppStdString(const std::string &std)
3838
3845
return " " ;
3839
3846
}
3840
3847
3848
+ static mode_t file_type (const std::string &path)
3849
+ {
3850
+ struct stat file_stat;
3851
+ if (stat (path.c_str (), &file_stat) == -1 )
3852
+ return 0 ;
3853
+ return file_stat.st_mode & S_IFMT;
3854
+ }
3855
+
3856
+ bool simplecpp::isFile (const std::string &path)
3857
+ {
3858
+ return file_type (path) == S_IFREG;
3859
+ }
3860
+
3861
+ bool simplecpp::isDirectory (const std::string &path)
3862
+ {
3863
+ return file_type (path) == S_IFDIR;
3864
+ }
3865
+
3841
3866
#if (__cplusplus < 201103L) && !defined(__APPLE__)
3842
3867
#undef nullptr
3843
3868
#endif
Original file line number Diff line number Diff line change @@ -373,6 +373,20 @@ namespace simplecpp {
373
373
374
374
/* * Returns the __cplusplus value for a given standard */
375
375
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);
376
390
}
377
391
378
392
#if defined(_MSC_VER)
You can’t perform that action at this time.
0 commit comments