X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_file.cpp;h=8eb3bd46e5b47082a104f46fe444af011a5ab49e;hb=f6548d1c7accc959ef53f8c08c1d7a71f94c7f53;hp=f48c1aa9189c8b04c23a92448afc5b51ddd9d216;hpb=834d14c3574c47225ddc31484ea144b9d1a1dffa;p=apitrace diff --git a/common/trace_file.cpp b/common/trace_file.cpp index f48c1aa..8eb3bd4 100644 --- a/common/trace_file.cpp +++ b/common/trace_file.cpp @@ -32,6 +32,7 @@ #include #include +#include #include "os.hpp" @@ -92,13 +93,6 @@ 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) : File(filename, mode), @@ -120,11 +114,10 @@ bool ZLibFile::rawOpen(const std::string &filename, File::Mode mode) // 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); + gz_state *state = (gz_state *)m_gzFile; + off_t loc = lseek(state->fd, 0, SEEK_CUR); + m_endOffset = lseek(state->fd, 0, SEEK_END); + lseek(state->fd, loc, SEEK_SET); } return m_gzFile != NULL; @@ -175,6 +168,6 @@ bool ZLibFile::rawSkip(size_t) int ZLibFile::rawPercentRead() { - gz_dummy_stream *stream = (gz_dummy_stream *)m_gzFile; - return 100 * (ftell(stream->file) / m_endOffset); + gz_state *state = (gz_state *)m_gzFile; + return 100 * (lseek(state->fd, 0, SEEK_CUR) / m_endOffset); }