summaryrefslogtreecommitdiff
path: root/src/common/utils.c
diff options
context:
space:
mode:
authorKenpachi Developer <Kenpachi.Developer@gmx.de>2020-02-08 00:31:56 +0100
committerHaru <haru@dotalux.com>2020-02-09 20:23:14 +0100
commitce21c1e9361e04391dc41463af24d5eb0c493bd1 (patch)
treeb0bcd3ce8a4e42bd6db4712df0955af75c9742d3 /src/common/utils.c
parent6e4c66213fca0fd482e1d983a4e3307f08619e5c (diff)
downloadhercules-ce21c1e9361e04391dc41463af24d5eb0c493bd1.tar.gz
hercules-ce21c1e9361e04391dc41463af24d5eb0c493bd1.tar.bz2
hercules-ce21c1e9361e04391dc41463af24d5eb0c493bd1.tar.xz
hercules-ce21c1e9361e04391dc41463af24d5eb0c493bd1.zip
Add is_file() function
Diffstat (limited to 'src/common/utils.c')
-rw-r--r--src/common/utils.c40
1 files changed, 40 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)