summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/utils.c40
-rw-r--r--src/common/utils.h1
2 files changed, 41 insertions, 0 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index 48ce539b6..12810dd09 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -166,6 +166,25 @@ void findfile(const char *p, const char *pat, void (func)(const char *, void *co
}
return;
}
+
+/**
+ * Checks if the passed path points to a file.
+ *
+ * @param path The path which should be checked.
+ * @return true if the passed path points to a file, otherwise false.
+ *
+ **/
+bool is_file(const char *path)
+{
+ nullpo_retr(false, path);
+
+ char path_tmp[MAX_PATH + 1];
+
+ checkpath(path_tmp, path);
+
+ return ((GetFileAttributesA(path_tmp) & FILE_ATTRIBUTE_DIRECTORY) == 0);
+}
+
#else
#define MAX_DIR_PATH 2048
@@ -235,6 +254,27 @@ void findfile(const char *p, const char *pat, void (func)(const char *, void *co
closedir(dir);
}
+
+/**
+ * Checks if the passed path points to a file.
+ *
+ * @param path The path which should be checked.
+ * @return true if the passed path points to a file, otherwise false.
+ *
+ **/
+bool is_file(const char *path)
+{
+ nullpo_retr(false, path);
+
+ char path_tmp[MAX_DIR_PATH + 1];
+
+ checkpath(path_tmp, path);
+
+ struct stat path_stat;
+
+ return (stat(path_tmp, &path_stat) == 0 && S_ISREG(path_stat.st_mode));
+}
+
#endif
bool exists(const char *filename)
diff --git a/src/common/utils.h b/src/common/utils.h
index a0590db7f..b160d3651 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -40,6 +40,7 @@ void WriteDump(FILE* fp, const void* buffer, size_t length);
void ShowDump(const void* buffer, size_t length);
void findfile(const char *p, const char *pat, void (func)(const char *, void *), void *context);
+bool is_file(const char *path);
bool exists(const char* filename);
/// calculates the value of A / B, in percent (rounded down)