1 //===-- FileHandling.cpp --------------------------------------------------===// 2 // 3 // The KLEE Symbolic Virtual Machine 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include "klee/Support/FileHandling.h" 10 11 #include "klee/Config/Version.h" 12 #include "klee/Config/config.h" 13 #include "klee/Support/ErrorHandling.h" 14 15 #include "llvm/Support/FileSystem.h" 16 17 #ifdef HAVE_ZLIB_H 18 #include "klee/Support/CompressionStream.h" 19 #endif 20 21 namespace klee { 22 23 std::unique_ptr<llvm::raw_fd_ostream> klee_open_output_file(const std::string & path,std::string & error)24klee_open_output_file(const std::string &path, std::string &error) { 25 error = ""; 26 std::unique_ptr<llvm::raw_fd_ostream> f; 27 std::error_code ec; 28 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 29 if (ec) 30 error = ec.message(); 31 if (!error.empty()) { 32 f.reset(nullptr); 33 } 34 return f; 35 } 36 37 #ifdef HAVE_ZLIB_H 38 std::unique_ptr<llvm::raw_ostream> klee_open_compressed_output_file(const std::string & path,std::string & error)39klee_open_compressed_output_file(const std::string &path, std::string &error) { 40 error = ""; 41 std::unique_ptr<llvm::raw_ostream> f(new compressed_fd_ostream(path, error)); 42 if (!error.empty()) { 43 f.reset(nullptr); 44 } 45 return f; 46 } 47 #endif 48 } 49