diff --git a/poppler/Stream.cc b/poppler/Stream.cc index 6ffd5d3..107bcda 100644 --- a/poppler/Stream.cc +++ b/poppler/Stream.cc @@ -753,16 +753,22 @@ GBool StreamPredictor::getNextLine() { // UniqueFileStream //------------------------------------------------------------------------ -UniqueFileStream::UniqueFileStream(FILE *fA, char *fileNameA, Goffset startA, GBool limitedA, - Goffset lengthA, Object *dictA): - FileStream(fA, fileNameA, startA, limitedA, lengthA, dictA) { - f = fopen(fileName, "rb"); -} +#ifdef _WIN32 -UniqueFileStream::~UniqueFileStream() { - close(); - fclose(f); -} +class UniqueFileStream: public FileStream { +public: + UniqueFileStream(FILE *fA, char *fileNameA, Goffset startA, GBool limitedA, Goffset lengthA, Object *dictA): + FileStream(fA, fileNameA, startA, limitedA, lengthA, dictA) { + f = fopen(fileName, "rb"); + } + + virtual ~UniqueFileStream() { + close(); + fclose(f); + } +}; + +#endif // _WIN32 //------------------------------------------------------------------------ // FileStream @@ -780,6 +786,11 @@ FileStream::FileStream(FILE *fA, char *fileNameA, Goffset startA, GBool limitedA bufPos = start; savePos = 0; saved = gFalse; + +#ifndef _WIN32 + fd = fileno(f); + offset = start; +#endif // _WIN32 } FileStream::~FileStream() { @@ -787,7 +798,11 @@ FileStream::~FileStream() { } BaseStream *FileStream::copy() { +#ifndef _WIN32 + return new FileStream(f, fileName, start, limited, length, &dict); +#else return new UniqueFileStream(f, fileName, start, limited, length, &dict); +#endif // _WIN32 } Stream *FileStream::makeSubStream(Goffset startA, GBool limitedA, @@ -796,8 +811,13 @@ Stream *FileStream::makeSubStream(Goffset startA, GBool limitedA, } void FileStream::reset() { +#ifndef _WIN32 + savePos = offset; + offset = start; +#else savePos = Gftell(f); Gfseek(f, start, SEEK_SET); +#endif // _WIN32 saved = gTrue; bufPtr = bufEnd = buf; bufPos = start; @@ -805,7 +825,11 @@ void FileStream::reset() { void FileStream::close() { if (saved) { +#ifndef _WIN32 + offset = savePos; +#else Gfseek(f, savePos, SEEK_SET); +#endif // _WIN32 saved = gFalse; } } @@ -823,7 +847,12 @@ GBool FileStream::fillBuf() { } else { n = fileStreamBufSize; } +#ifndef _WIN32 + n = pread(fd, buf, n, offset); + offset += n; +#else n = fread(buf, 1, n, f); +#endif // _WIN32 bufEnd = buf + n; if (bufPtr >= bufEnd) { return gFalse; @@ -835,15 +864,28 @@ void FileStream::setPos(Goffset pos, int dir) { Goffset size; if (dir >= 0) { +#ifndef _WIN32 + offset = pos; +#else Gfseek(f, pos, SEEK_SET); +#endif // _WIN32 bufPos = pos; } else { +#ifndef _WIN32 + size = lseek(fd, 0, SEEK_END); +#else Gfseek(f, 0, SEEK_END); size = Gftell(f); +#endif // _WIN32 if (pos > size) pos = size; +#ifndef _WIN32 + offset = size - pos; + bufPos = offset; +#else Gfseek(f, -pos, SEEK_END); bufPos = Gftell(f); +#endif // _WIN32 } bufPtr = bufEnd = buf; } diff --git a/poppler/Stream.h b/poppler/Stream.h index dfcd530..27e1344 100644 --- a/poppler/Stream.h +++ b/poppler/Stream.h @@ -503,14 +503,11 @@ private: Goffset bufPos; Goffset savePos; GBool saved; -}; - -class UniqueFileStream: public FileStream { -public: - - UniqueFileStream(FILE *fA, char *fileNameA, Goffset startA, GBool limitedA, - Goffset lengthA, Object *dictA); - virtual ~UniqueFileStream(); + +#ifndef _WIN32 + int fd; + Goffset offset; +#endif // _WIN32 }; //------------------------------------------------------------------------