Skip to content
Snippets Groups Projects
Commit 1b8caf51 authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Replace C++ stream io with C io in LLFileSystem

parent 88a4d9c3
No related branches found
No related tags found
No related merge requests found
...@@ -52,11 +52,10 @@ bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType fil ...@@ -52,11 +52,10 @@ bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType fil
{ {
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type); const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type);
llifstream file(filename, std::ios::binary); llstat stat;
if (file.is_open()) if (LLFile::stat(filename, &stat) == 0)
{ {
file.seekg(0, std::ios::end); return S_ISREG(stat.st_mode) && stat.st_size > 0;
return file.tellg() > 0;
} }
return false; return false;
} }
...@@ -99,11 +98,10 @@ S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType fi ...@@ -99,11 +98,10 @@ S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType fi
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type); const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(file_id, file_type);
S32 file_size = 0; S32 file_size = 0;
llifstream file(filename, std::ios::binary); llstat stat;
if (file.is_open()) if (LLFile::stat(filename, &stat) == 0)
{ {
file.seekg(0, std::ios::end); file_size = stat.st_size;
file_size = file.tellg();
} }
return file_size; return file_size;
...@@ -115,29 +113,45 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes) ...@@ -115,29 +113,45 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes)
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(mFileID, mFileType); const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(mFileID, mFileType);
llifstream file(filename, std::ios::binary); LLUniqueFile filep = LLFile::fopen(filename, "rb");
if (file.is_open()) if (filep)
{ {
file.seekg(mPosition, std::ios::beg); fseek(filep, mPosition, SEEK_SET);
if (fread((void*)buffer, bytes, 1, filep) > 0)
file.read((char*)buffer, bytes);
if (file)
{ {
mBytesRead = bytes; mBytesRead = bytes;
} }
else else
{ {
mBytesRead = file.gcount(); fseek(filep, 0L, SEEK_END);
long fsize = ftell(filep);
fseek(filep, mPosition, SEEK_SET);
if (mPosition < fsize)
{
long rsize = fsize - mPosition;
if (fread((void*)buffer, rsize, 1, filep) > 0)
{
mBytesRead = rsize;
}
else
{
success = FALSE;
}
}
else
{
success = FALSE;
}
} }
file.close(); if (!success)
mPosition += mBytesRead;
if (!mBytesRead)
{ {
success = FALSE; mBytesRead = 0;
} }
filep.close();
mPosition += mBytesRead;
} }
// update the last access time for the file - this is required // update the last access time for the file - this is required
...@@ -167,20 +181,20 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes) ...@@ -167,20 +181,20 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes)
if (mMode == APPEND) if (mMode == APPEND)
{ {
llofstream ofs(filename, std::ios::app | std::ios::binary); LLUniqueFile filep = LLFile::fopen(filename, "ab");
if (ofs) if (filep)
{ {
ofs.write((const char*)buffer, bytes); fwrite((const void*)buffer, bytes, 1, filep);
success = TRUE; success = TRUE;
} }
} }
else else
{ {
llofstream ofs(filename, std::ios::binary); LLUniqueFile filep = LLFile::fopen(filename, "wb");
if (ofs) if (filep)
{ {
ofs.write((const char*)buffer, bytes); fwrite((const void*)buffer, bytes, 1, filep);
mPosition += bytes; mPosition += bytes;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment