++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;
++}
++
++
+ GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
+ #if defined(WIN32)
+ //---------- Win32 ----------
+@@ -460,7 +506,7 @@
+ s->append("x");
+ t = (int)time(NULL);
+ for (i = 0; i < 1000; ++i) {
+- sprintf(buf, "%d", t + i);
++ sprintf(buf, "%08x-%08x", t + i, GetCurrentThreadId());
+ s2 = s->copy()->append(buf);
+ if (ext) {
+ s2->append(ext);
+@@ -468,8 +514,7 @@
+ if (!(f2 = fopen(s2->getCString(), "r"))) {
+ if (!(f2 = fopen(s2->getCString(), mode))) {
+ delete s2;
+- delete s;
+- return gFalse;
++ continue;
+ }
+ *name = s2;
+ *f = f2;
+@@ -479,6 +524,7 @@
+ fclose(f2);
+ delete s2;
+ }
++ fprintf(stderr, "Couldn't create temporary file\n");
+ delete s;
+ return gFalse;
+ #elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
+@@ -489,7 +535,7 @@
+ // with this file name after the tmpnam call and before the fopen
+ // call. I will happily accept fixes to this function for non-Unix
+ // OSs.
+- if (!(s = tmpnam(NULL))) {
++ if (!(s = mktmpname(NULL))) {
+ return gFalse;
+ }
+ *name = new GString(s);
+@@ -516,7 +562,7 @@
+ (*name)->append("/XXXXXX")->append(ext);
+ fd = mkstemps((*name)->getCString(), strlen(ext));
+ #else
+- if (!(s = tmpnam(NULL))) {
++ if (!(s = mktmpname(NULL))) {
+ return gFalse;
+ }
+ *name = new GString(s);
+@@ -533,7 +579,7 @@
+ (*name)->append("/XXXXXX");
+ fd = mkstemp((*name)->getCString());
+ #else // HAVE_MKSTEMP
+- if (!(s = tmpnam(NULL))) {
++ if (!(s = mktmpname(NULL))) {
+ return gFalse;
+ }
+ *name = new GString(s);
+--- xpdf/gfile.h.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/gfile.h 2010-05-18 11:22:18.000000000 -0700
+@@ -58,6 +58,9 @@
+ // Get current directory.
+ extern GString *getCurrentDir();
+
++/* create a temporary filename */
++char* mktmpname(char*ptr);
++
+ // Append a file name to a path string. <path> may be an empty
+ // string, denoting the current directory). Returns <path>.
+ extern GString *appendToPath(GString *path, char *fileName);
+--- xpdf/JBIG2Stream.cc.orig 2010-05-18 11:33:21.000000000 -0700
++++ xpdf/JBIG2Stream.cc 2010-06-03 16:55:03.000000000 -0700
+@@ -6,7 +6,24 @@
+ //
+ //========================================================================
+
+-#include <aconf.h>
++//========================================================================
++//
++// Modified under the Poppler project - http://poppler.freedesktop.org
++//
++// All changes made under the Poppler project to this file are licensed
++// under GPL version 2 or later
++//
++// Copyright (C) 2006 Raj Kumar <rkumar@archive.org>
++// Copyright (C) 2006 Paul Walmsley <paul@booyaka.com>
++// Copyright (C) 2006-2009 Albert Astals Cid <aacid@kde.org>
++// Copyright (C) 2009 David Benjamin <davidben@mit.edu>
++//
++// To see a description of the changes please see the Changelog file that
++// came with your tarball or type make ChangeLog if you are building from git
++//
++//========================================================================
++
++#include <config.h>
+
+ #ifdef USE_GCC_PRAGMAS
+ #pragma implementation
+@@ -24,8 +41,8 @@
+
+ //------------------------------------------------------------------------
+
+-static int contextSize[4] = { 16, 13, 10, 10 };
+-static int refContextSize[2] = { 13, 10 };
++static const int contextSize[4] = { 16, 13, 10, 10 };
++static const int refContextSize[2] = { 13, 10 };
+
+ //------------------------------------------------------------------------
+ // JBIG2HuffmanTable
+@@ -42,7 +59,7 @@
+ Guint prefix;
+ };
+
+-JBIG2HuffmanTable huffTableA[] = {
++static JBIG2HuffmanTable huffTableA[] = {
+ { 0, 1, 4, 0x000 },
+ { 16, 2, 8, 0x002 },
+ { 272, 3, 16, 0x006 },
+@@ -50,7 +67,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableB[] = {
++static JBIG2HuffmanTable huffTableB[] = {
+ { 0, 1, 0, 0x000 },
+ { 1, 2, 0, 0x002 },
+ { 2, 3, 0, 0x006 },
+@@ -61,7 +78,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableC[] = {
++static JBIG2HuffmanTable huffTableC[] = {
+ { 0, 1, 0, 0x000 },
+ { 1, 2, 0, 0x002 },
+ { 2, 3, 0, 0x006 },
+@@ -74,7 +91,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableD[] = {
++static JBIG2HuffmanTable huffTableD[] = {
+ { 1, 1, 0, 0x000 },
+ { 2, 2, 0, 0x002 },
+ { 3, 3, 0, 0x006 },
+@@ -84,7 +101,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableE[] = {
++static JBIG2HuffmanTable huffTableE[] = {
+ { 1, 1, 0, 0x000 },
+ { 2, 2, 0, 0x002 },
+ { 3, 3, 0, 0x006 },
+@@ -96,7 +113,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableF[] = {
++static JBIG2HuffmanTable huffTableF[] = {
+ { 0, 2, 7, 0x000 },
+ { 128, 3, 7, 0x002 },
+ { 256, 3, 8, 0x003 },
+@@ -114,7 +131,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableG[] = {
++static JBIG2HuffmanTable huffTableG[] = {
+ { -512, 3, 8, 0x000 },
+ { 256, 3, 8, 0x001 },
+ { 512, 3, 9, 0x002 },
+@@ -133,7 +150,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableH[] = {
++static JBIG2HuffmanTable huffTableH[] = {
+ { 0, 2, 1, 0x000 },
+ { 0, 2, jbig2HuffmanOOB, 0x001 },
+ { 4, 3, 4, 0x004 },
+@@ -158,7 +175,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableI[] = {
++static JBIG2HuffmanTable huffTableI[] = {
+ { 0, 2, jbig2HuffmanOOB, 0x000 },
+ { -1, 3, 1, 0x002 },
+ { 1, 3, 1, 0x003 },
+@@ -184,7 +201,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableJ[] = {
++static JBIG2HuffmanTable huffTableJ[] = {
+ { -2, 2, 2, 0x000 },
+ { 6, 2, 6, 0x001 },
+ { 0, 2, jbig2HuffmanOOB, 0x002 },
+@@ -209,7 +226,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableK[] = {
++static JBIG2HuffmanTable huffTableK[] = {
+ { 1, 1, 0, 0x000 },
+ { 2, 2, 1, 0x002 },
+ { 4, 4, 0, 0x00c },
+@@ -226,7 +243,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableL[] = {
++static JBIG2HuffmanTable huffTableL[] = {
+ { 1, 1, 0, 0x000 },
+ { 2, 2, 0, 0x002 },
+ { 3, 3, 1, 0x006 },
+@@ -243,7 +260,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableM[] = {
++static JBIG2HuffmanTable huffTableM[] = {
+ { 1, 1, 0, 0x000 },
+ { 2, 3, 0, 0x004 },
+ { 7, 3, 3, 0x005 },
+@@ -260,7 +277,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableN[] = {
++static JBIG2HuffmanTable huffTableN[] = {
+ { 0, 1, 0, 0x000 },
+ { -2, 3, 0, 0x004 },
+ { -1, 3, 0, 0x005 },
+@@ -269,7 +286,7 @@
+ { 0, 0, jbig2HuffmanEOT, 0 }
+ };
+
+-JBIG2HuffmanTable huffTableO[] = {
++static JBIG2HuffmanTable huffTableO[] = {
+ { 0, 1, 0, 0x000 },
+ { -1, 3, 0, 0x004 },
+ { 1, 3, 0, 0x005 },
+@@ -473,7 +490,7 @@