From bceabe87c1cf565dde23d4674d97a614a9587087 Mon Sep 17 00:00:00 2001 From: rh101 Date: Mon, 26 Apr 2021 01:44:50 +1000 Subject: [PATCH] Use FileStream instead of fopen to check if file can be opened in read mode --- cocos/platform/linux/CCDevice-linux.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cocos/platform/linux/CCDevice-linux.cpp b/cocos/platform/linux/CCDevice-linux.cpp index 806f45ed23..639f6539b5 100644 --- a/cocos/platform/linux/CCDevice-linux.cpp +++ b/cocos/platform/linux/CCDevice-linux.cpp @@ -345,11 +345,10 @@ public: std::string lowerCasePath = fontPath; std::transform(lowerCasePath.begin(), lowerCasePath.end(), lowerCasePath.begin(), ::tolower); if ( lowerCasePath.find(".ttf") != std::string::npos ) { - fontPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fontPath.c_str()); - - FILE *f = fopen(fontPath.c_str(), "r"); - if ( f ) { - fclose(f); + fontPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fontPath); + auto* fileStream = cocos2d::FileUtils::getInstance()->openFileStream(fontPath, FileStream::Mode::READ); + if ( fileStream ) { + delete fileStream; fontCache.insert(std::pair(family_name, fontPath)); return fontPath; }