summaryrefslogtreecommitdiff
path: root/indra/llcommon/llfile.cpp
diff options
context:
space:
mode:
authorFrederick Martian <fredmartian@gmail.com>2025-10-25 17:08:35 +0200
committerAndrey Kleshchev <117672381+akleshchev@users.noreply.github.com>2025-12-10 20:33:58 +0200
commit3ca3ea75c333078013914e174564340f894573e2 (patch)
treec12dfa3492102e87c153a997d946c1d173a35666 /indra/llcommon/llfile.cpp
parent79f21027371f32a9268ce8d944e3d4727ddd8b55 (diff)
Add a new static function LLFile::size() to determine the size of a file_name.
Replace LLAPRFile::remove(), LLAPRFile::size() and LLAPRFile::isExist() with according functions from LLFile and retire these LLAPRFile methods and the never used LLAPRFile::rename(), LLAPRFile::makeDir() and LLAPRFile::removeDir() functions. Also clean up remarks about the threading safety of the APRCachePool, which is not used in these locations anymore.
Diffstat (limited to 'indra/llcommon/llfile.cpp')
-rw-r--r--indra/llcommon/llfile.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp
index a539e4fe28..4ef39674c2 100644
--- a/indra/llcommon/llfile.cpp
+++ b/indra/llcommon/llfile.cpp
@@ -498,6 +498,45 @@ int LLFile::stat(const std::string& filename, llstat* filestatus, int suppress_e
}
// static
+S64 LLFile::size(const std::string& filename, int suppress_error)
+{
+#if LL_WINDOWS
+ std::wstring utf16filename = utf8path_to_wstring(filename);
+ HANDLE file_handle = CreateFileW(utf16filename.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (INVALID_HANDLE_VALUE != file_handle)
+ {
+ LARGE_INTEGER file_size;
+ if (GetFileSizeEx(file_handle, &file_size))
+ {
+ CloseHandle(file_handle);
+ return file_size.QuadPart;
+ }
+ }
+ // Get last error before calling the CloseHandle() function
+ int rc = set_errno_from_oserror(GetLastError());
+ if (INVALID_HANDLE_VALUE != file_handle)
+ {
+ CloseHandle(file_handle);
+ }
+#else
+ llstat filestatus;
+ int rc = ::stat(filename.c_str(), &filestatus);
+ if (rc == 0)
+ {
+ if (S_ISREG(filestatus.st_mode)
+ {
+ return filestatus.st_size;
+ }
+ // We got something else than a file
+ rc = -1;
+ errno = EACCES;
+ }
+#endif
+ warnif("size", filename, rc, suppress_error);
+ return 0;
+}
+
+// static
unsigned short LLFile::getattr(const std::string& filename, bool dontFollowSymLink, int suppress_error)
{
#if LL_WINDOWS