Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cocos/platform/CCFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,20 +669,21 @@ FileUtils::Status FileUtils::getContents(const std::string& filename, ResizableB
if (fullPath.empty())
return Status::NotExists;

FILE *fp = fopen(fs->getSuitableFOpen(fullPath).c_str(), "rb");
if (!fp)
return Status::OpenFailed;
std::string suitableFullPath = fs->getSuitableFOpen(fullPath);

#if defined(_MSC_VER)
auto descriptor = _fileno(fp);
#else
auto descriptor = fileno(fp);
#endif
struct stat statBuf;
if (fstat(descriptor, &statBuf) == -1) {
fclose(fp);
if (stat(suitableFullPath.c_str(), &statBuf) == -1) {
return Status::ReadFailed;
}

if (!(statBuf.st_mode & S_IFREG)) {
return Status::NotRegularFileType;
}

FILE *fp = fopen(suitableFullPath.c_str(), "rb");
if (!fp)
return Status::OpenFailed;

size_t size = statBuf.st_size;

buffer->resize(size);
Expand Down
3 changes: 2 additions & 1 deletion cocos/platform/CCFileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class CC_DLL FileUtils
ReadFailed = 3, // Read failed
NotInitialized = 4, // FileUtils is not initializes
TooLarge = 5, // The file is too large (great than 2^32-1)
ObtainSizeFailed = 6 // Failed to obtain the file size.
ObtainSizeFailed = 6, // Failed to obtain the file size.
NotRegularFileType = 7 // File type is not S_IFREG
};

/**
Expand Down