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");
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
#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 );
}
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." );
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
+{
+}
const int repeat;
int iteration; // number of current repetition,
// starting at 0
+ int extraoflags;
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
virtual bool eof() const { return eof_flag; };
};
+class SGBinaryFile : public SGFile {
+public:
+ SGBinaryFile( const std::string& file, int repeat_ = 1 );
+};
+
#endif // _SG_FILE_HXX