about summary refs log tree commit diff homepage
path: root/lib/Support
diff options
context:
space:
mode:
authorJulian Büning <julian.buening@rwth-aachen.de>2018-10-03 14:42:37 +0200
committerCristian Cadar <c.cadar@imperial.ac.uk>2018-10-23 18:57:53 +0300
commit2b34877c5dbf24eabf331a124b1e68d901a72cba (patch)
tree4d6f4a753d9d36a18c482cf0c8d4b8dc550bafb8 /lib/Support
parentd032742a963e7d8e83dad509dd1c95b4e1a34436 (diff)
downloadklee-2b34877c5dbf24eabf331a124b1e68d901a72cba.tar.gz
refactor klee_open_output_file to return std::unique_ptr
and introduce klee_open_compressed_output_file with similar behavior
along some other minor improvements
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/CompressionStream.cpp3
-rw-r--r--lib/Support/FileHandling.cpp33
2 files changed, 27 insertions, 9 deletions
diff --git a/lib/Support/CompressionStream.cpp b/lib/Support/CompressionStream.cpp
index 01fe1352..d17e1df1 100644
--- a/lib/Support/CompressionStream.cpp
+++ b/lib/Support/CompressionStream.cpp
@@ -23,7 +23,7 @@
 
 namespace klee {
 
-compressed_fd_ostream::compressed_fd_ostream(const char *Filename,
+compressed_fd_ostream::compressed_fd_ostream(const std::string &Filename,
                                              std::string &ErrorInfo)
     : llvm::raw_ostream(), pos(0) {
   ErrorInfo = "";
@@ -38,6 +38,7 @@ compressed_fd_ostream::compressed_fd_ostream(const char *Filename,
   if (EC) {
     ErrorInfo = EC.message();
     FD = -1;
+    return;
   }
   // Initialize the compression library
   strm.zalloc = Z_NULL;
diff --git a/lib/Support/FileHandling.cpp b/lib/Support/FileHandling.cpp
index 3e156f3c..068ce44b 100644
--- a/lib/Support/FileHandling.cpp
+++ b/lib/Support/FileHandling.cpp
@@ -7,6 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 #include "klee/Internal/Support/FileHandling.h"
+
 #include "klee/Config/Version.h"
 #include "klee/Config/config.h"
 #include "klee/Internal/Support/ErrorHandling.h"
@@ -15,25 +16,41 @@
 #include "llvm/Support/FileSystem.h"
 #endif
 
+#ifdef HAVE_ZLIB_H
+#include "klee/Internal/Support/CompressionStream.h"
+#endif
+
 namespace klee {
 
-llvm::raw_fd_ostream *klee_open_output_file(std::string &path,
-                                            std::string &error) {
-  llvm::raw_fd_ostream *f;
+std::unique_ptr<llvm::raw_fd_ostream>
+klee_open_output_file(const std::string &path, std::string &error) {
+  error = "";
+  std::unique_ptr<llvm::raw_fd_ostream> f;
 #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
   std::error_code ec;
-  f = new llvm::raw_fd_ostream(path.c_str(), ec, llvm::sys::fs::F_None);
+  f = std::unique_ptr<llvm::raw_fd_ostream>(new llvm::raw_fd_ostream(path.c_str(), ec, llvm::sys::fs::F_None)); // FIXME C++14
   if (ec)
     error = ec.message();
 #elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
-  f = new llvm::raw_fd_ostream(path.c_str(), error, llvm::sys::fs::F_None);
+  f = std::unique_ptr<llvm::raw_fd_ostream>(new llvm::raw_fd_ostream(path.c_str(), error, llvm::sys::fs::F_None)); // FIXME C++14
 #else
-  f = new llvm::raw_fd_ostream(path.c_str(), error, llvm::sys::fs::F_Binary);
+  f = std::unique_ptr<llvm::raw_fd_ostream>(new llvm::raw_fd_ostream(path.c_str(), error, llvm::sys::fs::F_Binary)); // FIXME C++14
 #endif
   if (!error.empty()) {
-    delete f;
-    f = NULL;
+    f.reset(nullptr);
   }
   return f;
 }
+
+#ifdef HAVE_ZLIB_H
+std::unique_ptr<llvm::raw_ostream>
+klee_open_compressed_output_file(const std::string &path, std::string &error) {
+  error = "";
+  std::unique_ptr<llvm::raw_ostream> f(new compressed_fd_ostream(path, error));
+  if (!error.empty()) {
+    f.reset(nullptr);
+  }
+  return f;
+}
+#endif
 }