X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_file_zlib.cpp;h=a432ccde44598984f2503ff4a68e304a723ec54d;hb=4dbf7c9e3f4b669ec38600c04ba8a67926d10cc7;hp=5d47d5387b366d472777f3577980386f06f80c2a;hpb=48412ffde3dd4710c96d5e8d9cfdf1789e4d703a;p=apitrace diff --git a/common/trace_file_zlib.cpp b/common/trace_file_zlib.cpp index 5d47d53..a432ccd 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 @@ -60,7 +68,7 @@ protected: virtual bool rawSkip(size_t length); virtual int rawPercentRead(); private: - void *m_gzFile; + gzFile m_gzFile; double m_endOffset; }; @@ -97,12 +105,12 @@ bool ZLibFile::rawOpen(const std::string &filename, File::Mode mode) bool ZLibFile::rawWrite(const void *buffer, size_t length) { - return gzwrite(m_gzFile, buffer, length) != -1; + return gzwrite(m_gzFile, buffer, unsigned(length)) != -1; } size_t ZLibFile::rawRead(void *buffer, size_t length) { - int ret = gzread(m_gzFile, buffer, length); + int ret = gzread(m_gzFile, buffer, unsigned(length)); return ret < 0 ? 0 : ret; } @@ -142,26 +150,10 @@ bool ZLibFile::rawSkip(size_t) int ZLibFile::rawPercentRead() { gz_state *state = (gz_state *)m_gzFile; - return 100 * (lseek(state->fd, 0, SEEK_CUR) / m_endOffset); + return int(100 * (lseek(state->fd, 0, SEEK_CUR) / m_endOffset)); } 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); -} -