diff options
| author | ghost <andreas.monzner@multimedia-labs.de> | 2010-11-23 13:58:30 +0100 |
|---|---|---|
| committer | ghost <andreas.monzner@multimedia-labs.de> | 2010-11-23 13:58:30 +0100 |
| commit | 7b2960a205f3c3e3b421d1664cd38644b3ffb679 (patch) | |
| tree | d57819fb0ff1eb5e64638bc584c54ae18816043f /lib/base/rawfile.cpp | |
| parent | fc83dfbe60f36712953498b20a1c2f10737e7685 (diff) | |
| parent | 7199d3c37e7e7065bd6943702b5864fa5186b9a8 (diff) | |
| download | enigma2-7b2960a205f3c3e3b421d1664cd38644b3ffb679.tar.gz enigma2-7b2960a205f3c3e3b421d1664cd38644b3ffb679.zip | |
Merge branch 'bug_615_replace_rawfile'
Diffstat (limited to 'lib/base/rawfile.cpp')
| -rw-r--r-- | lib/base/rawfile.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/base/rawfile.cpp b/lib/base/rawfile.cpp index c7e11feb..3a09e07e 100644 --- a/lib/base/rawfile.cpp +++ b/lib/base/rawfile.cpp @@ -4,7 +4,10 @@ #include <lib/base/rawfile.h> #include <lib/base/eerror.h> +DEFINE_REF(eRawFile); + eRawFile::eRawFile() + :m_lock(false) { m_fd = -1; m_file = 0; @@ -53,6 +56,13 @@ void eRawFile::setfd(int fd) off_t eRawFile::lseek(off_t offset, int whence) { + eSingleLocker l(m_lock); + m_current_offset = lseek_internal(offset, whence); + return m_current_offset; +} + +off_t eRawFile::lseek_internal(off_t offset, int whence) +{ // eDebug("lseek: %lld, %d", offset, whence); /* if there is only one file, use the native lseek - the file could be growing! */ if (m_nrfiles < 2) @@ -61,7 +71,8 @@ off_t eRawFile::lseek(off_t offset, int whence) return ::lseek(m_fd, offset, whence); else { - ::fseeko(m_file, offset, whence); + if (::fseeko(m_file, offset, whence) < 0) + perror("fseeko"); return ::ftello(m_file); } } @@ -100,11 +111,19 @@ int eRawFile::close() } } -ssize_t eRawFile::read(void *buf, size_t count) +ssize_t eRawFile::read(off_t offset, void *buf, size_t count) { -// eDebug("read: %p, %d", buf, count); + eSingleLocker l(m_lock); + + if (offset != m_current_offset) + { + m_current_offset = lseek_internal(offset, SEEK_SET); + if (m_current_offset < 0) + return m_current_offset; + } + switchOffset(m_current_offset); - + if (m_nrfiles >= 2) { if (m_current_offset + count > m_totallength) |
