From 0a1613abe1d5ec9353001d68d6bb44bc64d97244 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Thu, 2 Oct 2008 12:46:57 -0400 Subject: [PATCH] Output: Verify output files are open after opening them. --- src/base/stats/text.cc | 8 +++++--- src/sim/serialize.cc | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc index 6f40d92c8..f65b77777 100644 --- a/src/base/stats/text.cc +++ b/src/base/stats/text.cc @@ -107,7 +107,8 @@ Text::open(std::ostream &_stream) mystream = false; stream = &_stream; - assert(valid()); + if (!valid()) + fatal("Unable to open output stream for writing\n"); } void @@ -118,13 +119,14 @@ Text::open(const std::string &file) mystream = true; stream = new ofstream(file.c_str(), ios::trunc); - assert(valid()); + if (!valid()) + fatal("Unable to open statistics file for writing\n"); } bool Text::valid() const { - return stream != NULL; + return stream != NULL && stream->good(); } void diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc index 7050779b2..a4851d3f6 100644 --- a/src/sim/serialize.cc +++ b/src/sim/serialize.cc @@ -405,6 +405,8 @@ Serializable::serializeAll(const std::string &cpt_dir) string cpt_file = dir + Checkpoint::baseFilename; ofstream outstream(cpt_file.c_str()); time_t t = time(NULL); + if (!outstream.is_open()) + fatal("Unable to open file %s for writing\n", cpt_file.c_str()); outstream << "// checkpoint generated: " << ctime(&t); globals.serialize(outstream);