From 0b4fad3cca4b1c93a5f7f795274536d9a894efbe Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 9 Aug 2025 21:26:15 +0200 Subject: [PATCH] use GetFileAttributes instead of stat for filesearch on windows this is slightly faster and the recommended way of doing this apparently stat on windows has to emulate some POSIX stuff for that which may slow it down --- src/filesrch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/filesrch.c b/src/filesrch.c index 69c1fce68..35fbefc8a 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -484,9 +484,11 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want // FIXME: should we also follow symlinks? if ((dent->d_type == DT_DIR && depthleft) || (dent->d_type == DT_LNK && depthleft)) #else - if (stat(searchpath, &fsstat) < 0) // do we want to follow symlinks? if not: change it to lstat + // if we wanna follow symlinks we can check with FILE_ATTRIBUTE_REPARSE_POINT + DWORD fileattr = GetFileAttributes(searchpath); + if (fileattr == INVALID_FILE_ATTRIBUTES) ; // was the file (re)moved? can't stat it - else if (S_ISDIR(fsstat.st_mode) && depthleft) + else if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) && depthleft) #endif { searchpathindex[--depthleft] = strlen(searchpath) + 1;