37 std::string_view _borrowed;
58 std::string_view
view() const noexcept;
59 size_t size() const noexcept;
96 swap(a._path, b._path);
98 swap(a._lock_fd, b._lock_fd);
101 const std::string &
path() const noexcept;
103 tmp_path &keep(
bool yes) & noexcept;
104 tmp_path &&keep(
bool yes) && noexcept;
133 swap(a._file, b._file);
136 FILE *file() noexcept;
178 const std::string &format =
"esbmc.%%%%-%%%%-%%%%",
179 const char *mode =
"w+");
246 std::map<std::string, std::string_view> _bundled;
247 std::map<std::string, tmp_path> _materialized;
249 template <
typename F>
250 void for_each_under(
const std::string &prefix, F &&f)
const
252 for (
auto it = _bundled.lower_bound(prefix);
253 it != _bundled.end() &&
254 it->first.compare(0, prefix.size(), prefix) == 0;
257 if (it->first.size() == prefix.size() || it->first[prefix.size()] ==
'/')
258 f(it->first, it->second);
266 void add_bundled(
const std::string &
path,
const char *data,
size_t size);
270 std::optional<file_data>
read(
const std::string &
path)
const;
283 std::vector<std::string>
list(
const std::string &prefix)
const;
293 materialize(
const std::string &prefix,
const std::string &format);
bool is_bundled() const noexcept
Definition filesystem.cpp:211
file_data & operator=(const file_data &)=delete
size_t size() const noexcept
Definition filesystem.cpp:206
file_data(const file_data &)=delete
static file_data owned(std::string data)
Takes ownership of contents read from disk.
Definition filesystem.cpp:193
file_data & operator=(file_data &&)=default
std::string_view view() const noexcept
Definition filesystem.cpp:201
file_data(file_data &&)=default
static file_data bundled(const char *data, size_t size)
Borrows size bytes of static storage without copying them.
Definition filesystem.cpp:186
Files bundled into the binary, overlaid on the real filesystem.
Definition filesystem.h:245
size_t bundled_count() const noexcept
How many bundled files are registered.
Definition filesystem.cpp:287
const std::string & materialize(const std::string &prefix, const std::string &format)
Writes every bundled file below prefix into a fresh temporary directory named after format,...
Definition filesystem.cpp:302
std::vector< std::string > list(const std::string &prefix) const
Every bundled path below prefix, at any depth.
Definition filesystem.cpp:292
static filesystemt & get()
Definition filesystem.cpp:235
bool readable(const std::string &path) const
Whether the contents of path can actually be obtained.
Definition filesystem.cpp:282
void add_bundled(const std::string &path, const char *data, size_t size)
Registers static file contents; see file_data::bundled().
Definition filesystem.cpp:241
bool exists(const std::string &path) const
Definition filesystem.cpp:277
tmp_dir_override & operator=(const tmp_dir_override &)=delete
tmp_dir_override(const std::string &dir)
Definition filesystem.cpp:424
tmp_dir_override(const tmp_dir_override &)=delete
Temporary path to an open file with an associated FILE handle.
Definition filesystem.h:116
tmp_file(tmp_file &&o)=default
friend void swap(tmp_file &a, tmp_file &b)
Definition filesystem.h:129
tmp_file(const tmp_file &)=delete
Represents a temporary path, which is (optionally) removed by the destructor.
Definition filesystem.h:74
tmp_path(const tmp_path &)=delete
bool _keep
Definition filesystem.h:81
friend void swap(tmp_path &a, tmp_path &b)
Definition filesystem.h:93
tmp_path & keep(bool yes) &noexcept
Definition filesystem.cpp:368
ssize_t read(int fildes, void *buf, size_t nbyte)
Definition io.c:322
this file will contains helper functions for manipulating files
Definition filesystem.h:16
void register_tmp_for_cleanup(const std::string &path)
The register_*() registries below are process-global, append-only and unsynchronised; each is read by...
Definition filesystem.cpp:79
void kill_registered_pgroups_from_signal()
Async-signal-safe counterparts of the two cleanup calls above, for use from a signal handler.
Definition filesystem.cpp:145
void register_pgroup_for_cleanup(long pgid)
Track child process groups so the signal/timeout exit paths can kill them.
Definition filesystem.cpp:105
void kill_registered_pgroups()
Definition filesystem.cpp:131
constexpr const char * ESBMC_VFS_ROOT
Root of the bundled path namespace, e.g.
Definition filesystem.h:19
void remove_registered_tmps_from_signal()
Definition filesystem.cpp:155
bool is_bundled_source(std::string_view file)
True if file names one of ESBMC's own operational-model or library sources rather than user code.
Definition filesystem.cpp:221
tmp_file create_tmp_file(const std::string &format="esbmc.%%%%-%%%%-%%%%", const char *mode="w+")
The file is created exclusively and with 0600 permissions, so it is never a pre-existing path (or a s...
Definition filesystem.cpp:477
void cleanup_registered_tmps()
Definition filesystem.cpp:92
void create_path_and_write(const std::string &path, const char *s, size_t n)
Creates all folders needed for a path.
Definition filesystem.cpp:510
const std::string get_unique_tmp_path(const std::string &format)
Generates a unique path based on the format.
Definition filesystem.cpp:499
void unregister_pgroup(long pgid)
Definition filesystem.cpp:118
tmp_path create_tmp_dir(const std::string &format="esbmc.%%%%-%%%%-%%%%")
Definition filesystem.cpp:489
__ESBMC_C_CPP_BEGIN struct __esbmc_file_t FILE