From d03ab3ef276e4ee8fe4705100c3d1516eea338fc Mon Sep 17 00:00:00 2001 From: Alexander Wagner Date: Wed, 29 Nov 2023 20:28:45 +0100 Subject: [PATCH] - fixed Exist function on Linux --- code/Common/DefaultIOSystem.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/code/Common/DefaultIOSystem.cpp b/code/Common/DefaultIOSystem.cpp index b28910c70..1bda76e50 100644 --- a/code/Common/DefaultIOSystem.cpp +++ b/code/Common/DefaultIOSystem.cpp @@ -99,12 +99,12 @@ bool DefaultIOSystem::Exists(const char *pFile) const { return false; } #else - FILE *file = ::fopen(pFile, "rb"); - if (!file) { + struct stat statbuf; + stat(pFile, &statbuf); + // test for a regular file + if (!S_ISREG(statbuf.st_mode)){ return false; } - - ::fclose(file); #endif return true; @@ -116,6 +116,7 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) { ai_assert(strFile != nullptr); ai_assert(strMode != nullptr); FILE *file; + #ifdef _WIN32 std::wstring name = Utf8ToWide(strFile); if (name.empty()) { @@ -126,6 +127,7 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) { #else file = ::fopen(strFile, strMode); #endif + if (!file) { return nullptr; }