Use new wrapper insteaf of fopen, issue #261

This commit is contained in:
kervala 2016-02-20 17:56:25 +01:00
parent 667ddd1989
commit 808f7b2c30
31 changed files with 78 additions and 70 deletions

View file

@ -229,7 +229,7 @@ void setCrashAlreadyReported(bool state);
*\code *\code
void function(char *filename) void function(char *filename)
{ {
FILE *fp = fopen (filename, "r"); FILE *fp = nlfopen (filename, "r");
if (fp==NULL) if (fp==NULL)
{ {
nlerror("file not found"); nlerror("file not found");

View file

@ -1672,7 +1672,7 @@ bool CDriverGL::compileEXTVertexShader(CVertexProgram *program)
} }
/* /*
FILE *f = fopen(getLogDirectory() + "test.txt", "wb"); FILE *f = nlfopen(getLogDirectory() + "test.txt", "wb");
if (f) if (f)
{ {
std::string vpText; std::string vpText;

View file

@ -304,7 +304,7 @@ namespace NLGUI
return; return;
} }
FILE *fp = fopen (tmpdest.c_str(), "wb"); FILE *fp = nlfopen (tmpdest, "wb");
if (fp == NULL) if (fp == NULL)
{ {
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
@ -411,7 +411,7 @@ namespace NLGUI
return false; return false;
} }
FILE *fp = fopen (tmpdest.c_str(), "wb"); FILE *fp = nlfopen (tmpdest, "wb");
if (fp == NULL) if (fp == NULL)
{ {
curl_easy_cleanup(curl); curl_easy_cleanup(curl);

View file

@ -207,7 +207,7 @@ CAsyncFileManager::CFileLoad::CFileLoad (const std::string& sFileName, uint8 **p
// *************************************************************************** // ***************************************************************************
void CAsyncFileManager::CFileLoad::run (void) void CAsyncFileManager::CFileLoad::run (void)
{ {
FILE *f = fopen (_FileName.c_str(), "rb"); FILE *f = nlfopen (_FileName, "rb");
if (f != NULL) if (f != NULL)
{ {
uint8 *ptr; uint8 *ptr;
@ -253,7 +253,7 @@ void CAsyncFileManager::CMultipleFileLoad::run (void)
{ {
for (uint32 i = 0; i < _FileNames.size(); ++i) for (uint32 i = 0; i < _FileNames.size(); ++i)
{ {
FILE *f = fopen (_FileNames[i].c_str(), "rb"); FILE *f = nlfopen (_FileNames[i], "rb");
if (f != NULL) if (f != NULL)
{ {
uint8 *ptr; uint8 *ptr;

View file

@ -136,7 +136,7 @@ bool CBigFile::add (const std::string &sBigFileName, uint32 nOptions)
CHandleFile &handle= _ThreadFileArray.get(bnp.ThreadFileId); CHandleFile &handle= _ThreadFileArray.get(bnp.ThreadFileId);
// Open the big file. // Open the big file.
handle.File = fopen (sBigFileName.c_str(), "rb"); handle.File = nlfopen (sBigFileName, "rb");
if (handle.File == NULL) if (handle.File == NULL)
return false; return false;
@ -197,7 +197,7 @@ bool CBigFile::BNP::readHeader()
// Only external use // Only external use
if (InternalUse || BigFileName.empty()) return false; if (InternalUse || BigFileName.empty()) return false;
FILE *f = fopen (BigFileName.c_str(), "rb"); FILE *f = nlfopen (BigFileName, "rb");
if (f == NULL) return false; if (f == NULL) return false;
bool res = readHeader(f); bool res = readHeader(f);
@ -348,7 +348,7 @@ bool CBigFile::BNP::appendHeader()
// Only external use // Only external use
if (InternalUse || BigFileName.empty()) return false; if (InternalUse || BigFileName.empty()) return false;
FILE *f = fopen (BigFileName.c_str(), "ab"); FILE *f = nlfopen (BigFileName, "ab");
if (f == NULL) return false; if (f == NULL) return false;
uint32 nNbFile = (uint32)SFiles.size(); uint32 nNbFile = (uint32)SFiles.size();
@ -438,10 +438,10 @@ bool CBigFile::BNP::appendFile(const std::string &filename)
SFiles.push_back(ftmp); SFiles.push_back(ftmp);
OffsetFromBeginning += ftmp.Size; OffsetFromBeginning += ftmp.Size;
FILE *f1 = fopen(BigFileName.c_str(), "ab"); FILE *f1 = nlfopen(BigFileName, "ab");
if (f1 == NULL) return false; if (f1 == NULL) return false;
FILE *f2 = fopen(filename.c_str(), "rb"); FILE *f2 = nlfopen(filename, "rb");
if (f2 == NULL) if (f2 == NULL)
{ {
fclose(f1); fclose(f1);
@ -473,7 +473,7 @@ bool CBigFile::BNP::unpack(const std::string &sDestDir, TUnpackProgressCallback
// Only external use // Only external use
if (InternalUse || BigFileName.empty()) return false; if (InternalUse || BigFileName.empty()) return false;
FILE *bnp = fopen (BigFileName.c_str(), "rb"); FILE *bnp = nlfopen (BigFileName, "rb");
if (bnp == NULL) if (bnp == NULL)
return false; return false;
@ -506,7 +506,7 @@ bool CBigFile::BNP::unpack(const std::string &sDestDir, TUnpackProgressCallback
return false; return false;
} }
out = fopen (filename.c_str(), "wb"); out = nlfopen (filename, "wb");
if (out != NULL) if (out != NULL)
{ {
nlfseek64 (bnp, rBNPFile.Pos, SEEK_SET); nlfseek64 (bnp, rBNPFile.Pos, SEEK_SET);
@ -681,7 +681,7 @@ FILE* CBigFile::getFile (const std::string &sFileName, uint32 &rFileSize,
*/ */
if(handle.File== NULL) if(handle.File== NULL)
{ {
handle.File = fopen (bnp->BigFileName.c_str(), "rb"); handle.File = nlfopen (bnp->BigFileName, "rb");
if (handle.File == NULL) if (handle.File == NULL)
{ {
nlwarning ("bnp: can't fopen big file '%s' error %d '%s'", bnp->BigFileName.c_str(), errno, strerror(errno)); nlwarning ("bnp: can't fopen big file '%s' error %d '%s'", bnp->BigFileName.c_str(), errno, strerror(errno));

View file

@ -600,7 +600,7 @@ void CConfigFile::save () const
// Avoid any problem, Force Locale to default // Avoid any problem, Force Locale to default
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
FILE *fp = fopen (getFilename().c_str (), "w"); FILE *fp = nlfopen (getFilename(), "w");
if (fp == NULL) if (fp == NULL)
{ {
nlwarning ("CF: Couldn't create %s file", getFilename().c_str ()); nlwarning ("CF: Couldn't create %s file", getFilename().c_str ());

View file

@ -42,7 +42,7 @@ bool CCPUTimeStat::getCPUTicks(uint64& user, uint64& nice, uint64& system, uint6
#ifdef NL_OS_UNIX #ifdef NL_OS_UNIX
const char* statfile = "/proc/stat"; const char* statfile = "/proc/stat";
FILE* f = fopen(statfile, "r"); FILE* f = nlfopen(statfile, "r");
if (f == NULL) if (f == NULL)
return false; return false;
@ -66,7 +66,7 @@ bool CCPUTimeStat::getPIDTicks(uint64& utime, uint64& stime, uint64& cutime, uin
#ifdef NL_OS_UNIX #ifdef NL_OS_UNIX
std::string statfile = NLMISC::toString("/proc/%u/stat", pid); std::string statfile = NLMISC::toString("/proc/%u/stat", pid);
FILE* f = fopen(statfile.c_str(), "r"); FILE* f = nlfopen(statfile, "r");
if (f == NULL) if (f == NULL)
return false; return false;

View file

@ -93,7 +93,7 @@ bool loadStringFile(const std::string filename, vector<TStringInfo> &stringInfos
return true; return true;
} }
*/ */
/* FILE *fp = fopen(filename.c_str(), "rb"); /* FILE *fp = nlfopen(filename, "rb");
if (fp == NULL) if (fp == NULL)
{ {

View file

@ -491,7 +491,7 @@ void CFileDisplayer::doDisplay ( const CLog::TDisplayInfo& args, const char *mes
if (_FilePointer == (FILE*)1) if (_FilePointer == (FILE*)1)
{ {
_FilePointer = fopen (_FileName.c_str(), "at"); _FilePointer = nlfopen (_FileName, "at");
if (_FilePointer == NULL) if (_FilePointer == NULL)
printf ("Can't open log file '%s': %s\n", _FileName.c_str(), strerror (errno)); printf ("Can't open log file '%s': %s\n", _FileName.c_str(), strerror (errno));
} }

View file

@ -445,7 +445,7 @@ void cbInvalidEntityNamesFilename(const std::string &invalidEntityNamesFilename)
return; return;
} }
FILE *fp = fopen (fn.c_str(), "r"); FILE *fp = nlfopen (fn, "r");
if (fp == NULL) if (fp == NULL)
{ {
nlwarning ("EIT: Can't load filename '%s' for invalid entity names filename", fn.c_str()); nlwarning ("EIT: Can't load filename '%s' for invalid entity names filename", fn.c_str());

View file

@ -243,7 +243,7 @@ bool CIFile::open(const std::string &path, bool text)
_IsInXMLPackFile = false; _IsInXMLPackFile = false;
_BigFileOffset = 0; _BigFileOffset = 0;
_AlwaysOpened = false; _AlwaysOpened = false;
_F = fopen (path.c_str(), mode); _F = nlfopen (path, mode);
if (_F != NULL) if (_F != NULL)
{ {
/* /*
@ -598,7 +598,7 @@ bool COFile::open(const std::string &path, bool append, bool text, bool useTempF
return false; return false;
} }
_F=fopen(fileToOpen.c_str(), mode); _F = nlfopen(fileToOpen, mode);
return _F!=NULL; return _F!=NULL;
} }

View file

@ -1269,7 +1269,7 @@ void CFileContainer::addSearchBigFile (const string &sBigFilename, bool recurse,
// Open and read the big file header // Open and read the big file header
nlassert(!_MemoryCompressed); nlassert(!_MemoryCompressed);
FILE *Handle = fopen (sBigFilename.c_str(), "rb"); FILE *Handle = nlfopen (sBigFilename, "rb");
if (Handle == NULL) if (Handle == NULL)
{ {
nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't open file, skip it", sBigFilename.c_str(), recurse, alternative); nlwarning ("PATH: CPath::addSearchBigFile(%s, %d, %d): can't open file, skip it", sBigFilename.c_str(), recurse, alternative);
@ -1421,7 +1421,7 @@ void CFileContainer::addSearchXmlpackFile (const string &sXmlpackFilename, bool
} }
// Open and read the xmlpack file header // Open and read the xmlpack file header
FILE *Handle = fopen (sXmlpackFilename.c_str(), "rb"); FILE *Handle = nlfopen (sXmlpackFilename, "rb");
if (Handle == NULL) if (Handle == NULL)
{ {
nlwarning ("PATH: CPath::addSearchXmlpackFile(%s, %d, %d): can't open file, skip it", sXmlpackFilename.c_str(), recurse, alternative); nlwarning ("PATH: CPath::addSearchXmlpackFile(%s, %d, %d): can't open file, skip it", sXmlpackFilename.c_str(), recurse, alternative);
@ -1950,7 +1950,7 @@ bool CFile::isExists (const string &filename)
bool CFile::createEmptyFile (const std::string& filename) bool CFile::createEmptyFile (const std::string& filename)
{ {
FILE *file = fopen (filename.c_str(), "wb"); FILE *file = nlfopen (filename, "wb");
if (file) if (file)
{ {
@ -2311,13 +2311,13 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c
{ {
totalSize = CFile::getFileSize(ssrc); totalSize = CFile::getFileSize(ssrc);
} }
FILE *fp1 = fopen(ssrc.c_str(), "rb"); FILE *fp1 = nlfopen(ssrc, "rb");
if (fp1 == NULL) if (fp1 == NULL)
{ {
nlwarning ("PATH: CopyMoveFile error: can't fopen in read mode '%s'", ssrc.c_str()); nlwarning ("PATH: CopyMoveFile error: can't fopen in read mode '%s'", ssrc.c_str());
return false; return false;
} }
FILE *fp2 = fopen(sdest.c_str(), "wb"); FILE *fp2 = nlfopen(sdest, "wb");
if (fp2 == NULL) if (fp2 == NULL)
{ {
nlwarning ("PATH: CopyMoveFile error: can't fopen in read write mode '%s'", sdest.c_str()); nlwarning ("PATH: CopyMoveFile error: can't fopen in read write mode '%s'", sdest.c_str());

View file

@ -147,7 +147,7 @@ CHashKey getSHA1(const string &filename, bool forcePath)
return CHashKey(); return CHashKey();
} }
//FILE *fp = fopen (filename.c_str(), "rb"); //FILE *fp = nlfopen (filename, "rb");
//if (fp == NULL) return CHashKey(); //if (fp == NULL) return CHashKey();
err = SHA1Reset(&sha); err = SHA1Reset(&sha);

View file

@ -1743,7 +1743,7 @@ namespace NLMISC
bool CSString::readFromFile(const CSString& fileName) bool CSString::readFromFile(const CSString& fileName)
{ {
FILE* file; FILE* file;
file=fopen(fileName.c_str(),"rb"); file = nlfopen(fileName, "rb");
if (file==NULL) if (file==NULL)
{ {
clear(); clear();
@ -1766,7 +1766,7 @@ namespace NLMISC
bool CSString::writeToFile(const CSString& fileName) const bool CSString::writeToFile(const CSString& fileName) const
{ {
FILE* file; FILE* file;
file=fopen(fileName.c_str(),"wb"); file = nlfopen(fileName, "wb");
if (file==NULL) if (file==NULL)
{ {
nlwarning("Failed to open file for writing: %s",fileName.c_str()); nlwarning("Failed to open file for writing: %s",fileName.c_str());

View file

@ -93,7 +93,7 @@ namespace NLMISC
TXMLPackInfo &packInfo = _XMLPacks[packId]; TXMLPackInfo &packInfo = _XMLPacks[packId];
// open the xml pack for later access // open the xml pack for later access
// packInfo.FileHandler = fopen(xmlPackFileName.c_str(), "rb"); // packInfo.FileHandler = nlfopen(xmlPackFileName, "rb");
// open the xml pack for parsing // open the xml pack for parsing
CIFile packFile; CIFile packFile;
@ -182,7 +182,7 @@ namespace NLMISC
fileInfo.FileName = CStringMapper::map(subFileName); fileInfo.FileName = CStringMapper::map(subFileName);
fileInfo.FileOffset = (uint32)(beginOfFile - buffer.begin()); fileInfo.FileOffset = (uint32)(beginOfFile - buffer.begin());
fileInfo.FileSize = (uint32)(endOfFile - beginOfFile); fileInfo.FileSize = (uint32)(endOfFile - beginOfFile);
// fileInfo.FileHandler = fopen(xmlPackFileName.c_str(), "rb"); // fileInfo.FileHandler = nlfopen(xmlPackFileName, "rb");
packInfo._XMLFiles.insert(make_pair(fileInfo.FileName, fileInfo)); packInfo._XMLFiles.insert(make_pair(fileInfo.FileName, fileInfo));
// advance to next line // advance to next line
@ -264,7 +264,7 @@ namespace NLMISC
rFileOffset = fileInfo.FileOffset; rFileOffset = fileInfo.FileOffset;
rCacheFileOnOpen = false; rCacheFileOnOpen = false;
rAlwaysOpened = false; rAlwaysOpened = false;
FILE *fp = fopen(parts[0].c_str(), "rb"); FILE *fp = nlfopen(parts[0], "rb");
return fp; return fp;
} }

View file

@ -271,7 +271,7 @@ bool sendEmail (const string &smtpServer, const string &from, const string &to,
char dst_buf[dst_buf_size + 1]; char dst_buf[dst_buf_size + 1];
size_t size; size_t size;
FILE *src_stream = fopen (attachedFile.c_str(), "rb"); FILE *src_stream = nlfopen (attachedFile, "rb");
if (src_stream == NULL) if (src_stream == NULL)
{ {
nlwarning ("EMAIL: Can't attach file '%s' to the email because the file can't be open", attachedFile.c_str()); nlwarning ("EMAIL: Can't attach file '%s' to the email because the file can't be open", attachedFile.c_str());
@ -299,7 +299,7 @@ bool sendEmail (const string &smtpServer, const string &from, const string &to,
} }
// debug, display what we send into a file // debug, display what we send into a file
// { FILE *fp = fopen (CFile::findNewFile(getLogDirectory() + "mail.txt").c_str(), "wb"); // { FILE *fp = nlfopen (CFile::findNewFile(getLogDirectory() + "mail.txt"), "wb");
// fwrite (formatedBody.c_str(), 1, formatedBody.size(), fp); // fwrite (formatedBody.c_str(), 1, formatedBody.size(), fp);
// fclose (fp); } // fclose (fp); }

View file

@ -575,7 +575,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName,
if (haveLongArg("writepid")) if (haveLongArg("writepid"))
{ {
// use legacy C primitives // use legacy C primitives
FILE *fp = fopen("pid.state", "wt"); FILE *fp = nlfopen("pid.state", "wt");
if (fp) if (fp)
{ {
fprintf(fp, "%u", getpid()); fprintf(fp, "%u", getpid());
@ -623,7 +623,7 @@ sint IService::main (const char *serviceShortName, const char *serviceLongName,
else else
{ {
// create the basic .cfg that link the default one // create the basic .cfg that link the default one
FILE *fp = fopen (cfn.c_str(), "w"); FILE *fp = nlfopen (cfn, "w");
if (fp == NULL) if (fp == NULL)
{ {
nlerror ("SERVICE: Can't create config file '%s'", cfn.c_str()); nlerror ("SERVICE: Can't create config file '%s'", cfn.c_str());

View file

@ -72,7 +72,7 @@ private:
+ " </PRIMITIVE>\n" + " </PRIMITIVE>\n"
+ "</NEL_LIGO_PRIMITIVE_CLASS>"; + "</NEL_LIGO_PRIMITIVE_CLASS>";
FILE *fp = fopen(CLASS_FILE_NAME, "wt"); FILE *fp = NLMISC::nlfopen(CLASS_FILE_NAME, "wt");
nlassert(fp != NULL); nlassert(fp != NULL);
size_t s = fwrite(classfile.data(), 1, classfile.size(), fp); size_t s = fwrite(classfile.data(), 1, classfile.size(), fp);
nlassert(s == classfile.size()); nlassert(s == classfile.size());

View file

@ -19,6 +19,7 @@
#include <nel/misc/file.h> #include <nel/misc/file.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
#include <nel/misc/common.h>
// Test suite for NLMISC::CFile behavior // Test suite for NLMISC::CFile behavior
struct CUTMiscFile : public Test::Suite struct CUTMiscFile : public Test::Suite
@ -49,7 +50,7 @@ private:
void copyFileSize(uint fileSize) void copyFileSize(uint fileSize)
{ {
// create a source file (using standard c code) // create a source file (using standard c code)
FILE *fp = fopen(_SrcFile.c_str(), "wb"); FILE *fp = NLMISC::nlfopen(_SrcFile, "wb");
nlverify(fp != NULL); nlverify(fp != NULL);
for (uint i=0; i<fileSize; ++i) for (uint i=0; i<fileSize; ++i)
@ -63,7 +64,7 @@ private:
NLMISC::CFile::copyFile(_DstFile, _SrcFile, false); NLMISC::CFile::copyFile(_DstFile, _SrcFile, false);
// verify the resulting file // verify the resulting file
fp = fopen(_DstFile.c_str(), "rb"); fp = NLMISC::nlfopen(_DstFile, "rb");
TEST_ASSERT(fp != NULL); TEST_ASSERT(fp != NULL);
if (fp) if (fp)
{ {
@ -108,7 +109,7 @@ private:
void moveFileSize(size_t fileSize) void moveFileSize(size_t fileSize)
{ {
// remove the destination if any // remove the destination if any
FILE *fp = fopen(_DstFile.c_str(), "rb"); FILE *fp = NLMISC::nlfopen(_DstFile, "rb");
if (fp != NULL) if (fp != NULL)
{ {
fclose(fp); fclose(fp);
@ -116,7 +117,7 @@ private:
} }
// create a source file (using standard c code) // create a source file (using standard c code)
fp = fopen(_SrcFile.c_str(), "wb"); fp = NLMISC::nlfopen(_SrcFile, "wb");
nlverify(fp != NULL); nlverify(fp != NULL);
for (uint i=0; i<fileSize; ++i) for (uint i=0; i<fileSize; ++i)
@ -130,12 +131,12 @@ private:
NLMISC::CFile::moveFile(_DstFile, _SrcFile); NLMISC::CFile::moveFile(_DstFile, _SrcFile);
// verify the resulting file // verify the resulting file
fp = fopen(_SrcFile.c_str(), "rb"); fp = NLMISC::nlfopen(_SrcFile, "rb");
TEST_ASSERT_MSG(fp == NULL, "The source file is not removed"); TEST_ASSERT_MSG(fp == NULL, "The source file is not removed");
if (fp) if (fp)
fclose(fp); fclose(fp);
fp = fopen(_DstFile.c_str(), "rb"); fp = NLMISC::nlfopen(_DstFile, "rb");
TEST_ASSERT(fp != NULL); TEST_ASSERT(fp != NULL);
if (fp) if (fp)
{ {

View file

@ -156,15 +156,22 @@ void CCDBSynchronised::read( const string &fileName )
//----------------------------------------------- //-----------------------------------------------
void CCDBSynchronised::write( const string &fileName ) void CCDBSynchronised::write( const string &fileName )
{ {
bool res = false;
if( _Database != 0 ) if( _Database != 0 )
{ {
FILE * f; FILE * f = nlfopen(fileName, "w");
f = fopen(fileName.c_str(),"w"); if (f)
ICDBNode::CTextId id; {
_Database->write(id,f); ICDBNode::CTextId id;
fclose(f); _Database->write(id,f);
fclose(f);
res = true;
}
} }
else
if (!res)
{ {
nlwarning("<CCDBSynchronised::write> can't write %s : the database has not been initialized",fileName.c_str()); nlwarning("<CCDBSynchronised::write> can't write %s : the database has not been initialized",fileName.c_str());
} }

View file

@ -1931,7 +1931,7 @@ void CClientConfig::init(const string &configFileName)
if(!CFile::fileExists(configFileName)) if(!CFile::fileExists(configFileName))
{ {
// create the basic .cfg // create the basic .cfg
FILE *fp = fopen(configFileName.c_str(), "w"); FILE *fp = nlfopen(configFileName, "w");
if (fp == NULL) if (fp == NULL)
nlerror("CFG::init: Can't create config file '%s'", configFileName.c_str()); nlerror("CFG::init: Can't create config file '%s'", configFileName.c_str());

View file

@ -695,7 +695,7 @@ NLMISC_COMMAND(bugReport, "Call the bug report tool with dump", "<AddScreenshot>
if (ClientCfg.Local) if (ClientCfg.Local)
sys += "ShardName OFFLINE "; sys += "ShardName OFFLINE ";
FILE *fp = fopen (std::string(getLogDirectory() + "bug_report.txt").c_str(), "wb"); FILE *fp = nlfopen (getLogDirectory() + "bug_report.txt", "wb");
if (fp != NULL) if (fp != NULL)
{ {
string res = addSlashR(getDebugInformation()); string res = addSlashR(getDebugInformation());

View file

@ -2704,7 +2704,7 @@ void CInterfaceManager::log(const ucstring &str, const std::string &cat)
{ {
// Open file with the name of the player // Open file with the name of the player
const string fileName= "save/log_" + PlayerSelectedFileName + ".txt"; const string fileName= "save/log_" + PlayerSelectedFileName + ".txt";
FILE *f = fopen(fileName.c_str(), "at"); FILE *f = nlfopen(fileName, "at");
if (f != NULL) if (f != NULL)
{ {
const string finalString = string(NLMISC::IDisplayer::dateToHumanString()) + " (" + NLMISC::toUpper(cat) + ") * " + str.toUtf8(); const string finalString = string(NLMISC::IDisplayer::dateToHumanString()) + " (" + NLMISC::toUpper(cat) + ") * " + str.toUtf8();

View file

@ -869,7 +869,7 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
std::string batchFilename = ClientRootPath + UpdateBatchFilename; std::string batchFilename = ClientRootPath + UpdateBatchFilename;
FILE *fp = fopen (batchFilename.c_str(), "wt"); FILE *fp = nlfopen (batchFilename, "wt");
if (fp == NULL) if (fp == NULL)
{ {
@ -1302,7 +1302,7 @@ void CPatchManager::downloadFileWithCurl (const string &source, const string &de
setRWAccess(dest, false); setRWAccess(dest, false);
NLMISC::CFile::deleteFile(dest.c_str()); NLMISC::CFile::deleteFile(dest.c_str());
} }
FILE *fp = fopen (dest.c_str(), "wb"); FILE *fp = nlfopen (dest, "wb");
if (fp == NULL) if (fp == NULL)
{ {
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
@ -1441,8 +1441,8 @@ void CPatchManager::decompressFile (const string &filename)
string dest = filename.substr(0, filename.size ()-4); string dest = filename.substr(0, filename.size ()-4);
setRWAccess(dest, false); setRWAccess(dest, false);
//if(isVerboseLog()) nlinfo("Calling fopen('%s','wb')", dest.c_str()); //if(isVerboseLog()) nlinfo("Calling nlfopen('%s','wb')", dest.c_str());
FILE *fp = fopen (dest.c_str(), "wb"); FILE *fp = nlfopen (dest, "wb");
if (fp == NULL) if (fp == NULL)
{ {
string err = toString("Can't open file '%s' : code=%d %s, (error code 32)", dest.c_str(), errno, strerror(errno)); string err = toString("Can't open file '%s' : code=%d %s, (error code 32)", dest.c_str(), errno, strerror(errno));
@ -2192,7 +2192,7 @@ void CCheckThread::run ()
if (bnpFile.readHeader()) if (bnpFile.readHeader())
{ {
// read the file inside the bnp and calculate the sha1 // read the file inside the bnp and calculate the sha1
FILE *bnp = fopen (sBNPFilename.c_str(), "rb"); FILE *bnp = nlfopen (sBNPFilename, "rb");
if (bnp != NULL) if (bnp != NULL)
{ {
for (uint32 k = 0; k < bnpFile.SFiles.size(); ++k) for (uint32 k = 0; k < bnpFile.SFiles.size(); ++k)
@ -3068,7 +3068,7 @@ bool CPatchManager::extract(const std::string& patchPath,
uint nblab = 0; uint nblab = 0;
pPM->deleteFile(updateBatchFilename, false, false); pPM->deleteFile(updateBatchFilename, false, false);
FILE *fp = fopen (updateBatchFilename.c_str(), "wt"); FILE *fp = nlfopen (updateBatchFilename, "wt");
if (fp == 0) if (fp == 0)
{ {

View file

@ -143,7 +143,7 @@ bool CXDPFileReader::init(const std::string &sFilename, sint32 nLowerBound, sint
} }
else else
{ {
_File = fopen(sFilename.c_str(), "rb"); _File = nlfopen(sFilename, "rb");
if (_File == NULL) if (_File == NULL)
return false; return false;
fseek(_File, nLowerBound, SEEK_SET); fseek(_File, nLowerBound, SEEK_SET);
@ -560,7 +560,7 @@ CXDeltaPatch::TApplyResult CXDeltaPatch::apply(const std::string &sFileToPatch,
errorMsg = toString("output file %s already exists", sFileOutput.c_str()); errorMsg = toString("output file %s already exists", sFileOutput.c_str());
return ApplyResult_Error; return ApplyResult_Error;
} }
FILE *outFILE = fopen(sFileOutput.c_str(), "wb"); FILE *outFILE = nlfopen(sFileOutput, "wb");
if (outFILE == NULL) if (outFILE == NULL)
{ {
errorMsg = toString("cant create %s", sFileOutput.c_str()); errorMsg = toString("cant create %s", sFileOutput.c_str());
@ -572,7 +572,7 @@ CXDeltaPatch::TApplyResult CXDeltaPatch::apply(const std::string &sFileToPatch,
bool ftpPresent = false; bool ftpPresent = false;
if (pFromSource) if (pFromSource)
{ {
ftpFILE = fopen(sFileToPatch.c_str(), "rb"); ftpFILE = nlfopen(sFileToPatch, "rb");
if (ftpFILE == NULL) if (ftpFILE == NULL)
{ {
errorMsg = toString("expecting file %s", sFileToPatch.c_str()); errorMsg = toString("expecting file %s", sFileToPatch.c_str());

View file

@ -141,7 +141,7 @@ static void markBNPFile(std::string &path)
uint32 nFileSize=CFile::getFileSize(path); uint32 nFileSize=CFile::getFileSize(path);
if (!nFileSize) return; if (!nFileSize) return;
FILE *f = fopen(path.c_str(), "rb+"); FILE *f = nlfopen(path, "rb+");
if (!f) return; if (!f) return;
// Result // Result
if (nlfseek64 (f, nFileSize-4, SEEK_SET) != 0) if (nlfseek64 (f, nFileSize-4, SEEK_SET) != 0)

View file

@ -1384,7 +1384,7 @@ bool CClientEditionModule::loadUserComponent(const std::string& filename, bool m
uint32 timeStamp = 0; uint32 timeStamp = 0;
if (! compressed) if (! compressed)
{ {
FILE* file = fopen(filename.c_str(),"rb"); FILE* file = nlfopen(filename, "rb");
if (!file) if (!file)
{ {
nlwarning("Try to open an invalid file %s (access error)", filename.c_str()); nlwarning("Try to open an invalid file %s (access error)", filename.c_str());
@ -1491,7 +1491,7 @@ bool CClientEditionModule::loadUserComponent(const std::string& filename, bool m
else else
{ {
// Get Uncompressed File length (4 last byte of a gz) // Get Uncompressed File length (4 last byte of a gz)
FILE* file = fopen(filename.c_str(),"rb"); FILE* file = nlfopen(filename, "rb");
if (!file) if (!file)
{ {
nlwarning("Try to open an invalid file %s (access error)", filename.c_str()); nlwarning("Try to open an invalid file %s (access error)", filename.c_str());
@ -1653,7 +1653,7 @@ void CClientEditionModule::saveUserComponentFile(const std::string& filename, bo
if (!mustCompress) if (!mustCompress)
{ {
{ {
FILE* output = fopen(uncompressedName.c_str(), "wb"); FILE* output = nlfopen(uncompressedName, "wb");
if (output) if (output)
{ {
fwrite(component->UncompressedData, sizeof(char) , component->UncompressedDataLength, output); fwrite(component->UncompressedData, sizeof(char) , component->UncompressedDataLength, output);

View file

@ -154,7 +154,7 @@ bool unpack7Zip(const std::string &sevenZipFile, const std::string &destFileName
SzArEx_GetFileNameUtf16(&db, 0, &filename[0]); SzArEx_GetFileNameUtf16(&db, 0, &filename[0]);
// write the extracted file // write the extracted file
FILE *outputHandle = fopen(destFileName.c_str(), "wb+"); FILE *outputHandle = nlfopen(destFileName, "wb+");
if (outputHandle == 0) if (outputHandle == 0)
{ {

View file

@ -1020,7 +1020,7 @@ void CSheetManager::dumpVisualSlots()
// *************************************************************************** // ***************************************************************************
void CSheetManager::dumpVisualSlotsIndex() void CSheetManager::dumpVisualSlotsIndex()
{ {
FILE * vsIndexFile = fopen(std::string(getLogDirectory() + "vs_index.txt").c_str(),"w"); FILE * vsIndexFile = nlfopen(getLogDirectory() + "vs_index.txt", "w");
if( vsIndexFile ) if( vsIndexFile )
{ {
for (uint i=0; i < SLOTTYPE::NB_SLOT; ++i) for (uint i=0; i < SLOTTYPE::NB_SLOT; ++i)

View file

@ -65,7 +65,7 @@ public:
/*bool write(char *filename) /*bool write(char *filename)
{ {
FILE *outf=fopen(filename,"wb"); FILE *outf=nlfopen(filename, "wb");
if (outf==NULL) if (outf==NULL)
return false; return false;

View file

@ -1120,7 +1120,7 @@ bool CPersistentDataRecord::readFromFile(const std::string &fileName)
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
// open the file // open the file
FILE* inf= fopen(fileName.c_str(), "rb"); FILE* inf= nlfopen(fileName, "rb");
DROP_IF( inf==NULL, "Failed to open input file " << fileName, return false); DROP_IF( inf==NULL, "Failed to open input file " << fileName, return false);
// get the file size // get the file size