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
This commit is contained in:
thunder2 2011-04-03 23:11:38 +00:00
parent bc78397a64
commit bc113326e4
17 changed files with 109 additions and 119 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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) ;

View file

@ -32,6 +32,7 @@
#include "pqi/sslfns.h"
#include "pqi/pqi_base.h"
#include "util/rsdir.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
@ -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