about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--include/klee/Internal/Support/FileHandling.h19
-rw-r--r--lib/Support/CMakeLists.txt1
-rw-r--r--lib/Support/FileHandling.cpp43
-rw-r--r--tools/klee/main.cpp34
4 files changed, 74 insertions, 23 deletions
diff --git a/include/klee/Internal/Support/FileHandling.h b/include/klee/Internal/Support/FileHandling.h
new file mode 100644
index 00000000..bee06b9b
--- /dev/null
+++ b/include/klee/Internal/Support/FileHandling.h
@@ -0,0 +1,19 @@
+//===-- FileHandling.h ------------------------------------------*- C++ -*-===//
+//
+//                     The KLEE Symbolic Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef __KLEE_FILE_HANDLING_H__
+#define __KLEE_FILE_HANDLING_H__
+#include "llvm/Support/raw_ostream.h"
+#include <string>
+
+namespace klee {
+llvm::raw_fd_ostream *klee_open_output_file(std::string &path,
+                                            std::string &error);
+}
+
+#endif
diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt
index 4e44fbc6..7145930f 100644
--- a/lib/Support/CMakeLists.txt
+++ b/lib/Support/CMakeLists.txt
@@ -9,6 +9,7 @@
 klee_add_component(kleeSupport
   CompressionStream.cpp
   ErrorHandling.cpp
+  FileHandling.cpp
   MemoryUsage.cpp
   PrintVersion.cpp
   RNG.cpp
diff --git a/lib/Support/FileHandling.cpp b/lib/Support/FileHandling.cpp
new file mode 100644
index 00000000..092a1af0
--- /dev/null
+++ b/lib/Support/FileHandling.cpp
@@ -0,0 +1,43 @@
+//===-- FileHandling.cpp --------------------------------------------------===//
+//
+//                     The KLEE Symbolic Virtual Machine
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "klee/Internal/Support/FileHandling.h"
+#include "klee/Config/Version.h"
+#include "klee/Config/config.h"
+#include "klee/Internal/Support/ErrorHandling.h"
+
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
+#include "llvm/Support/FileSystem.h"
+#endif
+
+namespace klee {
+
+llvm::raw_fd_ostream *klee_open_output_file(std::string &path,
+                                            std::string &error) {
+  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);
+  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);
+#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 4)
+  f = new llvm::raw_fd_ostream(path.c_str(), error, llvm::sys::fs::F_Binary);
+#else
+  f = new llvm::raw_fd_ostream(path.c_str(), error,
+                               llvm::raw_fd_ostream::F_Binary);
+#endif
+  if (!error.empty()) {
+    if (f)
+      delete f;
+    f = NULL;
+  }
+  return f;
+}
+}
diff --git a/tools/klee/main.cpp b/tools/klee/main.cpp
index a91c9fd1..9e36f949 100644
--- a/tools/klee/main.cpp
+++ b/tools/klee/main.cpp
@@ -9,18 +9,19 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "klee/Config/Version.h"
 #include "klee/ExecutionState.h"
 #include "klee/Expr.h"
-#include "klee/Interpreter.h"
-#include "klee/Statistics.h"
-#include "klee/Config/Version.h"
 #include "klee/Internal/ADT/KTest.h"
 #include "klee/Internal/ADT/TreeStream.h"
 #include "klee/Internal/Support/Debug.h"
+#include "klee/Internal/Support/ErrorHandling.h"
+#include "klee/Internal/Support/FileHandling.h"
 #include "klee/Internal/Support/ModuleUtil.h"
-#include "klee/Internal/System/Time.h"
 #include "klee/Internal/Support/PrintVersion.h"
-#include "klee/Internal/Support/ErrorHandling.h"
+#include "klee/Internal/System/Time.h"
+#include "klee/Interpreter.h"
+#include "klee/Statistics.h"
 
 #if LLVM_VERSION_CODE > LLVM_VERSION(3, 2)
 #include "llvm/IR/Constants.h"
@@ -385,27 +386,14 @@ llvm::raw_fd_ostream *KleeHandler::openOutputFile(const std::string &filename) {
   llvm::raw_fd_ostream *f;
   std::string Error;
   std::string path = getOutputFilename(filename);
-#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);
-  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);
-#elif LLVM_VERSION_CODE >= LLVM_VERSION(3,4)
-  f = new llvm::raw_fd_ostream(path.c_str(), Error, llvm::sys::fs::F_Binary);
-#else
-  f = new llvm::raw_fd_ostream(path.c_str(), Error, llvm::raw_fd_ostream::F_Binary);
-#endif
+  f = klee_open_output_file(path, Error);
   if (!Error.empty()) {
     klee_warning("error opening file \"%s\".  KLEE may have run out of file "
-               "descriptors: try to increase the maximum number of open file "
-               "descriptors by using ulimit (%s).",
-               filename.c_str(), Error.c_str());
-    delete f;
-    f = NULL;
+                 "descriptors: try to increase the maximum number of open file "
+                 "descriptors by using ulimit (%s).",
+                 path.c_str(), Error.c_str());
+    return NULL;
   }
-
   return f;
 }