ostream *
OutputDirectory::openFile(const string &filename,
- ios_base::openmode mode)
+ ios_base::openmode mode, bool no_gz)
{
- if (filename.find(".gz", filename.length()-3) < filename.length()) {
+ bool gz = !no_gz;
+ gz = gz && filename.find(".gz", filename.length()-3) < filename.length();
+ if (gz) {
ogzstream *file = new ogzstream(filename.c_str(), mode);
if (!file->is_open())
fatal("Cannot open file %s", filename);
}
ostream *
-OutputDirectory::create(const string &name, bool binary)
+OutputDirectory::create(const string &name, bool binary, bool no_gz)
{
ostream *file = checkForStdio(name);
if (file)
string filename = resolve(name);
ios_base::openmode mode =
ios::trunc | (binary ? ios::binary : (ios::openmode)0);
- file = openFile(filename, mode);
+ file = openFile(filename, mode, no_gz);
return file;
}
*
* @param filename file to open
* @param mode attributes to open file with
+ * @param no_gz true to disable opening the file as a gzip compressed output
+ * stream; false otherwise
* @return stream pointer to opened file; will cause sim fail on error
*/
std::ostream *openFile(const std::string &filename,
- std::ios_base::openmode mode = std::ios::trunc);
+ std::ios_base::openmode mode = std::ios::trunc,
+ bool no_gz = false);
/**
* Sets name of this directory.
* @param name name of file to create (without this directory's name
* leading it)
* @param binary true to create a binary file; false otherwise
+ * @param no_gz true to disable creating a gzip compressed output stream;
+ * false otherwise
* @return stream to the opened file
*/
- std::ostream *create(const std::string &name, bool binary = false);
+ std::ostream *create(const std::string &name, bool binary = false,
+ bool no_gz = false);
/**
* Closes a file stream.
if (offset == 0) {
// create a new file (truncate)
- os = simout.create(filename, true);
+ os = simout.create(filename, true, true);
} else {
// do not truncate file if offset is non-zero
// (ios::in flag is required as well to keep the existing data
// intact, otherwise existing data will be zeroed out.)
os = simout.openFile(simout.directory() + filename,
- ios::in | ios::out | ios::binary);
+ ios::in | ios::out | ios::binary, true);
}
if (!os)
panic("could not open file %s\n", filename);