goo/gfile.cc | 38 +++++++++++++++++++++++ goo/gfile.h | 7 ++++ goo/gtypes.h | 19 ----------- poppler/Stream.cc | 67 +++++------------------------------------ poppler/XRef.cc | 4 +- poppler/poppler-config.h.cmake | 6 --- poppler/poppler-config.h.in | 6 --- utils/pdfinfo.cc | 16 +-------- 8 files changed, 60 insertions(+), 103 deletions(-)
New commits: commit 48ed05d95598b642a57456a843baf9f246502bb6 Author: Adrian Johnson <[email protected]> Date: Wed Feb 6 21:56:01 2013 +1030 Make Goffset long long and factor out all fseek/ftell into gfile.cc This fixes build problems on 32-bit machines due to off_t being defined differently depending on whether source files included condig.h. Bug 60095 diff --git a/goo/gfile.cc b/goo/gfile.cc index b075b2b..7630e20 100644 --- a/goo/gfile.cc +++ b/goo/gfile.cc @@ -49,6 +49,8 @@ # include <unixlib.h> # endif #endif // _WIN32 +#include <stdio.h> +#include <limits> #include "GooString.h" #include "gfile.h" @@ -546,6 +548,42 @@ char *getLine(char *buf, int size, FILE *f) { return buf; } +int Gfseek(FILE *f, Goffset offset, int whence) { +#if HAVE_FSEEKO + return fseeko(f, offset, whence); +#elif HAVE_FSEEK64 + return fseek64(f, offset, whence); +#elif _WIN32 + return _fseeki64(f, offset, whence); +#else + return fseek(f, offset, whence); +#endif +} + +Goffset Gftell(FILE *f) { +#if HAVE_FSEEKO + return ftello(f); +#elif HAVE_FSEEK64 + return ftell64(f); +#elif _WIN32 + return _ftelli64(f); +#else + return ftell(f); +#endif +} + +Goffset GoffsetMax() { +#if HAVE_FSEEKO + return (std::numeric_limits<off_t>::max)(); +#elif HAVE_FSEEK64 + return (std::numeric_limits<off64_t>::max)(); +#elif _WIN32 + return (std::numeric_limits<__int64>::max)(); +#else + return (std::numeric_limits<long>::max)(); +#endif +} + //------------------------------------------------------------------------ // GDir and GDirEntry //------------------------------------------------------------------------ diff --git a/goo/gfile.h b/goo/gfile.h index 4e11023..6787a6e 100644 --- a/goo/gfile.h +++ b/goo/gfile.h @@ -114,6 +114,13 @@ extern FILE *openFile(const char *path, const char *mode); // conventions. extern char *getLine(char *buf, int size, FILE *f); +// Like fseek/ftell but uses platform specific variants that support large files +extern int Gfseek(FILE *f, Goffset offset, int whence); +extern Goffset Gftell(FILE *f); + +// Largest offset supported by Gfseek/Gftell +extern Goffset GoffsetMax(); + //------------------------------------------------------------------------ // GDir and GDirEntry //------------------------------------------------------------------------ diff --git a/goo/gtypes.h b/goo/gtypes.h index 84245b7..a8d4519 100644 --- a/goo/gtypes.h +++ b/goo/gtypes.h @@ -27,10 +27,6 @@ #include "poppler-config.h" -#ifndef _WIN32 -#include <sys/types.h> // for off_t -#endif - /* * These have stupid names to avoid conflicts with some (but not all) * C++ compilers which define them. @@ -51,19 +47,6 @@ typedef unsigned char Guchar; typedef unsigned short Gushort; typedef unsigned int Guint; typedef unsigned long Gulong; - -/* Define Goffset to be the offset type used by the version of - * fseek we are using. - */ -#if HAVE_FSEEKO -typedef off_t Goffset; -#elif HAVE_FSEEK64 -typedef off64_t Goffset; -#elif _WIN32 -typedef __int64 Goffset; -#else -typedef long Goffset; -#endif - +typedef long long Goffset; #endif diff --git a/poppler/Stream.cc b/poppler/Stream.cc index 91a1af2..3e541c6 100644 --- a/poppler/Stream.cc +++ b/poppler/Stream.cc @@ -385,7 +385,7 @@ void FileOutStream::close () Goffset FileOutStream::getPos () { - return ftell(f); + return Gftell(f); } void FileOutStream::put (char c) @@ -800,19 +800,8 @@ Stream *FileStream::makeSubStream(Goffset startA, GBool limitedA, } void FileStream::reset() { -#if HAVE_FSEEKO - savePos = ftello(f); - fseeko(f, start, SEEK_SET); -#elif HAVE_FSEEK64 - savePos = ftell64(f); - fseek64(f, start, SEEK_SET); -#elif _WIN32 - savePos = _ftelli64(f); - _fseeki64(f, start, SEEK_SET); -#else - savePos = ftell(f); - fseek(f, start, SEEK_SET); -#endif + savePos = Gftell(f); + Gfseek(f, start, SEEK_SET); saved = gTrue; bufPtr = bufEnd = buf; bufPos = start; @@ -820,15 +809,7 @@ void FileStream::reset() { void FileStream::close() { if (saved) { -#if HAVE_FSEEKO - fseeko(f, savePos, SEEK_SET); -#elif HAVE_FSEEK64 - fseek64(f, savePos, SEEK_SET); -#elif _WIN32 - _fseeki64(f, savePos, SEEK_SET); -#else - fseek(f, savePos, SEEK_SET); -#endif + Gfseek(f, savePos, SEEK_SET); saved = gFalse; } } @@ -858,45 +839,15 @@ void FileStream::setPos(Goffset pos, int dir) { Goffset size; if (dir >= 0) { -#if HAVE_FSEEKO - fseeko(f, pos, SEEK_SET); -#elif HAVE_FSEEK64 - fseek64(f, pos, SEEK_SET); -#elif _WIN32 - _fseeki64(f, pos, SEEK_SET); -#else - fseek(f, pos, SEEK_SET); -#endif + Gfseek(f, pos, SEEK_SET); bufPos = pos; } else { -#if HAVE_FSEEKO - fseeko(f, 0, SEEK_END); - size = ftello(f); -#elif HAVE_FSEEK64 - fseek64(f, 0, SEEK_END); - size = ftell64(f); -#elif _WIN32 - _fseeki64(f, 0, SEEK_END); - size = _ftelli64(f); -#else - fseek(f, 0, SEEK_END); - size = ftell(f); -#endif + Gfseek(f, 0, SEEK_END); + size = Gftell(f); if (pos > size) pos = size; -#if HAVE_FSEEKO - fseeko(f, -pos, SEEK_END); - bufPos = ftello(f); -#elif HAVE_FSEEK64 - fseek64(f, -pos, SEEK_END); - bufPos = ftell64(f); -#elif _WIN32 - _fseeki64(f, -pos, SEEK_END); - bufPos = _ftelli64(f); -#else - fseek(f, -pos, SEEK_END); - bufPos = ftell(f); -#endif + Gfseek(f, -pos, SEEK_END); + bufPos = Gftell(f); } bufPtr = bufEnd = buf; } diff --git a/poppler/XRef.cc b/poppler/XRef.cc index 6aa168e..e2e86ad 100644 --- a/poppler/XRef.cc +++ b/poppler/XRef.cc @@ -41,8 +41,8 @@ #include <math.h> #include <ctype.h> #include <limits.h> -#include <limits> #include <float.h> +#include "goo/gfile.h" #include "goo/gmem.h" #include "Object.h" #include "Stream.h" @@ -852,7 +852,7 @@ GBool XRef::readXRefStreamSection(Stream *xrefStr, int *w, int first, int n) { } offset = (offset << 8) + c; } - if (offset > (unsigned long long)(std::numeric_limits<Goffset>::max)()) { + if (offset > (unsigned long long)GoffsetMax()) { error(errSyntaxError, -1, "Offset inside xref table too large for fseek"); return gFalse; } diff --git a/poppler/poppler-config.h.cmake b/poppler/poppler-config.h.cmake index 1fb2999..13a92fe 100644 --- a/poppler/poppler-config.h.cmake +++ b/poppler/poppler-config.h.cmake @@ -107,12 +107,6 @@ #cmakedefine USE_CMS 1 #endif -/* Define to 1 if you have the `fseek64' function. */ -#cmakedefine HAVE_FSEEK64 1 - -/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ -#cmakedefine HAVE_FSEEKO 1 - // Also, there are preprocessor symbols in the header files // that are used but never defined when building poppler using configure // or cmake: DISABLE_OUTLINE, DEBUG_MEM, SPLASH_CMYK, HAVE_T1LIB_H, diff --git a/poppler/poppler-config.h.in b/poppler/poppler-config.h.in index afd3dbd..11b5691 100644 --- a/poppler/poppler-config.h.in +++ b/poppler/poppler-config.h.in @@ -107,12 +107,6 @@ #undef USE_CMS #endif -/* Define to 1 if you have the `fseek64' function. */ -#undef HAVE_FSEEK64 - -/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ -#undef HAVE_FSEEKO - // Also, there are preprocessor symbols in the header files // that are used but never defined when building poppler using configure // or cmake: DISABLE_OUTLINE, DEBUG_MEM, SPLASH_CMYK, HAVE_T1LIB_H, diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc index 8cb9ae1..14e4f6c 100644 --- a/utils/pdfinfo.cc +++ b/utils/pdfinfo.cc @@ -36,6 +36,7 @@ #include "parseargs.h" #include "printencodings.h" #include "goo/GooString.h" +#include "goo/gfile.h" #include "goo/gmem.h" #include "GlobalParams.h" #include "Object.h" @@ -351,19 +352,8 @@ int main(int argc, char *argv[]) { f = fopen(fileName->getCString(), "rb"); #endif if (f) { -#if HAVE_FSEEKO - fseeko(f, 0, SEEK_END); - printf("File size: %lld bytes\n", (long long)ftello(f)); -#elif HAVE_FSEEK64 - fseek64(f, 0, SEEK_END); - printf("File size: %lld bytes\n", (long long)ftell64(f)); -#elif _WIN32 - _fseeki64(f, 0, SEEK_END); - printf("File size: %lld bytes\n", (long long)_ftelli64(f)); -#else - fseek(f, 0, SEEK_END); - printf("File size: %lld bytes\n", (long long)ftell(f)); -#endif + Gfseek(f, 0, SEEK_END); + printf("File size: %lld bytes\n", (long long)Gftell(f)); fclose(f); } _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
