17 const std::string &tmp_dir) {
22 const std::string &tmp_dir)
23 : in_memory_threshold_(in_memory_threshold)
40 int retval = fclose(
fp_);
73 buf_ =
reinterpret_cast<unsigned char *
>(smalloc(len));
77 buf_ =
reinterpret_cast<unsigned char *
>(srealloc(
buf_, newsize));
85 uint64_t bytes_written = fwrite(source, 1, len,
fp_);
86 if (bytes_written != len) {
88 "could not append to temporary file %s: length %lu, "
89 "actually written %lu, error %d",
101 int retval = fclose(
fp_);
112 buf_ =
reinterpret_cast<unsigned char *
>(srealloc(
buf_,
pos_));
123 int64_t actual_len = (pos + len <=
size_) ? len
124 : static_cast<int64_t>(
size_)
125 -
static_cast<int64_t
>(pos);
137 int64_t bytes_read =
ReadP(ptr, len,
pos_);
144 int64_t bytes_read =
Data(&source, len, pos);
145 memcpy(ptr, source, bytes_read);
170 uint64_t bytes_written = fwrite(
buf_, 1,
pos_,
fp_);
171 if (bytes_written !=
pos_) {
173 "could not write to temporary file %s: length %lu, "
174 "actually written %lu, error %d",
static FileBackedBuffer * Create(uint64_t in_memory_threshold, const std::string &tmp_dir="/tmp/")
CVMFS_EXPORT const LogSource source
FILE * CreateTempFile(const std::string &path_prefix, const int mode, const char *open_flags, std::string *final_path)
const uint64_t in_memory_threshold_
assert((mem||(size==0))&&"Out Of Memory")
MemoryMappedFile * mmapped_
enum FileBackedBuffer::@4 state_
int64_t ReadP(void *ptr, int64_t len, uint64_t pos)
int64_t Data(void **ptr, int64_t len, uint64_t pos)
int64_t Read(void *ptr, int64_t len)
enum FileBackedBuffer::@5 mode_
void Append(const void *source, uint64_t len)
FileBackedBuffer(uint64_t in_memory_threshold, const std::string &tmp_dir)
const std::string tmp_dir_
unsigned char * buffer() const