summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Martian <fredmartian@gmail.com>2025-12-09 22:11:14 +0100
committerAndrey Kleshchev <117672381+akleshchev@users.noreply.github.com>2025-12-10 20:33:58 +0200
commit4153d676839aff0055937d346fcee995f62083f7 (patch)
tree964fe3cd954cf941c208d8bd3bce0a54265327c0
parent9aff5ff403ab8bba071c7a5c75b664399fbfe482 (diff)
Make function documentation more clear about the negative offset value.
Improve error checking inside function and add comment about not updating the seek pointer when an offset of 0 is specified
-rwxr-xr-xindra/llcommon/llfile.cpp12
-rwxr-xr-xindra/llcommon/llfile.h3
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