File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 31
31
#include < stack>
32
32
#include < stdexcept>
33
33
#include < string>
34
+ #include < sys/stat.h>
34
35
#if __cplusplus >= 201103L
35
36
#ifdef SIMPLECPP_WINDOWS
36
37
#include < mutex>
42
43
43
44
#ifdef _WIN32
44
45
#include < direct.h>
46
+ using mode_t = unsigned short ;
45
47
#else
46
48
#include < unistd.h>
49
+ #include < sys/types.h>
47
50
#endif
48
51
49
52
#ifdef SIMPLECPP_WINDOWS
@@ -153,7 +156,7 @@ static unsigned long long stringToULL(const std::string &s)
153
156
return ret;
154
157
}
155
158
156
- // TODO: added an undercore since this conflicts with a function of the same name in utils.h from Cppcheck source when building Cppcheck with MSBuild
159
+ // TODO: added an undercore since this conflicts with a function of the same name in utils.h from Cppcheck source when building Cppcheck with MSBuild
157
160
static bool startsWith_ (const std::string &s, const std::string &p)
158
161
{
159
162
return (s.size () >= p.size ()) && std::equal (p.begin (), p.end (), s.begin ());
@@ -4103,6 +4106,24 @@ std::string simplecpp::getCppStdString(const std::string &std)
4103
4106
return getCppStdString (getCppStd (std));
4104
4107
}
4105
4108
4109
+ static mode_t file_type (const std::string &path)
4110
+ {
4111
+ struct stat file_stat;
4112
+ if (stat (path.c_str (), &file_stat) == -1 )
4113
+ return 0 ;
4114
+ return file_stat.st_mode & S_IFMT;
4115
+ }
4116
+
4117
+ bool simplecpp::isFile (const std::string &path)
4118
+ {
4119
+ return file_type (path) == S_IFREG;
4120
+ }
4121
+
4122
+ bool simplecpp::isDirectory (const std::string &path)
4123
+ {
4124
+ return file_type (path) == S_IFDIR;
4125
+ }
4126
+
4106
4127
#if (__cplusplus < 201103L) && !defined(__APPLE__)
4107
4128
#undef nullptr
4108
4129
#endif
Original file line number Diff line number Diff line change @@ -389,6 +389,20 @@ namespace simplecpp {
389
389
/* * Returns the __cplusplus value for a given standard */
390
390
SIMPLECPP_LIB std::string getCppStdString (const std::string &std);
391
391
SIMPLECPP_LIB std::string getCppStdString (cppstd_t std);
392
+
393
+ /* *
394
+ * @brief Checks if given path is a file
395
+ * @param path Path to be checked
396
+ * @return true if given path is a file
397
+ */
398
+ SIMPLECPP_LIB bool isFile (const std::string &path);
399
+
400
+ /* *
401
+ * @brief Checks if a given path is a directory
402
+ * @param path Path to be checked
403
+ * @return true if given path is a directory
404
+ */
405
+ SIMPLECPP_LIB bool isDirectory (const std::string &path);
392
406
}
393
407
394
408
#if defined(_MSC_VER)
You can’t perform that action at this time.
0 commit comments