diff --git a/indra/llfilesystem/llfilesystem.cpp b/indra/llfilesystem/llfilesystem.cpp
index 2e2a97826c..c952cb2f1a 100644
--- a/indra/llfilesystem/llfilesystem.cpp
+++ b/indra/llfilesystem/llfilesystem.cpp
@@ -62,12 +62,20 @@ bool LLFileSystem::getExists(const LLUUID& file_id, const LLAssetType::EType fil
const std::string extra_info = "";
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id_str, file_type, extra_info);
- llifstream file(filename, std::ios::binary);
- if (file.is_open())
+ // IO-streams replacement
+ //llifstream file(filename, std::ios::binary);
+ //if (file.is_open())
+ //{
+ // file.seekg(0, std::ios::end);
+ // return file.tellg() > 0;
+ //}
+ llstat file_stat;
+ if (LLFile::stat(filename, &file_stat) == 0)
{
- file.seekg(0, std::ios::end);
- return file.tellg() > 0;
+ return S_ISREG(file_stat.st_mode) && file_stat.st_size > 0;
}
+ //
+
return false;
}
@@ -130,12 +138,19 @@ S32 LLFileSystem::getFileSize(const LLUUID& file_id, const LLAssetType::EType fi
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id_str, file_type, extra_info);
S32 file_size = 0;
- llifstream file(filename, std::ios::binary);
- if (file.is_open())
+ // IO-streams replacement
+ //llifstream file(filename, std::ios::binary);
+ //if (file.is_open())
+ //{
+ // file.seekg(0, std::ios::end);
+ // file_size = file.tellg();
+ //}
+ llstat file_stat;
+ if (LLFile::stat(filename, &file_stat) == 0)
{
- file.seekg(0, std::ios::end);
- file_size = file.tellg();
+ file_size = file_stat.st_size;
}
+ //
return file_size;
}
@@ -149,23 +164,37 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes)
const std::string extra_info = "";
const std::string filename = LLDiskCache::getInstance()->metaDataToFilepath(id, mFileType, extra_info);
- llifstream file(filename, std::ios::binary);
- if (file.is_open())
+ // IO-streams replacement
+ //llifstream file(filename, std::ios::binary);
+ //if (file.is_open())
+ //{
+ // file.seekg(mPosition, std::ios::beg);
+
+ // file.read((char*)buffer, bytes);
+
+ // if (file)
+ // {
+ // mBytesRead = bytes;
+ // }
+ // else
+ // {
+ // mBytesRead = file.gcount();
+ // }
+
+ // file.close();
+
+ // mPosition += mBytesRead;
+ // if (!mBytesRead)
+ // {
+ // success = FALSE;
+ // }
+ //}
+ LLFILE* file = LLFile::fopen(filename, "rb");
+ if (file)
{
- file.seekg(mPosition, std::ios::beg);
-
- file.read((char*)buffer, bytes);
-
- if (file)
- {
- mBytesRead = bytes;
- }
- else
- {
- mBytesRead = file.gcount();
- }
-
- file.close();
+ fseek(file, mPosition, SEEK_SET);
+ mBytesRead = fread(buffer, 1, bytes, file);
+ fclose(file);
mPosition += mBytesRead;
if (!mBytesRead)
@@ -173,6 +202,7 @@ BOOL LLFileSystem::read(U8* buffer, S32 bytes)
success = FALSE;
}
}
+ //
// update the last access time for the file - this is required
// even though we are reading and not writing because this is the
@@ -202,55 +232,102 @@ BOOL LLFileSystem::write(const U8* buffer, S32 bytes)
BOOL success = FALSE;
+ // IO-streams replacement
+ //if (mMode == APPEND)
+ //{
+ // llofstream ofs(filename, std::ios::app | std::ios::binary);
+ // if (ofs)
+ // {
+ // ofs.write((const char*)buffer, bytes);
+
+ // mPosition = ofs.tellp(); // Fix asset caching
+
+ // success = TRUE;
+ // }
+ //}
+ //// Fix asset caching
+ //else if (mMode == READ_WRITE)
+ //{
+ // // Don't truncate if file already exists
+ // llofstream ofs(filename, std::ios::in | std::ios::binary);
+ // if (ofs)
+ // {
+ // ofs.seekp(mPosition, std::ios::beg);
+ // ofs.write((const char*)buffer, bytes);
+ // mPosition += bytes;
+ // success = TRUE;
+ // }
+ // else
+ // {
+ // // File doesn't exist - open in write mode
+ // ofs.open(filename, std::ios::binary);
+ // if (ofs.is_open())
+ // {
+ // ofs.write((const char*)buffer, bytes);
+ // mPosition += bytes;
+ // success = TRUE;
+ // }
+ // }
+ //}
+ ////
+ //else
+ //{
+ // llofstream ofs(filename, std::ios::binary);
+ // if (ofs)
+ // {
+ // ofs.write((const char*)buffer, bytes);
+
+ // mPosition += bytes;
+
+ // success = TRUE;
+ // }
+ //}
if (mMode == APPEND)
{
- llofstream ofs(filename, std::ios::app | std::ios::binary);
+ LLFILE* ofs = LLFile::fopen(filename, "a+b");
if (ofs)
{
- ofs.write((const char*)buffer, bytes);
-
- mPosition = ofs.tellp(); // Fix asset caching
-
+ fwrite(buffer, 1, bytes, ofs);
+ mPosition = ftell(ofs);
+ fclose(ofs);
success = TRUE;
}
}
- // Fix asset caching
else if (mMode == READ_WRITE)
{
- // Don't truncate if file already exists
- llofstream ofs(filename, std::ios::in | std::ios::binary);
+ LLFILE* ofs = LLFile::fopen(filename, "r+b");
if (ofs)
{
- ofs.seekp(mPosition, std::ios::beg);
- ofs.write((const char*)buffer, bytes);
- mPosition += bytes;
+ fseek(ofs, mPosition, SEEK_SET);
+ fwrite(buffer, 1, bytes, ofs);
+ mPosition = ftell(ofs);
+ fclose(ofs);
success = TRUE;
}
else
{
- // File doesn't exist - open in write mode
- ofs.open(filename, std::ios::binary);
- if (ofs.is_open())
+ ofs = LLFile::fopen(filename, "wb");
+ if (ofs)
{
- ofs.write((const char*)buffer, bytes);
- mPosition += bytes;
+ fwrite(buffer, 1, bytes, ofs);
+ mPosition = ftell(ofs);
+ fclose(ofs);
success = TRUE;
}
}
}
- //
else
{
- llofstream ofs(filename, std::ios::binary);
+ LLFILE* ofs = LLFile::fopen(filename, "wb");
if (ofs)
{
- ofs.write((const char*)buffer, bytes);
-
- mPosition += bytes;
-
+ fwrite(buffer, 1, bytes, ofs);
+ mPosition = ftell(ofs);
+ fclose(ofs);
success = TRUE;
}
}
+ //
return success;
}