9#include "klee/Config/config.h"
14#include "llvm/Support/FileSystem.h"
25 std::string &ErrorInfo)
26 :
llvm::raw_ostream(), pos(0) {
29#if LLVM_VERSION_CODE >= LLVM_VERSION(7, 0)
31 llvm::sys::fs::openFileForWrite(Filename, FD);
34 llvm::sys::fs::openFileForWrite(Filename, FD, llvm::sys::fs::F_None);
37 ErrorInfo = EC.message();
45 strm.next_in = Z_NULL;
46 strm.next_out = buffer;
50 const auto ret = deflateInit2(&strm, Z_BEST_COMPRESSION, Z_DEFLATED, 31,
54 ErrorInfo =
"Deflate initialisation returned with error: " + std::to_string(ret);
57void compressed_fd_ostream::writeFullCompressedData() {
59 if (strm.avail_out == 0) {
60 write_file(
reinterpret_cast<const char *
>(buffer),
BUFSIZE);
61 strm.next_out = buffer;
66void compressed_fd_ostream::flush_compressed_data() {
71 int deflate_res = Z_OK;
72 while (deflate_res == Z_OK) {
74 writeFullCompressedData();
75 deflate_res = deflate(&strm, Z_FINISH);
77 assert(deflate_res == Z_STREAM_END);
78 write_file(
reinterpret_cast<const char *
>(buffer),
BUFSIZE - strm.avail_out);
81compressed_fd_ostream::~compressed_fd_ostream() {
84 flush_compressed_data();
90void compressed_fd_ostream::write_impl(
const char *Ptr,
size_t Size) {
92 const_cast<unsigned char *
>(
reinterpret_cast<const unsigned char *
>(Ptr));
96 while (strm.avail_in != 0) {
98 const auto res
__attribute__ ((unused)) = deflate(&strm, Z_NO_FLUSH);
100 writeFullCompressedData();
104void compressed_fd_ostream::write_file(
const char *Ptr,
size_t Size) {
106 assert(FD >= 0 &&
"File already closed");
108 ssize_t ret = ::write(FD, Ptr, Size);
110 if (errno == EINTR || errno == EAGAIN)
112 assert(0 &&
"Could not write to file");
void *__dso_handle __attribute__((__weak__))
compressed_fd_ostream(const std::string &Filename, std::string &ErrorInfo)