X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_file_zlib.cpp;h=c4eed33dd2df650d9f63826981999b3498a500ad;hb=e6891fcf1538562a33ab071d8aec705d27bd2ffd;hp=92cead9188862ddb57d4bf74d79e14082680eac2;hpb=b4a3d1495a5e92ba23bf463bcea34a6e75b55294;p=apitrace diff --git a/common/trace_file_zlib.cpp b/common/trace_file_zlib.cpp index 92cead9..c4eed33 100644 --- a/common/trace_file_zlib.cpp +++ b/common/trace_file_zlib.cpp @@ -33,6 +33,14 @@ #include #include +// for lseek +#ifdef _WIN32 +#include +#else +#include +#include +#endif + #include "os.hpp" #include @@ -53,14 +61,14 @@ public: protected: virtual bool rawOpen(const std::string &filename, File::Mode mode); virtual bool rawWrite(const void *buffer, size_t length); - virtual bool rawRead(void *buffer, size_t length); + virtual size_t rawRead(void *buffer, size_t length); virtual int rawGetc(); virtual void rawClose(); virtual void rawFlush(); virtual bool rawSkip(size_t length); virtual int rawPercentRead(); private: - void *m_gzFile; + gzFile m_gzFile; double m_endOffset; }; @@ -73,6 +81,7 @@ ZLibFile::ZLibFile(const std::string &filename, ZLibFile::~ZLibFile() { + close(); } bool ZLibFile::rawOpen(const std::string &filename, File::Mode mode) @@ -99,9 +108,10 @@ bool ZLibFile::rawWrite(const void *buffer, size_t length) return gzwrite(m_gzFile, buffer, length) != -1; } -bool ZLibFile::rawRead(void *buffer, size_t length) +size_t ZLibFile::rawRead(void *buffer, size_t length) { - return gzread(m_gzFile, buffer, length) != -1; + int ret = gzread(m_gzFile, buffer, length); + return ret < 0 ? 0 : ret; } int ZLibFile::rawGetc() @@ -147,19 +157,3 @@ int ZLibFile::rawPercentRead() File * File::createZLib(void) { return new ZLibFile; } - -bool File::isZLibCompressed(const std::string &filename) -{ - std::fstream stream(filename.c_str(), - std::fstream::binary | std::fstream::in); - if (!stream.is_open()) - return false; - - unsigned char byte1, byte2; - stream >> byte1; - stream >> byte2; - stream.close(); - - return (byte1 == 0x1f && byte2 == 0x8b); -} -