From bc113326e410846bfb221f0d9eb3a001b968fbc2 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sun, 3 Apr 2011 23:11:38 +0000 Subject: [PATCH] Fixed problem with utf characters in the %APPDATA% path on Windows. Added function for opening files on Windows and Linux - RsDirUtil::rs_fopen. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4124 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dbase/cachestrapper.cc | 2 +- libretroshare/src/dbase/findex.cc | 2 +- libretroshare/src/ft/ftcontroller.cc | 12 ++--- libretroshare/src/ft/ftextralist.cc | 10 +--- libretroshare/src/ft/ftfilecreator.cc | 14 +----- libretroshare/src/ft/ftfileprovider.cc | 14 +----- libretroshare/src/pqi/authssl.cc | 5 +- libretroshare/src/pqi/p3cfgmgr.cc | 22 ++++----- libretroshare/src/pqi/pqibin.cc | 17 +++---- libretroshare/src/pqi/pqistreamer.cc | 2 +- libretroshare/src/pqi/sslfns.cc | 7 +-- libretroshare/src/rsserver/rsinit.cc | 48 +++++++++++++------- libretroshare/src/rsserver/rsloginhandler.cc | 17 +++---- libretroshare/src/tcponudp/tcpstream.cc | 2 +- libretroshare/src/util/rsdebug.cc | 12 ++--- libretroshare/src/util/rsdir.cc | 41 ++++++++++------- libretroshare/src/util/rsdir.h | 1 + 17 files changed, 109 insertions(+), 119 deletions(-) diff --git a/libretroshare/src/dbase/cachestrapper.cc b/libretroshare/src/dbase/cachestrapper.cc index d69ae62d2..cc01239f3 100644 --- a/libretroshare/src/dbase/cachestrapper.cc +++ b/libretroshare/src/dbase/cachestrapper.cc @@ -718,7 +718,7 @@ bool CacheStrapper::CacheExist(CacheData& data){ std::string filename = data.path + "/" + data.name; FILE* file = NULL; - file = fopen(filename.c_str(), "r"); + file = RsDirUtil::rs_fopen(filename.c_str(), "r"); if(file == NULL) return false; diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index a0f8f21d8..368c1b74b 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -978,7 +978,7 @@ int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uin /* finally, save to file */ - FILE *file = fopen(filenametmp.c_str(), "wb"); + FILE *file = RsDirUtil::rs_fopen(filenametmp.c_str(), "wb"); if (file == NULL) { std::cerr << "FileIndex::saveIndex error opening file for writting: " << filename << ". Giving up." << std::endl; diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index f9a55bc01..129fab3f3 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -682,7 +682,7 @@ bool ftController::moveFile(const std::string& source,const std::string& dest) bool ftController::copyFile(const std::string& source,const std::string& dest) { - FILE *in = fopen64(source.c_str(),"rb") ; + FILE *in = RsDirUtil::rs_fopen(source.c_str(),"rb") ; if(in == NULL) { @@ -690,7 +690,7 @@ bool ftController::copyFile(const std::string& source,const std::string& dest) return false ; } - FILE *out = fopen64(dest.c_str(),"wb") ; + FILE *out = RsDirUtil::rs_fopen(dest.c_str(),"wb") ; if(out == NULL) { @@ -1040,13 +1040,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has destination = dest + "/" + fname; // create void file with the target name. -#ifdef WINDOWS_SYS - std::wstring destinationW; - librs::util::ConvertUtf8ToUtf16(destination, destinationW); - FILE *f = _wfopen(destinationW.c_str(), L"w"); -#else - FILE *f = fopen64(destination.c_str(),"w") ; -#endif + FILE *f = RsDirUtil::rs_fopen(destination.c_str(),"w") ; if(f == NULL) std::cerr << "Could not open file " << destination << " for writting." << std::endl ; else diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index b27cd4338..145e312dd 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -215,7 +215,7 @@ bool ftExtraList::moveExtraFile(std::string fname, std::string hash, uint64_t si } std::string path = destpath + '/' + fname; - if (0 == rename(it->second.info.path.c_str(), path.c_str())) + if (RsDirUtil::renameFile(it->second.info.path, path)) { /* rename */ it->second.info.path = path; @@ -427,13 +427,7 @@ bool ftExtraList::loadList(std::list& load) } /* open file */ -#ifdef WINDOWS_SYS - std::wstring filepathW; - librs::util::ConvertUtf8ToUtf16(fi->file.path, filepathW); - FILE *fd = _wfopen(filepathW.c_str(), L"rb"); -#else - FILE *fd = fopen64(fi->file.path.c_str(), "rb"); -#endif + FILE *fd = RsDirUtil::rs_fopen(fi->file.path.c_str(), "rb"); if (fd == NULL) { delete (*it); diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index c42deac84..cc58ac3ed 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -251,13 +251,7 @@ int ftFileCreator::locked_initializeFileAttrs() * attempt to open file */ -#ifdef WINDOWS_SYS - std::wstring wfile_name; - librs::util::ConvertUtf8ToUtf16(file_name, wfile_name); - fd = _wfopen(wfile_name.c_str(), L"r+b"); -#else - fd = fopen64(file_name.c_str(), "r+b"); -#endif + fd = RsDirUtil::rs_fopen(file_name.c_str(), "r+b"); if (!fd) { @@ -268,11 +262,7 @@ int ftFileCreator::locked_initializeFileAttrs() std::cerr << std::endl; /* try opening for write */ -#ifdef WINDOWS_SYS - fd = _wfopen(wfile_name.c_str(), L"w+b"); -#else - fd = fopen64(file_name.c_str(), "w+b"); -#endif + fd = RsDirUtil::rs_fopen(file_name.c_str(), "w+b"); if (!fd) { std::cerr << "ftFileCreator::initializeFileAttrs()"; diff --git a/libretroshare/src/ft/ftfileprovider.cc b/libretroshare/src/ft/ftfileprovider.cc index 9c4c160e6..c8c3329ee 100644 --- a/libretroshare/src/ft/ftfileprovider.cc +++ b/libretroshare/src/ft/ftfileprovider.cc @@ -305,24 +305,14 @@ int ftFileProvider::initializeFileAttrs() * attempt to open file */ -#ifdef WINDOWS_SYS - std::wstring wfile_name; - librs::util::ConvertUtf8ToUtf16(file_name, wfile_name); - fd = _wfopen(wfile_name.c_str(), L"r+b"); -#else - fd = fopen64(file_name.c_str(), "r+b"); -#endif + fd = RsDirUtil::rs_fopen(file_name.c_str(), "r+b"); if (!fd) { std::cerr << "ftFileProvider::initializeFileAttrs() Failed to open (r+b): "; std::cerr << file_name << std::endl; /* try opening read only */ -#ifdef WINDOWS_SYS - fd = _wfopen(wfile_name.c_str(), L"rb"); -#else - fd = fopen64(file_name.c_str(), "rb"); -#endif + fd = RsDirUtil::rs_fopen(file_name.c_str(), "rb"); if (!fd) { std::cerr << "ftFileProvider::initializeFileAttrs() Failed to open (rb): "; diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 09f81df74..37da827f7 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -36,6 +36,7 @@ #include "authgpg.h" #include "pqi/p3connmgr.h" #include "serialiser/rsconfigitems.h" +#include "util/rsdir.h" /******************** notify of new Cert **************************/ #include "pqinotify.h" @@ -178,7 +179,7 @@ static int initLib = 0; SSL_CTX_set_cipher_list(sslctx, "DEFAULT"); // certificates (Set Local Server Certificate). - FILE *ownfp = fopen(cert_file, "r"); + FILE *ownfp = RsDirUtil::rs_fopen(cert_file, "r"); if (ownfp == NULL) { std::cerr << "Couldn't open Own Certificate!" << std::endl; @@ -201,7 +202,7 @@ static int initLib = 0; mOwnPublicKey = X509_get_pubkey(x509); // get private key - FILE *pkfp = fopen(priv_key_file, "rb"); + FILE *pkfp = RsDirUtil::rs_fopen(priv_key_file, "rb"); if (pkfp == NULL) { std::cerr << "Couldn't Open PrivKey File!" << std::endl; diff --git a/libretroshare/src/pqi/p3cfgmgr.cc b/libretroshare/src/pqi/p3cfgmgr.cc index e1d360400..255c6e86d 100644 --- a/libretroshare/src/pqi/p3cfgmgr.cc +++ b/libretroshare/src/pqi/p3cfgmgr.cc @@ -265,8 +265,8 @@ bool p3ConfigMgr::backedUpFileSave(const std::string& fname, const std::string& #endif // open file from which to collect buffer - file = fopen(fname.c_str(), "rb"); - sign = fopen(sign_fname.c_str(), "rb"); + file = RsDirUtil::rs_fopen(fname.c_str(), "rb"); + sign = RsDirUtil::rs_fopen(sign_fname.c_str(), "rb"); // if failed then create files if((file == NULL) || (sign == NULL)){ @@ -274,8 +274,8 @@ bool p3ConfigMgr::backedUpFileSave(const std::string& fname, const std::string& std::cerr << "p3Config::backedUpFileSave() failed to open meta files " << fname << std::endl; #endif - file = fopen(fname.c_str(), "wb"); - sign = fopen(sign_fname.c_str(), "wb"); + file = RsDirUtil::rs_fopen(fname.c_str(), "wb"); + sign = RsDirUtil::rs_fopen(sign_fname.c_str(), "wb"); if((file == NULL) || (sign == NULL)){ std::cerr << "p3Config::backedUpFileSave() failed to open backup meta files" << fname_backup << std::endl; @@ -319,8 +319,8 @@ bool p3ConfigMgr::backedUpFileSave(const std::string& fname, const std::string& if((size_file) > 0 && (size_sign > 0)){ // now write actual back-up file - file = fopen(fname_backup.c_str(), "wb"); - sign = fopen(sign_fname_backup.c_str(), "wb"); + file = RsDirUtil::rs_fopen(fname_backup.c_str(), "wb"); + sign = RsDirUtil::rs_fopen(sign_fname_backup.c_str(), "wb"); if((file == NULL) || (sign == NULL)){ #ifdef CONFIG_DEBUG @@ -629,8 +629,8 @@ bool p3ConfigMgr::checkForGlobalSigConfig() std::string fName = basedir + "/" + metafname; std::string sigName = basedir + "/" + metasigfname; - metaFile = fopen(fName.c_str(), "r"); - metaSig = fopen(sigName.c_str(), "r"); + metaFile = RsDirUtil::rs_fopen(fName.c_str(), "r"); + metaSig = RsDirUtil::rs_fopen(sigName.c_str(), "r"); // check if files exist if((metaFile != NULL) && (metaSig != NULL)) @@ -1060,7 +1060,7 @@ bool p3Config::backedUpFileSave(const std::string& cfg_fname, const std::string& #endif // open file from which to collect buffer - cfg_file = fopen(cfg_fname.c_str(), "rb"); + cfg_file = RsDirUtil::rs_fopen(cfg_fname.c_str(), "rb"); // if it fails to open, create file,but back-up file will now be empty if(cfg_file == NULL){ @@ -1068,7 +1068,7 @@ bool p3Config::backedUpFileSave(const std::string& cfg_fname, const std::string& std::cerr << "p3Config::backedUpFileSave() fopen failed for file: " << cfg_fname << std::endl; #endif - cfg_file = fopen(cfg_fname.c_str(), "wb"); + cfg_file = RsDirUtil::rs_fopen(cfg_fname.c_str(), "wb"); if(cfg_file == NULL) { @@ -1116,7 +1116,7 @@ bool p3Config::backedUpFileSave(const std::string& cfg_fname, const std::string& { // now write actual back-up file - cfg_file = fopen(cfg_fname_backup.c_str(), "wb"); + cfg_file = RsDirUtil::rs_fopen(cfg_fname_backup.c_str(), "wb"); if(cfg_file == NULL){ #ifdef CONFIG_DEBUG diff --git a/libretroshare/src/pqi/pqibin.cc b/libretroshare/src/pqi/pqibin.cc index 3ca7d04e7..bf39c87e6 100644 --- a/libretroshare/src/pqi/pqibin.cc +++ b/libretroshare/src/pqi/pqibin.cc @@ -23,13 +23,10 @@ * */ - - - - #include "pqi/pqibin.h" #include "pqi/authssl.h" #include "util/rsnet.h" +#include "util/rsdir.h" // #define DEBUG_PQIBIN @@ -40,23 +37,23 @@ BinFileInterface::BinFileInterface(const char *fname, int flags) if ((bin_flags & BIN_FLAGS_READABLE) && (bin_flags & BIN_FLAGS_WRITEABLE)) { - buf = fopen(fname, "rb+"); + buf = RsDirUtil::rs_fopen(fname, "rb+"); /* if the file don't exist */ if (!buf) { - buf = fopen(fname, "wb+"); + buf = RsDirUtil::rs_fopen(fname, "wb+"); } } else if (bin_flags & BIN_FLAGS_READABLE) { - buf = fopen(fname, "rb"); + buf = RsDirUtil::rs_fopen(fname, "rb"); } else if (bin_flags & BIN_FLAGS_WRITEABLE) { // This is enough to remove old file in Linux... // but not in windows.... (what to do) - buf = fopen(fname, "wb"); + buf = RsDirUtil::rs_fopen(fname, "wb"); fflush(buf); /* this might help windows! */ } else @@ -430,7 +427,7 @@ uint64_t BinMemInterface::bytecount() bool BinMemInterface::writetofile(const char *fname) { - FILE *fd = fopen(fname, "wb"); + FILE *fd = RsDirUtil::rs_fopen(fname, "wb"); if (!fd) { return false; @@ -449,7 +446,7 @@ bool BinMemInterface::writetofile(const char *fname) bool BinMemInterface::readfromfile(const char *fname) { - FILE *fd = fopen(fname, "rb"); + FILE *fd = RsDirUtil::rs_fopen(fname, "rb"); if (!fd) { return false; diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index f7c6fc3f6..b68199b31 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -804,7 +804,7 @@ continue_packet: // if(pktlen == 17306) // { -// FILE *f = fopen("dbug.packet.bin","w"); +// FILE *f = RsDirUtil::rs_fopen("dbug.packet.bin","w"); // fwrite(block,pktlen,1,f) ; // fclose(f) ; // exit(-1) ; diff --git a/libretroshare/src/pqi/sslfns.cc b/libretroshare/src/pqi/sslfns.cc index 05f9764cc..c977e1bd2 100644 --- a/libretroshare/src/pqi/sslfns.cc +++ b/libretroshare/src/pqi/sslfns.cc @@ -32,6 +32,7 @@ #include "pqi/sslfns.h" #include "pqi/pqi_base.h" +#include "util/rsdir.h" #include #include @@ -115,7 +116,7 @@ X509_REQ *GenerateX509Req( // open the file. FILE *out; - if (NULL == (out = fopen(pkey_file.c_str(), "w"))) + if (NULL == (out = RsDirUtil::rs_fopen(pkey_file.c_str(), "w"))) { fprintf(stderr,"GenerateX509Req: Couldn't Create Key File!"); fprintf(stderr," : %s\n", pkey_file.c_str()); @@ -144,7 +145,7 @@ X509_REQ *GenerateX509Req( /********** Test Loading the private Key.... ************/ FILE *tst_in = NULL; EVP_PKEY *tst_pkey = NULL; - if (NULL == (tst_in = fopen(pkey_file.c_str(), "rb"))) + if (NULL == (tst_in = RsDirUtil::rs_fopen(pkey_file.c_str(), "rb"))) { fprintf(stderr,"GenerateX509Req() Couldn't Open Private Key"); fprintf(stderr," : %s\n", pkey_file.c_str()); @@ -692,7 +693,7 @@ int LoadCheckX509(const char *cert_file, std::string &issuerName, std::string &l * and checks the certificate */ - FILE *tmpfp = fopen(cert_file, "r"); + FILE *tmpfp = RsDirUtil::rs_fopen(cert_file, "r"); if (tmpfp == NULL) { #ifdef AUTHSSL_DEBUG diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 2f07dd026..f924e8605 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -36,6 +36,7 @@ #include "util/rsdebug.h" #include "util/rsdir.h" #include "util/rsrandom.h" +#include "util/folderiterator.h" #include "retroshare/rsinit.h" #include "rsserver/rsloginhandler.h" @@ -742,16 +743,20 @@ void RsInit::setupBaseDir() // use directory "Data" in portable version RsInitConfig::basedir = "Data"; } else { - char *h = getenv("APPDATA"); + wchar_t *wh = _wgetenv(L"APPDATA"); + std::string h; + librs::util::ConvertUtf16ToUtf8(std::wstring(wh), h); std::cerr << "retroShare::basedir() -> $APPDATA = "; std::cerr << h << std::endl; char *h2 = getenv("HOMEDRIVE"); std::cerr << "retroShare::basedir() -> $HOMEDRIVE = "; std::cerr << h2 << std::endl; - char *h3 = getenv("HOMEPATH"); + wchar_t *wh3 = _wgetenv(L"HOMEPATH"); + std::string h3; + librs::util::ConvertUtf16ToUtf8(std::wstring(wh3), h3); std::cerr << "retroShare::basedir() -> $HOMEPATH = "; std::cerr << h3 << std::endl; - if (h == NULL) + if (h.empty()) { // generating default std::cerr << "load_check_basedir() getEnv Error --Win95/98?"; @@ -896,24 +901,34 @@ bool getAvailableAccounts(std::list &ids) * files checked to see if they have changed. (rehashed) */ - struct dirent *dent; - struct stat buf; - /* check for the dir existance */ - DIR *dir = opendir(RsInitConfig::basedir.c_str()); - if (!dir) + librs::util::FolderIterator dirIt(RsInitConfig::basedir); + if (!dirIt.isValid()) { std::cerr << "Cannot Open Base Dir - No Available Accounts" << std::endl; exit(1); } - while(NULL != (dent = readdir(dir))) + struct stat64 buf; + + while (dirIt.readdir()) { /* check entry type */ - std::string fname = dent -> d_name; + std::string fname; + dirIt.d_name(fname); std::string fullname = RsInitConfig::basedir + "/" + fname; +#ifdef FIM_DEBUG + std::cerr << "calling stats on " << fullname < &ids) } } } - closedir(dir) ; + /* close directory */ + dirIt.closedir(); for(it = directories.begin(); it != directories.end(); it++) { @@ -1266,7 +1282,7 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std /* Save cert to file */ // open the file. FILE *out = NULL; - if (NULL == (out = fopen(cert_name.c_str(), "w"))) + if (NULL == (out = RsDirUtil::rs_fopen(cert_name.c_str(), "w"))) { fprintf(stderr,"RsGenerateCert() Couldn't create Cert File"); fprintf(stderr," : %s\n", cert_name.c_str()); @@ -1306,7 +1322,7 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std std::cerr << "Mv Config Dir from: " << tmpbase << " to: " << finalbase; std::cerr << std::endl; - if (0 > rename(tmpbase.c_str(), finalbase.c_str())) + if (!RsDirUtil::renameFile(tmpbase, finalbase)) { std::cerr << "rename FAILED" << std::endl; } @@ -1502,7 +1518,7 @@ bool RsInit::get_configinit(std::string dir, std::string &id) initfile += configInitFile; // open and read in the lines. - FILE *ifd = fopen(initfile.c_str(), "r"); + FILE *ifd = RsDirUtil::rs_fopen(initfile.c_str(), "r"); char path[1024]; int i; @@ -1532,7 +1548,7 @@ bool RsInit::create_configinit(std::string dir, std::string id) initfile += configInitFile; // open and read in the lines. - FILE *ifd = fopen(initfile.c_str(), "w"); + FILE *ifd = RsDirUtil::rs_fopen(initfile.c_str(), "w"); if (ifd != NULL) { diff --git a/libretroshare/src/rsserver/rsloginhandler.cc b/libretroshare/src/rsserver/rsloginhandler.cc index 597ac11a3..850dfe276 100644 --- a/libretroshare/src/rsserver/rsloginhandler.cc +++ b/libretroshare/src/rsserver/rsloginhandler.cc @@ -3,6 +3,7 @@ #include #include #include "rsloginhandler.h" +#include "util/rsdir.h" #ifdef UBUNTU #include @@ -195,7 +196,7 @@ bool RsLoginHandler::tryAutoLogin(const std::string& ssl_id,std::string& ssl_pas /******************** OSX KeyChain stuff *****************************/ #else /* UNIX, but not UBUNTU or APPLE */ - FILE* helpFile = fopen(getAutologinFileName.c_str(), "r"); + FILE* helpFile = RsDirUtil::rs_fopen(getAutologinFileName.c_str(), "r"); if(helpFile == NULL){ std::cerr << "\nFailed to open help file\n" << std::endl; @@ -265,7 +266,7 @@ bool RsLoginHandler::tryAutoLogin(const std::string& ssl_id,std::string& ssl_pas int datalen = 0; /* open the data to the file */ - FILE *fp = fopen(getAutologinFileName(ssl_id).c_str(), "rb"); + FILE *fp = RsDirUtil::rs_fopen(getAutologinFileName(ssl_id).c_str(), "rb"); if (fp != NULL) { fseek(fp, 0, SEEK_END); @@ -407,7 +408,7 @@ bool RsLoginHandler::enableAutoLogin(const std::string& ssl_id,const std::string #else /* WARNING: Autologin is inherently unsafe */ - FILE* helpFile = fopen(getAutologinFileName.c_str(), "w"); + FILE* helpFile = RsDirUtil::rs_fopen(getAutologinFileName.c_str(), "w"); if(helpFile == NULL){ std::cerr << "\nRsStoreAutoLogin(): Failed to open help file\n" << std::endl; @@ -493,7 +494,7 @@ bool RsLoginHandler::enableAutoLogin(const std::string& ssl_id,const std::string //std::cerr << std::endl; /* save the data to the file */ - FILE *fp = fopen(getAutologinFileName(ssl_id).c_str(), "wb"); + FILE *fp = RsDirUtil::rs_fopen(getAutologinFileName(ssl_id).c_str(), "wb"); if (fp != NULL) { fwrite(DataOut.pbData, 1, DataOut.cbData, fp); @@ -599,7 +600,7 @@ bool RsLoginHandler::clearAutoLogin(const std::string& ssl_id) std::string passwdfile = getAutologinFileName(ssl_id) ; - FILE *fp = fopen(passwdfile.c_str(), "wb"); + FILE *fp = RsDirUtil::rs_fopen(passwdfile.c_str(), "wb"); if (fp != NULL) { @@ -626,7 +627,7 @@ bool RsLoginHandler::checkAndStoreSSLPasswdIntoGPGFile(const std::string& ssl_id // std::cerr << "let's store the ssl Password into a pgp ecrypted file" << std::endl; - FILE *sslPassphraseFile = fopen(getSSLPasswdFileName(ssl_id).c_str(), "r"); + FILE *sslPassphraseFile = RsDirUtil::rs_fopen(getSSLPasswdFileName(ssl_id).c_str(), "r"); if(sslPassphraseFile != NULL) // already have it. { @@ -634,7 +635,7 @@ bool RsLoginHandler::checkAndStoreSSLPasswdIntoGPGFile(const std::string& ssl_id return true ; } - sslPassphraseFile = fopen(getSSLPasswdFileName(ssl_id).c_str(), "w"); + sslPassphraseFile = RsDirUtil::rs_fopen(getSSLPasswdFileName(ssl_id).c_str(), "w"); if(sslPassphraseFile == NULL) { @@ -674,7 +675,7 @@ bool RsLoginHandler::getSSLPasswdFromGPGFile(const std::string& ssl_id,std::stri // Let's read the password from an encrypted file // Let's check if there's a ssl_passpharese_file that we can decrypt with PGP // - FILE *sslPassphraseFile = fopen(getSSLPasswdFileName(ssl_id).c_str(), "r"); + FILE *sslPassphraseFile = RsDirUtil::rs_fopen(getSSLPasswdFileName(ssl_id).c_str(), "r"); if (sslPassphraseFile == NULL) { diff --git a/libretroshare/src/tcponudp/tcpstream.cc b/libretroshare/src/tcponudp/tcpstream.cc index 022a85c72..a2f831d69 100644 --- a/libretroshare/src/tcponudp/tcpstream.cc +++ b/libretroshare/src/tcponudp/tcpstream.cc @@ -2506,7 +2506,7 @@ uint32 TcpStream::int_rbytes() static FILE *bc_fd = 0; int setupBinaryCheck(std::string fname) { - bc_fd = fopen(fname.c_str(), "r"); + bc_fd = RsDirUtil::rs_fopen(fname.c_str(), "r"); return 1; } diff --git a/libretroshare/src/util/rsdebug.cc b/libretroshare/src/util/rsdebug.cc index d4e690fd2..29ea59a1e 100644 --- a/libretroshare/src/util/rsdebug.cc +++ b/libretroshare/src/util/rsdebug.cc @@ -23,11 +23,9 @@ * */ - - - #include "util/rsdebug.h" #include "util/rsthreads.h" +#include "util/rsdir.h" #include #include @@ -57,7 +55,7 @@ int setDebugCrashMode(const char *cfile) RsStackMutex stack(logMtx); /******** LOCKED ****************/ crashfile = cfile; /* if the file exists - then we crashed, save it */ - FILE *tmpin = fopen(crashfile.c_str(), "r"); + FILE *tmpin = RsDirUtil::rs_fopen(crashfile.c_str(), "r"); if (tmpin) { /* see how long it is */ @@ -71,7 +69,7 @@ int setDebugCrashMode(const char *cfile) /* go back to the start */ fseek(tmpin, 0, SEEK_SET); - FILE *tmpout = fopen(crashfile_save.c_str(), "w"); + FILE *tmpout = RsDirUtil::rs_fopen(crashfile_save.c_str(), "w"); int da_size = 10240; char dataarray[da_size]; /* 10k */ unsigned int da_read = 0; @@ -131,7 +129,7 @@ int clearDebugCrashLog() debugMode = RS_DEBUG_STDERR; /* just open the file, and then close */ - FILE *tmpin = fopen(crashfile.c_str(), "w"); + FILE *tmpin = RsDirUtil::rs_fopen(crashfile.c_str(), "w"); fclose(tmpin); return 1; @@ -147,7 +145,7 @@ int setDebugFile(const char *fname) int locked_setDebugFile(const char *fname) { - if (NULL != (ofd = fopen(fname, "w"))) + if (NULL != (ofd = RsDirUtil::rs_fopen(fname, "w"))) { fprintf(stderr, "Logging redirected to %s\n", fname); debugMode = RS_DEBUG_LOGFILE; diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc index 7581f0e90..6492806eb 100644 --- a/libretroshare/src/util/rsdir.cc +++ b/libretroshare/src/util/rsdir.cc @@ -582,15 +582,8 @@ bool RsDirUtil::getFileHash(const std::string& filepath, std::string &hash, uint unsigned char sha_buf[SHA_DIGEST_LENGTH]; unsigned char gblBuf[512]; -#ifdef WINDOWS_SYS - std::wstring filepathW; - librs::util::ConvertUtf8ToUtf16(filepath, filepathW); - if (NULL == (fd = _wfopen(filepathW.c_str(), L"rb"))) + if (NULL == (fd = RsDirUtil::rs_fopen(filepath.c_str(), "rb"))) return false; -#else - if (NULL == (fd = fopen64(filepath.c_str(), "rb"))) - return false; -#endif /* determine size */ fseeko64(fd, 0, SEEK_END); @@ -645,18 +638,18 @@ bool RsDirUtil::getFileHash(const std::string& filepath, std::string &hash, uint bool RsDirUtil::renameFile(const std::string& from, const std::string& to) { - int loops = 0; + int loops = 0; -#if defined(WIN32) || defined(MINGW) || defined(__CYGWIN__) -#ifdef WIN_CROSS_UBUNTU - std::wstring f,t ; - for(int i=0;i