diff options
| -rwxr-xr-x | indra/llcommon/llfile.cpp | 12 | ||||
| -rwxr-xr-x | indra/llcommon/llfile.h | 3 |
2 files changed, 8 insertions, 7 deletions
diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index 3e469111fa..a1d41cdf73 100755 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -911,16 +911,16 @@ S64 LLFile::read(const std::string& filename, void* buf, S64 offset, S64 nbytes, std::ios_base::openmode omode = LLFile::in | LLFile::binary; LLFile file(filename, omode, ec); - if (file) + if (!ec && (bool)file) { - S64 bytes_read = 0; if (offset > 0) { file.seek(offset, ec); } + // else (offset == 0) file was just opened and should already be at 0. if (!ec) { - bytes_read = file.read(buf, nbytes, ec); + S64 bytes_read = file.read(buf, nbytes, ec); if (!ec) { return bytes_read; @@ -961,16 +961,16 @@ S64 LLFile::write(const std::string& filename, const void* buf, S64 offset, S64 } LLFile file(filename, omode, ec); - if (file) + if (!ec && (bool)file) { - S64 bytes_written = 0; if (offset > 0) { file.seek(offset, ec); } + // else (offset == 0) we are not appending, file was just opened and should already be at 0. if (!ec) { - bytes_written = file.write(buf, nbytes, ec); + S64 bytes_written = file.write(buf, nbytes, ec); if (!ec) { return bytes_written; diff --git a/indra/llcommon/llfile.h b/indra/llcommon/llfile.h index b007fcaf02..2c74c97d0b 100755 --- a/indra/llcommon/llfile.h +++ b/indra/llcommon/llfile.h @@ -343,7 +343,8 @@ public: /// write nBytes from the buffer into the file, starting at offset in the file static S64 write(const std::string& filename, const void* buf, S64 offset, S64 nbytes); static S64 write(const std::string& filename, const void* buf, S64 offset, S64 nbytes, std::error_code& ec); - ///< A negative offset will append the data to the end of the file + ///< If a negative offset is provided, the file is opened in append mode and the + /// write will be appended to the end of the file. /// @returns bytes written on success, or -1 on failure /// return the file stat structure for filename |
