summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorMerov Linden <merov@lindenlab.com>2015-04-09 16:51:02 -0700
committerMerov Linden <merov@lindenlab.com>2015-04-09 16:51:02 -0700
commit8952e8177528fe0eee65916b9e12c3183f15e392 (patch)
tree3625cecb6fd90bf0de23021c22b5d805527af131 /indra/llcommon
parent47a3aecc97faa6ecb5267dde4274f0fe417e8409 (diff)
parent6b9b4c91d122dccabf7541af70ed68a623ad8810 (diff)
Merge lindenlab/viewer-tools-update
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-xindra/llcommon/llerror.cpp6
-rwxr-xr-xindra/llcommon/llfile.cpp270
-rwxr-xr-xindra/llcommon/llfile.h249
-rwxr-xr-xindra/llcommon/llliveappconfig.cpp2
-rwxr-xr-xindra/llcommon/lllivefile.cpp85
-rwxr-xr-xindra/llcommon/llstring.cpp2
6 files changed, 51 insertions, 563 deletions
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp
index 8119b14887..3cb81b4e47 100755
--- a/indra/llcommon/llerror.cpp
+++ b/indra/llcommon/llerror.cpp
@@ -113,7 +113,7 @@ namespace {
public:
RecordToFile(const std::string& filename)
{
- mFile.open(filename, llofstream::out | llofstream::app);
+ mFile.open(filename.c_str(), std::ios_base::out | std::ios_base::app);
if (!mFile)
{
LL_INFOS() << "Error setting log file to " << filename << LL_ENDL;
@@ -135,7 +135,7 @@ namespace {
}
private:
- llofstream mFile;
+ std::ofstream mFile;
};
@@ -335,7 +335,7 @@ namespace
LLSD configuration;
{
- llifstream file(filename());
+ std::ifstream file(filename().c_str());
if (file.is_open())
{
LLSDSerialize::fromXML(configuration, file);
diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp
index 304d702979..ab432a923d 100755
--- a/indra/llcommon/llfile.cpp
+++ b/indra/llcommon/llfile.cpp
@@ -865,273 +865,3 @@ int llstdio_filebuf::sync()
}
#endif
-/************** input file stream ********************************/
-
-
-llifstream::llifstream() : _M_filebuf(),
-#if LL_WINDOWS
- std::istream(&_M_filebuf) {}
-#else
- std::istream()
-{
- this->init(&_M_filebuf);
-}
-#endif
-
-// explicit
-llifstream::llifstream(const std::string& _Filename,
- ios_base::openmode _Mode) : _M_filebuf(),
-#if LL_WINDOWS
- std::istream(&_M_filebuf)
-{
- llutf16string wideName = utf8str_to_utf16str( _Filename );
- if (_M_filebuf.open(wideName.c_str(), _Mode | ios_base::in) == 0)
- {
- _Myios::setstate(ios_base::failbit);
- }
-}
-#else
- std::istream()
-{
- this->init(&_M_filebuf);
- this->open(_Filename.c_str(), _Mode | ios_base::in);
-}
-#endif
-
-// explicit
-llifstream::llifstream(const char* _Filename,
- ios_base::openmode _Mode) : _M_filebuf(),
-#if LL_WINDOWS
- std::istream(&_M_filebuf)
-{
- llutf16string wideName = utf8str_to_utf16str( _Filename );
- if (_M_filebuf.open(wideName.c_str(), _Mode | ios_base::in) == 0)
- {
- _Myios::setstate(ios_base::failbit);
- }
-}
-#else
- std::istream()
-{
- this->init(&_M_filebuf);
- this->open(_Filename, _Mode | ios_base::in);
-}
-#endif
-
-
-#if llstream_LLFILE
-// explicit
-llifstream::llifstream(_Filet *_File,
- ios_base::openmode _Mode, size_t _Size) :
- _M_filebuf(_File, _Mode, _Size),
-#if LL_WINDOWS
- std::istream(&_M_filebuf) {}
-#else
- std::istream()
-{
- this->init(&_M_filebuf);
-}
-#endif
-
-#if !LL_WINDOWS
-// explicit
-llifstream::llifstream(int __fd,
- ios_base::openmode _Mode, size_t _Size) :
- _M_filebuf(__fd, _Mode, _Size),
- std::istream()
-{
- this->init(&_M_filebuf);
-}
-#endif
-#endif // llstream_LLFILE
-
-bool llifstream::is_open() const
-{ // test if C stream has been opened
- return _M_filebuf.is_open();
-}
-
-void llifstream::open(const char* _Filename, ios_base::openmode _Mode)
-{ // open a C stream with specified mode
-
-#if LL_WINDOWS
- llutf16string wideName = utf8str_to_utf16str( _Filename );
- if (_M_filebuf.open( wideName.c_str(), _Mode | ios_base::in) == 0)
- {
- _Myios::setstate(ios_base::failbit);
- }
- else
- {
- _Myios::clear();
- }
-#else
- if (_M_filebuf.open(_Filename, _Mode | ios_base::in) == 0)
- {
- this->setstate(ios_base::failbit);
- }
- else
- {
- this->clear();
- }
-#endif
-}
-
-void llifstream::close()
-{ // close the C stream
- if (_M_filebuf.close() == 0)
- {
-#if LL_WINDOWS
- _Myios::setstate(ios_base::failbit);
-#else
- this->setstate(ios_base::failbit);
-#endif
- }
-}
-
-
-/************** output file stream ********************************/
-
-
-llofstream::llofstream() : _M_filebuf(),
-#if LL_WINDOWS
- std::ostream(&_M_filebuf) {}
-#else
- std::ostream()
-{
- this->init(&_M_filebuf);
-}
-#endif
-
-// explicit
-llofstream::llofstream(const std::string& _Filename,
- ios_base::openmode _Mode) : _M_filebuf(),
-#if LL_WINDOWS
- std::ostream(&_M_filebuf)
-{
- llutf16string wideName = utf8str_to_utf16str( _Filename );
- if (_M_filebuf.open( wideName.c_str(), _Mode | ios_base::out) == 0)
- {
- _Myios::setstate(ios_base::failbit);
- }
-}
-#else
- std::ostream()
-{
- this->init(&_M_filebuf);
- this->open(_Filename.c_str(), _Mode | ios_base::out);
-}
-#endif
-
-// explicit
-llofstream::llofstream(const char* _Filename,
- ios_base::openmode _Mode) : _M_filebuf(),
-#if LL_WINDOWS
- std::ostream(&_M_filebuf)
-{
- llutf16string wideName = utf8str_to_utf16str( _Filename );
- if (_M_filebuf.open( wideName.c_str(), _Mode | ios_base::out) == 0)
- {
- _Myios::setstate(ios_base::failbit);
- }
-}
-#else
- std::ostream()
-{
- this->init(&_M_filebuf);
- this->open(_Filename, _Mode | ios_base::out);
-}
-#endif
-
-#if llstream_LLFILE
-// explicit
-llofstream::llofstream(_Filet *_File,
- ios_base::openmode _Mode, size_t _Size) :
- _M_filebuf(_File, _Mode, _Size),
-#if LL_WINDOWS
- std::ostream(&_M_filebuf) {}
-#else
- std::ostream()
-{
- this->init(&_M_filebuf);
-}
-#endif
-
-#if !LL_WINDOWS
-// explicit
-llofstream::llofstream(int __fd,
- ios_base::openmode _Mode, size_t _Size) :
- _M_filebuf(__fd, _Mode, _Size),
- std::ostream()
-{
- this->init(&_M_filebuf);
-}
-#endif
-#endif // llstream_LLFILE
-
-bool llofstream::is_open() const
-{ // test if C stream has been opened
- return _M_filebuf.is_open();
-}
-
-void llofstream::open(const char* _Filename, ios_base::openmode _Mode)
-{ // open a C stream with specified mode
-#if LL_WINDOWS
- llutf16string wideName = utf8str_to_utf16str( _Filename );
- if (_M_filebuf.open( wideName.c_str(), _Mode | ios_base::out) == 0)
- {
- _Myios::setstate(ios_base::failbit);
- }
- else
- {
- _Myios::clear();
- }
-#else
- if (_M_filebuf.open(_Filename, _Mode | ios_base::out) == 0)
- {
- this->setstate(ios_base::failbit);
- }
- else
- {
- this->clear();
- }
-#endif
-}
-
-void llofstream::close()
-{ // close the C stream
- if (_M_filebuf.close() == 0)
- {
-#if LL_WINDOWS
- _Myios::setstate(ios_base::failbit);
-#else
- this->setstate(ios_base::failbit);
-#endif
- }
-}
-
-/************** helper functions ********************************/
-
-std::streamsize llifstream_size(llifstream& ifstr)
-{
- if(!ifstr.is_open()) return 0;
- std::streampos pos_old = ifstr.tellg();
- ifstr.seekg(0, ios_base::beg);
- std::streampos pos_beg = ifstr.tellg();
- ifstr.seekg(0, ios_base::end);
- std::streampos pos_end = ifstr.tellg();
- ifstr.seekg(pos_old, ios_base::beg);
- return pos_end - pos_beg;
-}
-
-std::streamsize llofstream_size(llofstream& ofstr)
-{
- if(!ofstr.is_open()) return 0;
- std::streampos pos_old = ofstr.tellp();
- ofstr.seekp(0, ios_base::beg);
- std::streampos pos_beg = ofstr.tellp();
- ofstr.seekp(0, ios_base::end);
- std::streampos pos_end = ofstr.tellp();
- ofstr.seekp(pos_old, ios_base::beg);
- return pos_end - pos_beg;
-}
-
-
diff --git a/indra/llcommon/llfile.h b/indra/llcommon/llfile.h
index 44a1e42fa5..e310d47325 100755
--- a/indra/llcommon/llfile.h
+++ b/indra/llcommon/llfile.h
@@ -86,12 +86,6 @@ public:
static const char * tmpdir();
};
-// Remove ll[io]fstream support for [LL]FILE*, preparing to remove dependency
-// on GNU's standard library.
-#if ! defined(llstream_LLFILE)
-#define llstream_LLFILE 0
-#endif
-
/**
* @brief Provides a layer of compatibility for C/POSIX.
*
@@ -198,247 +192,4 @@ protected:
#endif
};
-
-/**
- * @brief Controlling input for files.
- *
- * This class supports reading from named files, using the inherited
- * functions from std::basic_istream. To control the associated
- * sequence, an instance of std::basic_filebuf (or a platform-specific derivative)
- * which allows construction using a pre-exisintg file stream buffer.
- * We refer to this std::basic_filebuf (or derivative) as @c sb.
-*/
-class LL_COMMON_API llifstream : public std::istream
-{
- // input stream associated with a C stream
-public:
- // Constructors:
- /**
- * @brief Default constructor.
- *
- * Initializes @c sb using its default constructor, and passes
- * @c &sb to the base class initializer. Does not open any files
- * (you haven't given it a filename to open).
- */
- llifstream();
-
- /**
- * @brief Create an input file stream.
- * @param Filename String specifying the filename.
- * @param Mode Open file in specified mode (see std::ios_base).
- *
- * @c ios_base::in is automatically included in @a mode.
- */
- explicit llifstream(const std::string& _Filename,
- ios_base::openmode _Mode = ios_base::in);
- explicit llifstream(const char* _Filename,
- ios_base::openmode _Mode = ios_base::in);
-
-#if llstream_LLFILE
- /**
- * @brief Create a stream using an open c file stream.
- * @param File An open @c FILE*.
- @param Mode Same meaning as in a standard filebuf.
- @param Size Optimal or preferred size of internal buffer, in chars.
- Defaults to system's @c BUFSIZ.
- */
- explicit llifstream(_Filet *_File,
- ios_base::openmode _Mode = ios_base::in,
- //size_t _Size = static_cast<size_t>(BUFSIZ));
- size_t _Size = static_cast<size_t>(1));
-
- /**
- * @brief Create a stream using an open file descriptor.
- * @param fd An open file descriptor.
- @param Mode Same meaning as in a standard filebuf.
- @param Size Optimal or preferred size of internal buffer, in chars.
- Defaults to system's @c BUFSIZ.
- */
-#if !LL_WINDOWS
- explicit llifstream(int __fd,
- ios_base::openmode _Mode = ios_base::in,
- //size_t _Size = static_cast<size_t>(BUFSIZ));
- size_t _Size = static_cast<size_t>(1));
-#endif
-#endif // llstream_LLFILE
-
- /**
- * @brief The destructor does nothing.
- *
- * The file is closed by the filebuf object, not the formatting
- * stream.
- */
- virtual ~llifstream() {}
-
- // Members:
-#if llstream_LLFILE
- /**
- * @brief Accessing the underlying buffer.
- * @return The current basic_filebuf buffer.
- *
- * This hides both signatures of std::basic_ios::rdbuf().
- */
- llstdio_filebuf* rdbuf() const
- { return const_cast<llstdio_filebuf*>(&_M_filebuf); }
-#endif // llstream_LLFILE
-
- /**
- * @brief Wrapper to test for an open file.
- * @return @c rdbuf()->is_open()
- */
- bool is_open() const;
-
- /**
- * @brief Opens an external file.
- * @param Filename The name of the file.
- * @param Node The open mode flags.
- *
- * Calls @c llstdio_filebuf::open(s,mode|in). If that function
- * fails, @c failbit is set in the stream's error state.
- */
- void open(const std::string& _Filename,
- ios_base::openmode _Mode = ios_base::in)
- { open(_Filename.c_str(), _Mode); }
- void open(const char* _Filename,
- ios_base::openmode _Mode = ios_base::in);
-
- /**
- * @brief Close the file.
- *
- * Calls @c llstdio_filebuf::close(). If that function
- * fails, @c failbit is set in the stream's error state.
- */
- void close();
-
-private:
- llstdio_filebuf _M_filebuf;
-};
-
-
-/**
- * @brief Controlling output for files.
- *
- * This class supports writing to named files, using the inherited
- * functions from std::basic_ostream. To control the associated
- * sequence, an instance of std::basic_filebuf (or a platform-specific derivative)
- * which allows construction using a pre-exisintg file stream buffer.
- * We refer to this std::basic_filebuf (or derivative) as @c sb.
-*/
-class LL_COMMON_API llofstream : public std::ostream
-{
-public:
- // Constructors:
- /**
- * @brief Default constructor.
- *
- * Initializes @c sb using its default constructor, and passes
- * @c &sb to the base class initializer. Does not open any files
- * (you haven't given it a filename to open).
- */
- llofstream();
-
- /**
- * @brief Create an output file stream.
- * @param Filename String specifying the filename.
- * @param Mode Open file in specified mode (see std::ios_base).
- *
- * @c ios_base::out|ios_base::trunc is automatically included in
- * @a mode.
- */
- explicit llofstream(const std::string& _Filename,
- ios_base::openmode _Mode = ios_base::out|ios_base::trunc);
- explicit llofstream(const char* _Filename,
- ios_base::openmode _Mode = ios_base::out|ios_base::trunc);
-
-#if llstream_LLFILE
- /**
- * @brief Create a stream using an open c file stream.
- * @param File An open @c FILE*.
- @param Mode Same meaning as in a standard filebuf.
- @param Size Optimal or preferred size of internal buffer, in chars.
- Defaults to system's @c BUFSIZ.
- */
- explicit llofstream(_Filet *_File,
- ios_base::openmode _Mode = ios_base::out,
- //size_t _Size = static_cast<size_t>(BUFSIZ));
- size_t _Size = static_cast<size_t>(1));
-
- /**
- * @brief Create a stream using an open file descriptor.
- * @param fd An open file descriptor.
- @param Mode Same meaning as in a standard filebuf.
- @param Size Optimal or preferred size of internal buffer, in chars.
- Defaults to system's @c BUFSIZ.
- */
-#if !LL_WINDOWS
- explicit llofstream(int __fd,
- ios_base::openmode _Mode = ios_base::out,
- //size_t _Size = static_cast<size_t>(BUFSIZ));
- size_t _Size = static_cast<size_t>(1));
-#endif
-#endif // llstream_LLFILE
-
- /**
- * @brief The destructor does nothing.
- *
- * The file is closed by the filebuf object, not the formatting
- * stream.
- */
- virtual ~llofstream() {}
-
- // Members:
-#if llstream_LLFILE
- /**
- * @brief Accessing the underlying buffer.
- * @return The current basic_filebuf buffer.
- *
- * This hides both signatures of std::basic_ios::rdbuf().
- */
- llstdio_filebuf* rdbuf() const
- { return const_cast<llstdio_filebuf*>(&_M_filebuf); }
-#endif // llstream_LLFILE
-
- /**
- * @brief Wrapper to test for an open file.
- * @return @c rdbuf()->is_open()
- */
- bool is_open() const;
-
- /**
- * @brief Opens an external file.
- * @param Filename The name of the file.
- * @param Node The open mode flags.
- *
- * Calls @c llstdio_filebuf::open(s,mode|out). If that function
- * fails, @c failbit is set in the stream's error state.
- */
- void open(const std::string& _Filename,
- ios_base::openmode _Mode = ios_base::out|ios_base::trunc)
- { open(_Filename.c_str(), _Mode); }
- void open(const char* _Filename,
- ios_base::openmode _Mode = ios_base::out|ios_base::trunc);
-
- /**
- * @brief Close the file.
- *
- * Calls @c llstdio_filebuf::close(). If that function
- * fails, @c failbit is set in the stream's error state.
- */
- void close();
-
-private:
- llstdio_filebuf _M_filebuf;
-};
-
-
-/**
- * @breif filesize helpers.
- *
- * The file size helpers are not considered particularly efficient,
- * and should only be used for config files and the like -- not in a
- * loop.
- */
-std::streamsize LL_COMMON_API llifstream_size(llifstream& fstr);
-std::streamsize LL_COMMON_API llofstream_size(llofstream& fstr);
-
#endif // not LL_LLFILE_H
diff --git a/indra/llcommon/llliveappconfig.cpp b/indra/llcommon/llliveappconfig.cpp
index 7c87c5a1a0..f955194009 100755
--- a/indra/llcommon/llliveappconfig.cpp
+++ b/indra/llcommon/llliveappconfig.cpp
@@ -49,7 +49,7 @@ bool LLLiveAppConfig::loadFile()
{
LL_INFOS() << "LLLiveAppConfig::loadFile(): reading from "
<< filename() << LL_ENDL;
- llifstream file(filename());
+ std::ifstream file(filename().c_str());
LLSD config;
if (file.is_open())
{
diff --git a/indra/llcommon/lllivefile.cpp b/indra/llcommon/lllivefile.cpp
index c1987baf55..ea485c2d86 100755
--- a/indra/llcommon/lllivefile.cpp
+++ b/indra/llcommon/lllivefile.cpp
@@ -51,6 +51,8 @@ public:
bool mLastExists;
LLEventTimer* mEventTimer;
+private:
+ LOG_CLASS(LLLiveFile);
};
LLLiveFile::Impl::Impl(const std::string& filename, const F32 refresh_period)
@@ -83,46 +85,51 @@ LLLiveFile::~LLLiveFile()
bool LLLiveFile::Impl::check()
{
- if (!mForceCheck && mRefreshTimer.getElapsedTimeF32() < mRefreshPeriod)
+ bool detected_change = false;
+ // Skip the check if not enough time has elapsed and we're not
+ // forcing a check of the file
+ if (mForceCheck || mRefreshTimer.getElapsedTimeF32() >= mRefreshPeriod)
{
- // Skip the check if not enough time has elapsed and we're not
- // forcing a check of the file
- return false;
- }
- mForceCheck = false;
- mRefreshTimer.reset();
-
- // Stat the file to see if it exists and when it was last modified.
- llstat stat_data;
- int res = LLFile::stat(mFilename, &stat_data);
-
- if (res)
- {
- // Couldn't stat the file, that means it doesn't exist or is
- // broken somehow. Clear flags and return.
- if (mLastExists)
- {
- mLastExists = false;
- return true; // no longer existing is a change!
- }
- return false;
- }
-
- // The file exists, decide if we want to load it.
- if (mLastExists)
- {
- // The file existed last time, don't read it if it hasn't changed since
- // last time.
- if (stat_data.st_mtime <= mLastModTime)
- {
- return false;
- }
- }
-
- // We want to read the file. Update status info for the file.
- mLastExists = true;
- mLastStatTime = stat_data.st_mtime;
- return true;
+ mForceCheck = false; // force only forces one check
+ mRefreshTimer.reset(); // don't check again until mRefreshPeriod has passed
+
+ // Stat the file to see if it exists and when it was last modified.
+ llstat stat_data;
+ if (LLFile::stat(mFilename, &stat_data))
+ {
+ // Couldn't stat the file, that means it doesn't exist or is
+ // broken somehow.
+ if (mLastExists)
+ {
+ mLastExists = false;
+ detected_change = true; // no longer existing is a change!
+ LL_DEBUGS() << "detected deleted file '" << mFilename << "'" << LL_ENDL;
+ }
+ }
+ else
+ {
+ // The file exists
+ if ( ! mLastExists )
+ {
+ // last check, it did not exist - that counts as a change
+ LL_DEBUGS() << "detected created file '" << mFilename << "'" << LL_ENDL;
+ detected_change = true;
+ }
+ else if ( stat_data.st_mtime > mLastModTime )
+ {
+ // file modification time is newer than last check
+ LL_DEBUGS() << "detected updated file '" << mFilename << "'" << LL_ENDL;
+ detected_change = true;
+ }
+ mLastExists = true;
+ mLastStatTime = stat_data.st_mtime;
+ }
+ }
+ if (detected_change)
+ {
+ LL_INFOS() << "detected file change '" << mFilename << "'" << LL_ENDL;
+ }
+ return detected_change;
}
void LLLiveFile::Impl::changed()
diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp
index 617969ab2a..227f81e88f 100755
--- a/indra/llcommon/llstring.cpp
+++ b/indra/llcommon/llstring.cpp
@@ -107,7 +107,7 @@ bool iswindividual(llwchar elem)
bool _read_file_into_string(std::string& str, const std::string& filename)
{
- llifstream ifs(filename, llifstream::binary);
+ std::ifstream ifs(filename.c_str(), std::ifstream::binary);
if (!ifs.is_open())
{
LL_INFOS() << "Unable to open file " << filename << LL_ENDL;