diff -Naurp poppler-old/glib/poppler-document.cc poppler/glib/poppler-document.cc --- poppler-old/glib/poppler-document.cc 2009-03-14 07:26:01.000000000 -0400 +++ poppler/glib/poppler-document.cc 2009-03-14 09:20:19.000000000 -0400 @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +#include + #include #include #include @@ -73,12 +75,18 @@ _poppler_document_new_from_pdfdoc (PDFDo document = (PopplerDocument *) g_object_new (POPPLER_TYPE_DOCUMENT, NULL, NULL); if (!newDoc->isOk()) { + int fopen_errno; switch (newDoc->getErrorCode()) { case errOpenFile: - g_set_error (error, POPPLER_ERROR, - POPPLER_ERROR_OPEN_FILE, - "Failed to open the PDF file"); + // If there was an error opening the file, count it as a G_FILE_ERROR + // and set the GError parameters accordingly. (this assumes that the + // only way to get an errOpenFile error is if newDoc was created using + // a filename and thus fopen was called, which right now is true. + fopen_errno = newDoc->getFopenErrno(); + g_set_error (error, G_FILE_ERROR, + g_file_error_from_errno (fopen_errno), + strerror(fopen_errno)); break; case errBadCatalog: g_set_error (error, POPPLER_ERROR, diff -Naurp poppler-old/poppler/PDFDoc.cc poppler/poppler/PDFDoc.cc --- poppler-old/poppler/PDFDoc.cc 2009-03-14 07:26:01.000000000 -0400 +++ poppler/poppler/PDFDoc.cc 2009-03-14 09:07:01.000000000 -0400 @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -71,7 +72,6 @@ PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword, GooString *userPassword, void *guiDataA) { Object obj; - GooString *fileName1, *fileName2; ok = gFalse; errCode = errNone; @@ -87,33 +87,22 @@ PDFDoc::PDFDoc(GooString *fileNameA, Goo #endif fileName = fileNameA; - fileName1 = fileName; - // try to open file - fileName2 = NULL; #ifdef VMS - if (!(file = fopen(fileName1->getCString(), "rb", "ctx=stm"))) { - error(-1, "Couldn't open file '%s'", fileName1->getCString()); + file = fopen(fileName->getCString(), "rb", "ctx=stm"); +#else + file = fopen(fileName->getCString(), "rb"); +#endif + if (file == NULL) { + error(-1, "Couldn't open file '%s': %s.", fileName->getCString(), + strerror(errno)); errCode = errOpenFile; + // Keep a copy of the errno returned by fopen so that it can be referred + // to later. + fopenErrno = errno; return; } -#else - if (!(file = fopen(fileName1->getCString(), "rb"))) { - fileName2 = fileName->copy(); - fileName2->lowerCase(); - if (!(file = fopen(fileName2->getCString(), "rb"))) { - fileName2->upperCase(); - if (!(file = fopen(fileName2->getCString(), "rb"))) { - error(-1, "Couldn't open file '%s'", fileName->getCString()); - delete fileName2; - errCode = errOpenFile; - return; - } - } - delete fileName2; - } -#endif // create stream obj.initNull(); diff -Naurp poppler-old/poppler/PDFDoc.h poppler/poppler/PDFDoc.h --- poppler-old/poppler/PDFDoc.h 2009-03-14 07:26:01.000000000 -0400 +++ poppler/poppler/PDFDoc.h 2009-03-14 07:58:52.000000000 -0400 @@ -77,6 +77,10 @@ public: // Get the error code (if isOk() returns false). int getErrorCode() { return errCode; } + // Get the error code returned by fopen() (if getErrorCode() == + // errOpenFile). + int getFopenErrno() { return fopenErrno; } + // Get file name. GooString *getFileName() { return fileName; } @@ -238,6 +242,9 @@ private: GBool ok; int errCode; + //If there is an error opening the PDF file with fopen() in the constructor, + //then the POSIX errno will be here. + int fopenErrno; }; #endif