]> git.cworth.org Git - apitrace/blobdiff - trace_file.cpp
Fix indention.
[apitrace] / trace_file.cpp
index 4c170a6043fcf7d2276ea5f0205e7f0f6af03020..45473b345ffa3a3cae447ccab1fe101e93f91514 100644 (file)
@@ -56,6 +56,16 @@ File::~File()
     close();
 }
 
+
+File::Offset File::currentOffset()
+{
+    return File::Offset();
+}
+
+void File::setCurrentOffset(const File::Offset &offset)
+{
+}
+
 bool File::isZLibCompressed(const std::string &filename)
 {
     std::fstream stream(filename.c_str(),
@@ -87,6 +97,12 @@ bool File::isSnappyCompressed(const std::string &filename)
     return (byte1 == SNAPPY_BYTE1 && byte2 == SNAPPY_BYTE2);
 }
 
+typedef struct gz_stream {
+    z_stream stream;
+    int      z_err;   /* error code for last stream operation */
+    int      z_eof;   /* set if end of input file */
+    FILE     *file;   /* .gz file */
+} gz_dummy_stream;
 
 ZLibFile::ZLibFile(const std::string &filename,
                    File::Mode mode)
@@ -103,15 +119,28 @@ bool ZLibFile::rawOpen(const std::string &filename, File::Mode mode)
 {
     m_gzFile = gzopen(filename.c_str(),
                       (mode == File::Write) ? "wb" : "rb");
+
+    if (mode == File::Read && m_gzFile) {
+        //XXX: unfortunately zlib doesn't support
+        //     SEEK_END or we could've done:
+        //m_endOffset = gzseek(m_gzFile, 0, SEEK_END);
+        //gzrewind(m_gzFile);
+        gz_dummy_stream *stream = (gz_dummy_stream *)m_gzFile;
+        long loc = ftell(stream->file);
+        fseek(stream->file,0,SEEK_END);
+        m_endOffset = ftell(stream->file);
+        fseek(stream->file, loc, SEEK_SET);
+    }
+
     return m_gzFile != NULL;
 }
 
-bool ZLibFile::rawWrite(const void *buffer, int length)
+bool ZLibFile::rawWrite(const void *buffer, size_t length)
 {
     return gzwrite(m_gzFile, buffer, length) != -1;
 }
 
-bool ZLibFile::rawRead(void *buffer, int length)
+bool ZLibFile::rawRead(void *buffer, size_t length)
 {
     return gzread(m_gzFile, buffer, length) != -1;
 }
@@ -129,7 +158,24 @@ void ZLibFile::rawClose()
     }
 }
 
-void ZLibFile::rawFlush(FlushType type)
+void ZLibFile::rawFlush()
 {
     gzflush(m_gzFile, Z_SYNC_FLUSH);
 }
+
+
+bool ZLibFile::supportsOffsets() const
+{
+    return false;
+}
+
+bool ZLibFile::rawSkip(size_t)
+{
+    return false;
+}
+
+int ZLibFile::rawPercentRead()
+{
+    gz_dummy_stream *stream = (gz_dummy_stream *)m_gzFile;
+    return 100 * (ftell(stream->file) / m_endOffset);
+}