- fixed Exist function on Linux

pull/5391/head
Alexander Wagner 2023-11-29 20:28:45 +01:00 committed by Kim Kulling
parent e86f1acb9b
commit d03ab3ef27
1 changed files with 6 additions and 4 deletions

View File

@ -99,12 +99,12 @@ bool DefaultIOSystem::Exists(const char *pFile) const {
return false; return false;
} }
#else #else
FILE *file = ::fopen(pFile, "rb"); struct stat statbuf;
if (!file) { stat(pFile, &statbuf);
// test for a regular file
if (!S_ISREG(statbuf.st_mode)){
return false; return false;
} }
::fclose(file);
#endif #endif
return true; return true;
@ -116,6 +116,7 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) {
ai_assert(strFile != nullptr); ai_assert(strFile != nullptr);
ai_assert(strMode != nullptr); ai_assert(strMode != nullptr);
FILE *file; FILE *file;
#ifdef _WIN32 #ifdef _WIN32
std::wstring name = Utf8ToWide(strFile); std::wstring name = Utf8ToWide(strFile);
if (name.empty()) { if (name.empty()) {
@ -126,6 +127,7 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) {
#else #else
file = ::fopen(strFile, strMode); file = ::fopen(strFile, strMode);
#endif #endif
if (!file) { if (!file) {
return nullptr; return nullptr;
} }