Commit e1e4457a authored by Christian Persch's avatar Christian Persch

all: Use the openFile fopen wrapper from gfile.h

Use the openFile wrapper instead of calling fopen directly
in the libraries.
parent 1e99a1ee
......@@ -26,6 +26,7 @@
#include <stdio.h>
#include <limits.h>
#include "goo/gfile.h"
#include "goo/gmem.h"
#include "poppler/Error.h"
#include "FoFiBase.h"
......@@ -51,7 +52,7 @@ char *FoFiBase::readFile(const char *fileName, int *fileLen) {
char *buf;
int n;
if (!(f = fopen(fileName, "rb"))) {
if (!(f = openFile(fileName, "rb"))) {
error(errIO, -1, "Cannot open '{0:s}'", fileName);
return nullptr;
}
......
......@@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "goo/gfile.h"
#include "FoFiIdentifier.h"
//------------------------------------------------------------------------
......@@ -184,7 +185,7 @@ private:
FileReader *FileReader::make(const char *fileName) {
FILE *fA;
if (!(fA = fopen(fileName, "rb"))) {
if (!(fA = openFile(fileName, "rb"))) {
return nullptr;
}
return new FileReader(fA);
......
......@@ -18,7 +18,8 @@
#include "config.h"
#include <errno.h>
#include <glib/gstdio.h>
#include <goo/gfile.h>
#include "poppler.h"
#include "poppler-private.h"
......@@ -173,7 +174,7 @@ poppler_attachment_save (PopplerAttachment *attachment,
g_return_val_if_fail (POPPLER_IS_ATTACHMENT (attachment), FALSE);
f = g_fopen (filename, "wb");
f = openFile (filename, "wb");
if (f == nullptr)
{
......
......@@ -20,7 +20,8 @@
#include "config.h"
#include <errno.h>
#include <glib/gstdio.h>
#include <goo/gfile.h>
#include "poppler-media.h"
#include "poppler-private.h"
......@@ -214,7 +215,7 @@ poppler_media_save (PopplerMedia *poppler_media,
g_return_val_if_fail (POPPLER_IS_MEDIA (poppler_media), FALSE);
g_return_val_if_fail (poppler_media->stream.isStream(), FALSE);
f = g_fopen (filename, "wb");
f = openFile (filename, "wb");
if (f == nullptr)
{
......
......@@ -28,6 +28,7 @@
#include <config.h>
#include "FileSpec.h"
#include "goo/gfile.h"
EmbFile::EmbFile(Object &&efStream)
{
......@@ -83,7 +84,7 @@ bool EmbFile::save(const char *path) {
FILE *f;
bool ret;
if (!(f = fopen(path, "wb"))) {
if (!(f = openFile(path, "wb"))) {
return false;
}
ret = save2(f);
......
......@@ -46,6 +46,7 @@
#include <stddef.h>
#include <math.h>
#include <string.h>
#include "goo/gfile.h"
#include "goo/gmem.h"
#include "Error.h"
#include "Object.h"
......@@ -461,7 +462,7 @@ cmsHPROFILE loadColorProfile(const char *fileName)
if (fileName[0] == '/') {
// full path
// check if open the file
if ((fp = fopen(fileName,"r")) != nullptr) {
if ((fp = openFile(fileName,"r")) != nullptr) {
fclose(fp);
hp = cmsOpenProfileFromFile(fileName,"r");
}
......@@ -471,7 +472,7 @@ cmsHPROFILE loadColorProfile(const char *fileName)
GooString *path = new GooString(GLOBAL_COLOR_PROFILE_DIR);
path->append(fileName);
// check if open the file
if ((fp = fopen(path->c_str(),"r")) != nullptr) {
if ((fp = openFile(path->c_str(),"r")) != nullptr) {
fclose(fp);
hp = cmsOpenProfileFromFile(path->c_str(),"r");
}
......
......@@ -1064,7 +1064,7 @@ void GlobalParams::setupBaseFonts(char *dir) {
fileName = nullptr;
if (dir) {
fileName = appendToPath(new GooString(dir), displayFontTab[i].t1FileName);
if ((f = fopen(fileName->c_str(), "rb"))) {
if ((f = openFile(fileName->c_str(), "rb"))) {
fclose(f);
} else {
delete fileName;
......@@ -1074,7 +1074,7 @@ void GlobalParams::setupBaseFonts(char *dir) {
for (j = 0; !fileName && displayFontDirs[j]; ++j) {
fileName = appendToPath(new GooString(displayFontDirs[j]),
displayFontTab[i].t1FileName);
if ((f = fopen(fileName->c_str(), "rb"))) {
if ((f = openFile(fileName->c_str(), "rb"))) {
fclose(f);
} else {
delete fileName;
......
......@@ -216,7 +216,7 @@ static void GetWindowsFontDir(char *winFontDir, int cbWinFontDirLen)
static bool FileExists(const char *path)
{
FILE * f = fopen(path, "rb");
FILE * f = openFile(path, "rb");
if (f) {
fclose(f);
return true;
......
......@@ -897,7 +897,7 @@ int PDFDoc::savePageAs(GooString *name, int pageNo)
Ref *refPage = getCatalog()->getPageRef(pageNo);
Object page = getXRef()->fetch(refPage->num, refPage->gen);
if (!(f = fopen(name->c_str(), "wb"))) {
if (!(f = openFile(name->c_str(), "wb"))) {
error(errIO, -1, "Couldn't open file '{0:t}'", name);
return errOpenFile;
}
......@@ -1030,7 +1030,7 @@ int PDFDoc::saveAs(GooString *name, PDFWriteMode mode) {
OutStream *outStr;
int res;
if (!(f = fopen(name->c_str(), "wb"))) {
if (!(f = openFile(name->c_str(), "wb"))) {
error(errIO, -1, "Couldn't open file '{0:t}'", name);
return errOpenFile;
}
......@@ -1062,7 +1062,7 @@ int PDFDoc::saveWithoutChangesAs(GooString *name) {
OutStream *outStr;
int res;
if (!(f = fopen(name->c_str(), "wb"))) {
if (!(f = openFile(name->c_str(), "wb"))) {
error(errIO, -1, "Couldn't open file '{0:t}'", name);
return errOpenFile;
}
......
......@@ -1141,7 +1141,7 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc,
#endif
} else {
fileTypeA = psFile;
if (!(f = fopen(fileName, "w"))) {
if (!(f = openFile(fileName, "w"))) {
error(errIO, -1, "Couldn't open PostScript file '{0:s}'", fileName);
ok = false;
return;
......@@ -2309,7 +2309,7 @@ void PSOutputDev::setupExternalType1Font(GooString *fileName, GooString *psName)
embFontList->append("\n");
// copy the font file
if (!(fontFile = fopen(fileName->c_str(), "rb"))) {
if (!(fontFile = openFile(fileName->c_str(), "rb"))) {
error(errIO, -1, "Couldn't open external font file");
return;
}
......
......@@ -59,6 +59,7 @@
#include <fcntl.h> // for O_BINARY
#include <io.h> // for setmode
#endif
#include "goo/gfile.h"
#include "goo/gmem.h"
#include "goo/GooString.h"
#include "goo/GooList.h"
......@@ -5637,7 +5638,7 @@ TextOutputDev::TextOutputDev(const char *fileName, bool physLayoutA,
// keep DOS from munging the end-of-line characters
setmode(fileno(stdout), O_BINARY);
#endif
} else if ((outputStream = fopen(fileName, append ? "ab" : "wb"))) {
} else if ((outputStream = openFile(fileName, append ? "ab" : "wb"))) {
needClose = true;
} else {
error(errIO, -1, "Couldn't open text file '{0:s}'", fileName);
......
......@@ -36,6 +36,7 @@
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include "goo/gfile.h"
#include "goo/gmem.h"
#include "SplashErrorCodes.h"
#include "SplashBitmap.h"
......@@ -165,7 +166,7 @@ SplashError SplashBitmap::writePNMFile(char *fileName) {
FILE *f;
SplashError e;
if (!(f = fopen(fileName, "wb"))) {
if (!(f = openFile(fileName, "wb"))) {
return splashErrOpenFile;
}
......@@ -262,7 +263,7 @@ SplashError SplashBitmap::writeAlphaPGMFile(char *fileName) {
if (!alpha) {
return splashErrModeMismatch;
}
if (!(f = fopen(fileName, "wb"))) {
if (!(f = openFile(fileName, "wb"))) {
return splashErrOpenFile;
}
fprintf(f, "P5\n%d %d\n255\n", width, height);
......@@ -338,7 +339,7 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, const char
FILE *f;
SplashError e;
if (!(f = fopen(fileName, "wb"))) {
if (!(f = openFile(fileName, "wb"))) {
return splashErrOpenFile;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment