Commit 5ff5945f authored by Hal Finkel's avatar Hal Finkel
Browse files

Don't pass O_CREAT when not necessary

parent 3faeace6
......@@ -84,10 +84,11 @@ GenericFileIO_MPI::~GenericFileIO_MPI() {
(void) MPI_File_close(&FH);
}
void GenericFileIO_MPI::open(const std::string &FN, bool ForReading) {
void GenericFileIO_MPI::open(const std::string &FN, bool ForReading, bool MustExist) {
FileName = FN;
int amode = ForReading ? MPI_MODE_RDONLY : (MPI_MODE_WRONLY | MPI_MODE_CREATE);
int amode = ForReading ? MPI_MODE_RDONLY : (MPI_MODE_WRONLY |
(!MustExist ? MPI_MODE_CREATE : 0));
if (MPI_File_open(Comm, const_cast<char *>(FileName.c_str()), amode,
MPI_INFO_NULL, &FH) != MPI_SUCCESS)
throw runtime_error((!ForReading ? "Unable to create the file: " :
......@@ -183,10 +184,11 @@ GenericFileIO_POSIX::~GenericFileIO_POSIX() {
if (FH != -1) close(FH);
}
void GenericFileIO_POSIX::open(const std::string &FN, bool ForReading) {
void GenericFileIO_POSIX::open(const std::string &FN, bool ForReading, bool MustExist) {
FileName = FN;
int flags = ForReading ? O_RDONLY : (O_WRONLY | O_CREAT);
int flags = ForReading ? O_RDONLY : (O_WRONLY |
(!MustExist ? O_CREAT : 0));
int mode = S_IRUSR | S_IWUSR | S_IRGRP;
errno = 0;
if ((FH = ::open(FileName.c_str(), flags, mode)) == -1)
......@@ -784,7 +786,7 @@ nocomp:
else
FH.get() = new GenericFileIO_POSIX();
FH.get()->open(LocalFileName);
FH.get()->open(LocalFileName, false, true);
uint64_t Offset = RHLocal.Start;
for (size_t i = 0; i < Vars.size(); ++i) {
......
......@@ -64,7 +64,7 @@ public:
virtual ~GenericFileIO() {}
public:
virtual void open(const std::string &FN, bool ForReading = false) = 0;
virtual void open(const std::string &FN, bool ForReading = false, bool MustExist = false) = 0;
virtual void setSize(size_t sz) = 0;
virtual void read(void *buf, size_t count, off_t offset,
const std::string &D) = 0;
......@@ -82,7 +82,7 @@ public:
virtual ~GenericFileIO_MPI();
public:
virtual void open(const std::string &FN, bool ForReading = false);
virtual void open(const std::string &FN, bool ForReading = false, bool MustExist = false);
virtual void setSize(size_t sz);
virtual void read(void *buf, size_t count, off_t offset, const std::string &D);
virtual void write(const void *buf, size_t count, off_t offset, const std::string &D);
......@@ -108,7 +108,7 @@ public:
~GenericFileIO_POSIX();
public:
void open(const std::string &FN, bool ForReading = false);
void open(const std::string &FN, bool ForReading = false, bool MustExist = false);
void setSize(size_t sz);
void read(void *buf, size_t count, off_t offset, const std::string &D);
void write(const void *buf, size_t count, off_t offset, const std::string &D);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment