From 2fd59711482471414d72dfb34bca72e4b4fd04df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Wed, 9 Jun 2010 13:46:40 +0000 Subject: [PATCH] poppler: embed mktmpname() from the xpdf changes patch --- lib/pdf/Makefile.in | 4 +++- lib/pdf/XMLOutputDev.cc | 1 + lib/pdf/popplercompat.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++++ lib/pdf/popplercompat.h | 4 ++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 lib/pdf/popplercompat.cc diff --git a/lib/pdf/Makefile.in b/lib/pdf/Makefile.in index f91c72b..4a70716 100644 --- a/lib/pdf/Makefile.in +++ b/lib/pdf/Makefile.in @@ -10,7 +10,7 @@ all: ../libgfxpdf$(A) libgfxpdf: ../libgfxpdf$(A) -libgfxpdf_objects = GFXOutputDev.$(O) InfoOutputDev.$(O) BitmapOutputDev.$(O) FullBitmapOutputDev.$(O) XMLOutputDev.$(O) pdf.$(O) fonts.$(O) bbox.$(O) +libgfxpdf_objects = GFXOutputDev.$(O) InfoOutputDev.$(O) BitmapOutputDev.$(O) FullBitmapOutputDev.$(O) XMLOutputDev.$(O) pdf.$(O) fonts.$(O) bbox.$(O) popplercompat.$(O) xpdf_in_source = @xpdf_in_source@ @@ -33,6 +33,8 @@ splash_objects = xpdf/SplashOutputDev.$(O) xpdf/SplashFont.$(O) xpdf/SplashState xpdf/SplashScreen.$(O) xpdf/SplashPath.$(O) xpdf/SplashXPath.$(O) xpdf/SplashXPathScanner.$(O) \ xpdf/SplashFTFontEngine.$(O) xpdf/SplashFTFontFile.$(O) xpdf/SplashFTFont.$(O) +popplercompat.$(O): popplercompat.cc + $(C) popplercompat.cc -o $@ fonts.$(O): fonts.c $(C) fonts.c -o $@ bbox.$(O): bbox.c diff --git a/lib/pdf/XMLOutputDev.cc b/lib/pdf/XMLOutputDev.cc index a5fd653..06aad02 100644 --- a/lib/pdf/XMLOutputDev.cc +++ b/lib/pdf/XMLOutputDev.cc @@ -21,6 +21,7 @@ #include #include "XMLOutputDev.h" #include "GfxState.h" +#include "popplercompat.h" #ifndef HAVE_POPPLER #include "gfile.h" #endif diff --git a/lib/pdf/popplercompat.cc b/lib/pdf/popplercompat.cc new file mode 100644 index 0000000..4da1a6f --- /dev/null +++ b/lib/pdf/popplercompat.cc @@ -0,0 +1,52 @@ +#include +#include +#include +#include "popplercompat.h" + +#ifdef HAVE_POPPLER +static char* getTempDir() +{ +#ifdef WIN32 + char*dir = getenv("TMP"); + if(!dir) dir = getenv("TEMP"); + if(!dir) dir = getenv("tmp"); + if(!dir) dir = getenv("temp"); + if(!dir) dir = "C:\\"; +#else + char* dir = "/tmp/"; +#endif + return dir; +} + +char* mktmpname(char*ptr) { + static char tmpbuf[128]; + char*dir = getTempDir(); + int l = strlen(dir); + char*sep = ""; + if(!ptr) + ptr = tmpbuf; + if(l && dir[l-1]!='/' && dir[l-1]!='\\') { +#ifdef WIN32 + sep = "\\"; +#else + sep = "/"; +#endif + } + + // used to be mktemp. This does remove the warnings, but + // It's not exactly an improvement. +#ifdef HAVE_LRAND48 + sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48()); +#else +# ifdef HAVE_RAND + sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand()); +# else + static int count = 1; + sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count); + count ++; +# endif +#endif + return ptr; +} + +#endif diff --git a/lib/pdf/popplercompat.h b/lib/pdf/popplercompat.h index cf8bfca..b76df7e 100644 --- a/lib/pdf/popplercompat.h +++ b/lib/pdf/popplercompat.h @@ -18,4 +18,8 @@ #endif #endif +#ifdef HAVE_POPPLER +char* mktmpname(char*ptr); +#endif + #endif -- 1.7.10.4