summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2020-02-09 21:18:26 +0100
committerGitHub <noreply@github.com>2020-02-09 21:18:26 +0100
commit481d92bfa0fac1320aebf0ab4f4ceb8365fa3ff3 (patch)
tree807314fa875ca53ab1508f347bcf5ad12e9f3348 /src/common
parent9e68350a054d5ec181a40528728d8de185a4f43c (diff)
parentd84aee4cd917fd1a151d7ec0b3a2d7e32df02441 (diff)
downloadhercules-481d92bfa0fac1320aebf0ab4f4ceb8365fa3ff3.tar.gz
hercules-481d92bfa0fac1320aebf0ab4f4ceb8365fa3ff3.tar.bz2
hercules-481d92bfa0fac1320aebf0ab4f4ceb8365fa3ff3.tar.xz
hercules-481d92bfa0fac1320aebf0ab4f4ceb8365fa3ff3.zip
Merge pull request #2590 from Kenpachi2k13/issue#2530
Change unload NPC behavior to kill mobs that were spawned by unloaded NPC (non-permanent monster spawns) [Issue #2530]
Diffstat (limited to 'src/common')
-rw-r--r--src/common/utils.c44
-rw-r--r--src/common/utils.h9
2 files changed, 50 insertions, 3 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index 48ce539b6..084080df7 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -132,7 +132,7 @@ void findfile(const char *p, const char *pat, void (func)(const char *, void *co
{
WIN32_FIND_DATAA FindFileData;
HANDLE hFind;
- char tmppath[MAX_PATH+1];
+ char tmppath[MAX_DIR_PATH + 1];
const char *path = (p ==NULL)? "." : p;
const char *pattern = (pat==NULL)? "" : pat;
@@ -166,9 +166,26 @@ void findfile(const char *p, const char *pat, void (func)(const char *, void *co
}
return;
}
-#else
-#define MAX_DIR_PATH 2048
+/**
+ * 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);
+
+ return ((GetFileAttributesA(path_tmp) & FILE_ATTRIBUTE_DIRECTORY) == 0);
+}
+
+#else
static char *checkpath(char *path, const char *srcpath)
{
@@ -235,6 +252,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..3e0d73e40 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -31,6 +31,14 @@
/* [HCache] 1-byte key to ensure our method is the latest, we can modify to ensure the method matches */
#define HCACHE_KEY 'k'
+#ifndef MAX_DIR_PATH
+#ifdef WIN32
+#define MAX_DIR_PATH MAX_PATH
+#else
+#define MAX_DIR_PATH 2048
+#endif
+#endif
+
//Caps values to min/max
#define cap_value(a, min, max) (((a) >= (max)) ? (max) : ((a) <= (min)) ? (min) : (a))
@@ -40,6 +48,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)