misc: Merge branch 'release-staging-v20.1.0.0' into develop
[gem5.git] / src / base / output.cc
index dc85c2a5454f78041e2a95f91011305353302bd4..5703a379caf9fdcfafffedc36ab4c94c253eeeeb 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 ARM Limited
+ * Copyright (c) 2020 Barkhausen Institut
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Nathan Binkert
- *          Chris Emmons
- *          Andreas Sandberg
- *          Sascha Bischoff
  */
 
 #include "base/output.hh"
@@ -58,7 +54,7 @@
 #include <cstdlib>
 #include <fstream>
 
-#include "base/misc.hh"
+#include "base/logging.hh"
 
 using namespace std;
 
@@ -88,9 +84,11 @@ OutputFile<StreamType>::OutputFile(const OutputDirectory &dir,
     _mode(mode), _recreateable(recreateable),
     _fstream(static_cast<stream_type_t *>(_stream))
 {
-    _fstream->open(dir.resolve(_name).c_str(), _mode);
+    std::string resolved_path = dir.resolve(_name);
+
+    _fstream->open(resolved_path.c_str(), _mode);
 
-    assert(_fstream->is_open());
+    panic_if(!_fstream->is_open(), "Failed to open \"%s\"\n", resolved_path);
 }
 
 template<class StreamType>
@@ -147,6 +145,11 @@ OutputDirectory::checkForStdio(const string &name)
 void
 OutputDirectory::close(OutputStream *file)
 {
+    if (file == &stdout || file == &stderr) {
+        file->stream()->flush();
+        return;
+    }
+
     auto i = files.find(file->name());
     if (i == files.end())
         fatal("Attempted to close an unregistred file stream");