From 5d4cad9c02e9d4f31477fed0e3b20b35c83936f8 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 20 Jun 2012 11:20:57 -0400 Subject: ABI change: fix use of off_t, size_t, and integer types Significantly improve the code's use of off_t for file offsets, size_t for memory sizes, and integer types in cases where there has to be compatibility with external interfaces. Rework sections of the code that would have prevented qpdf from working on files larger than 2 (or maybe 4) GB in size. --- libqpdf/QUtil.cc | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'libqpdf/QUtil.cc') diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 1bdae0fe..e1071940 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -14,7 +15,7 @@ #endif std::string -QUtil::int_to_string(int num, int fullpad) +QUtil::int_to_string(long long num, int fullpad) { // This routine will need to be recompiled if an int can be longer than // 49 digits. @@ -28,14 +29,20 @@ QUtil::int_to_string(int num, int fullpad) "limit"); } +#ifdef HAVE_PRINTF_LL +# define PRINTF_LL "ll" +#else +# define PRINTF_LL "l" +#endif if (fullpad) { - sprintf(t, "%0*d", fullpad, num); + sprintf(t, "%0*" PRINTF_LL "d", fullpad, num); } else { - sprintf(t, "%d", num); + sprintf(t, "%" PRINTF_LL "d", num); } +#undef PRINTF_LL return std::string(t); } @@ -101,6 +108,26 @@ QUtil::fopen_wrapper(std::string const& description, FILE* f) return f; } +int +QUtil::fseek_off_t(FILE* stream, off_t offset, int whence) +{ +#if HAVE_FSEEKO + return fseeko(stream, offset, whence); +#else + return fseek(stream, offset, whence); +#endif +} + +off_t +QUtil::ftell_off_t(FILE* stream) +{ +#if HAVE_FSEEKO + return ftello(stream); +#else + return ftell(stream); +#endif +} + char* QUtil::copy_string(std::string const& str) { -- cgit v1.2.3-54-g00ecf