fixed file_exists and dir_exists

This commit is contained in:
timerix 2023-03-13 19:30:13 +06:00
parent 965c784e37
commit 0adea8c52c
2 changed files with 4 additions and 4 deletions

View File

@ -12,13 +12,13 @@ bool dir_exists(const char* path){
#if KFS_USE_WINDOWS_H #if KFS_USE_WINDOWS_H
DWORD dwAttrib = GetFileAttributes(path); DWORD dwAttrib = GetFileAttributes(path);
return (bool)( return (bool)(
(dwAttrib != INVALID_FILE_ATTRIBUTES) & // file exists (dwAttrib != INVALID_FILE_ATTRIBUTES) && // file exists
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is a directory (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is a directory
#else #else
struct stat stats; struct stat stats;
i32 rez=stat(path, &stats); i32 rez=stat(path, &stats);
return (bool)( return (bool)(
(rez!=-1) & // file exists (rez!=-1) && // file exists
(S_ISDIR(stats.st_mode))); // file is a directory (S_ISDIR(stats.st_mode))); // file is a directory
#endif #endif
} }

View File

@ -15,13 +15,13 @@ bool file_exists(const char* path){
#if KFS_USE_WINDOWS_H #if KFS_USE_WINDOWS_H
DWORD dwAttrib = GetFileAttributes(path); DWORD dwAttrib = GetFileAttributes(path);
return (bool)( return (bool)(
(dwAttrib != INVALID_FILE_ATTRIBUTES) & // file exists (dwAttrib != INVALID_FILE_ATTRIBUTES) && // file exists
!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is not directory !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // file is not directory
#else #else
struct stat stats; struct stat stats;
i32 rez=stat(path, &stats); i32 rez=stat(path, &stats);
return (bool)( return (bool)(
(rez!=-1) & // file exists (rez!=-1) && // file exists
!(S_ISDIR(stats.st_mode))); // file is not directory !(S_ISDIR(stats.st_mode))); // file is not directory
#endif #endif
} }