Introduce SGBinaryFile
For Windows, default file mode is TEXT. If binary files should be created _O_BINARY shall be or'ed to the open flags. This is not necessary on *nixes. Introduce a SGBinaryFile as extension to SGFile which adds the flag upon construction on Windows. This should keep existing behaviour for all other usages of SGFile.
This commit is contained in:
@@ -612,7 +612,7 @@ HTTPRepository::failure() const
|
||||
virtual void gotBodyData(const char* s, int n)
|
||||
{
|
||||
if (!file.get()) {
|
||||
file.reset(new SGFile(pathInRepo.str()));
|
||||
file.reset(new SGBinaryFile(pathInRepo.str()));
|
||||
if (!file->open(SG_IO_OUT)) {
|
||||
SG_LOG(SG_TERRASYNC, SG_WARN, "unable to create file " << pathInRepo);
|
||||
_directory->repository()->http->cancelRequest(this, "Unable to create output file");
|
||||
@@ -664,7 +664,7 @@ HTTPRepository::failure() const
|
||||
std::string fileName; // if empty, we're getting the directory itself
|
||||
SGPath pathInRepo;
|
||||
simgear::sha1nfo hashContext;
|
||||
std::auto_ptr<SGFile> file;
|
||||
std::auto_ptr<SGBinaryFile> file;
|
||||
};
|
||||
|
||||
class DirGetRequest : public HTTPRepoGetRequest
|
||||
|
||||
@@ -45,8 +45,9 @@
|
||||
#include "sg_file.hxx"
|
||||
|
||||
|
||||
SGFile::SGFile(const std::string &file, int repeat_)
|
||||
: file_name(file), fp(-1), eof_flag(true), repeat(repeat_), iteration(0)
|
||||
SGFile::SGFile(const std::string &file, int repeat_, int extraoflags_ )
|
||||
: file_name(file), fp(-1), eof_flag(true), repeat(repeat_), iteration(0),
|
||||
extraoflags(extraoflags_)
|
||||
{
|
||||
set_type( sgFileType );
|
||||
}
|
||||
@@ -70,13 +71,13 @@ bool SGFile::open( const SGProtocolDir d ) {
|
||||
|
||||
if ( get_dir() == SG_IO_OUT ) {
|
||||
#ifdef _WIN32
|
||||
int mode = 00666;
|
||||
int mode = _S_IREAD | _S_IWRITE;
|
||||
#else
|
||||
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
||||
#endif
|
||||
fp = ::open( file_name.c_str(), O_WRONLY | O_CREAT | O_TRUNC, mode );
|
||||
fp = ::open( file_name.c_str(), O_WRONLY | O_CREAT | O_TRUNC | extraoflags, mode );
|
||||
} else if ( get_dir() == SG_IO_IN ) {
|
||||
fp = ::open( file_name.c_str(), O_RDONLY );
|
||||
fp = ::open( file_name.c_str(), O_RDONLY | extraoflags );
|
||||
} else {
|
||||
SG_LOG( SG_IO, SG_ALERT,
|
||||
"Error: bidirection mode not available for files." );
|
||||
@@ -178,3 +179,12 @@ bool SGFile::close() {
|
||||
eof_flag = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
SGBinaryFile::SGBinaryFile( const std::string& file, int repeat_ ) :
|
||||
#ifdef _WIN32
|
||||
SGFile(file,repeat_, _O_BINARY)
|
||||
#else
|
||||
SGFile(file,repeat_, 0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ class SGFile : public SGIOChannel {
|
||||
const int repeat;
|
||||
int iteration; // number of current repetition,
|
||||
// starting at 0
|
||||
int extraoflags;
|
||||
|
||||
public:
|
||||
|
||||
@@ -50,7 +51,7 @@ public:
|
||||
* @param file name of file to open
|
||||
* @param repeat On eof restart at the beginning of the file
|
||||
*/
|
||||
SGFile( const std::string& file, int repeat_ = 1 );
|
||||
SGFile( const std::string& file, int repeat_ = 1, int extraoflags = 0);
|
||||
|
||||
/**
|
||||
* Create an SGFile from an existing, open file-descriptor
|
||||
@@ -85,4 +86,9 @@ public:
|
||||
virtual bool eof() const { return eof_flag; };
|
||||
};
|
||||
|
||||
class SGBinaryFile : public SGFile {
|
||||
public:
|
||||
SGBinaryFile( const std::string& file, int repeat_ = 1 );
|
||||
};
|
||||
|
||||
#endif // _SG_FILE_HXX
|
||||
|
||||
Reference in New Issue
Block a user